Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Assests Filter assign scope

Martin Svensson
Contributor
February 8, 2023

I'm trying to pre populate a customfeild with an employee that has the approver role.

I need to be able to add or remove users from the approver customfeild directly in the customer portal.

The choices will then be affectuated with the postfunction to add or remove the users from the system approver asset object.

But when i run this the approver will not populate the portal field, i have tried several diffrent takes on the aql.

Any ideas?

Skärmklippc.PNG

2 answers

1 accepted

0 votes
Answer accepted
PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 8, 2023

Assuming that customfield_11300 is another insight objects custom field, you then want to compare that against the Key attribute

object HAVING inR(objectType=Systems and Key=${customerield_11300}, reftype in ("Approver"))

If that doesn't work, try the following:

object HAVING inR(objectType=Systems and Key in(${customerield_11300${0}}), reftype in ("Approver"))
Martin Svensson
Contributor
February 9, 2023

Yes, CF11300 is configured to show the systems available and cf11301 can present the choosen approvers 

PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 9, 2023

Key refers to the Key attribute (created by default for all object types along with Name, Created, and Updated).

Issues only store the key of your object as a reference to the object.

IQL placeholder, the value of an insight custom field returned by ${customfield_xxxx} will be the key of the selected object.  So if you want to find objects linked directly to the selected object, you need to match use the key of the selected object.

You should be able to use the IQL Search page to confirm this works:

Combine the filter scope IQL and filter assign scope IQL as:

objecttype=Userad and object having inR(Key=<enter a key for a selected system>, reftype in ("Approver"))

If you are getting the expected approver, then the auto-assign should work.

Be sure you delete the default/automatic value both in the custom field config and in the request type.
You'll also want to hide that field from the portal. The insight assign function is run via listeners, it doesn't show live on screen. 

Martin Svensson
Contributor
February 14, 2023

Hi Peter

I figured that i was beggin for a miracle.

But i still wonder why the automatic choice in the cf is for backend use only?

Why would you use that? You can easy do the same with postf.

I can see a whole lot of usecases were a live cf update would be lifesaver.

Do you have any ideas how i can get the same results within the potal?

PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 14, 2023

Jira and JSM are historically very simple in terms of front-end UI dynamic behavior (e.g. showing/hiding fields on the fly based selections or conditionally populating certain fields with different values other than the global default)

I use Scriptrunner Behaviour for that sort of thing.

Martin Svensson
Contributor
February 16, 2023

Yeah i'm starting to see that problem.

Sounds interesting, do you have any examples how you do it?

I have not used scriptrunner that much, but if you think there is a way to solve it i wanna aleast try.

I cant leave this matter unsoleved with this automatic but really nonautomatic feature.

PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 22, 2023

Here is a sample script (untested) that would work in scriptrunner behaviour to apply a default value to 1 insight field based on selection on another.

You apply this script to the system field so that it runs each time that field is updated.

 

import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.IQLFacade
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours
@WithPlugin('com.riadalabs.jira.plugins.insight') insightPlugin
@PluginModule IQLFacade iqlFacade

if (underlyingIssue) return //don't run after initial creation or else it would overwrite a selected approver

def systemField = getFieldById('customfield_11300')
def approversField = getFieldById('customfield_11301')

def selectedSystem = systemField.value
if (!selectedSystem) return //no selection was made, or the selection was clear, nothing more to do
if (selectedSystem instanceof List) {
//default to the first one if we have a list, generally, it's likely to be a list of size 1 anyway
selectedSystem = selectedSystem[0]
}

def iql = /objectType=Users and object having inR(objecType =Systems and Key = $selectedSystem, refType = "Approver")/
def approverObjects = iqlFacade.findObjects(iql.toString())

if (!approverObjects) {
approversField.setHelpText("No default approvers found for System $selectedSystem")
return
}
approversField.clearHelpText().setFormValue(approverObjects.first().objectKey)
Martin Svensson
Contributor
February 23, 2023

Wow thanks alot, i will try this.

0 votes
Martin Svensson
Contributor
February 9, 2023

Hi Peter Thanx for the quick followup.

I couldnt get the Key variable to work it didnt return any value, what does key value do compared to Name or label?

Skärmklippcdcd.PNG

I tried this one but with no luck, still nothing pre populated. only if i add the choosen value as default will it show up on the customfeild in the portal.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events