How to set Custom Field value without Issue object using Groovy

KL Kumar June 1, 2017

Hello!

I have a group picker in Create screen with some logic(Behaviours Groovy script) to filter the values in it and I have to add those filtered values to group picker. This may work using post function (as mentioned in https://www.adaptavist.com/doco/display/SFJ/Set+a+multi+group+picker+custom+field+via+a+post+function) because an Issue object will be created and available by this time.

"issue.setCustomFieldValue(singleGroupCf, [group])"

But in my case, I have this group picker in Create screen and hence, Issue object will not be created yet.

 

Can someone help me in adding the filtered values to group picker without Issue object using Groovy?

Appreciate your help!

1 answer

0 votes
Thomas Venekamp June 6, 2017

You can use your code as a post-function in the 'Create' transition. You just have to be aware, that your code will be executed after the first step "1. Create the issue".

Create a new custom script function in the post-function section of the workflow transition and then click on the little arrow on the right side to put the code one step later.

KL Kumar June 6, 2017

Hi,

Thanks for your reply Thomas.

 

As you said I can put my code as post-function, in general, post-function executes after the transition (in this case Create transition). But my Group Picker is present in Create screen itself. That means the values must be filtered and available in Create screen itself (before the post-function) as per my groovy logic.

If I use 'Issue' object to set the custom field in my logic, the issue object is returning 'null' because the issue bject has not yet created in Create screen (before clicking on Create button).

The other way around I believe, this can be achieved is, we should be able to execute the logic when we click on Group Picker icon. Then it executes my logic and pulls out the filtered data on the Group Picker window. I am not sure how this can be achievable.

 

Thanks!

Thomas Venekamp June 7, 2017

I am sorry, i missunderstood you.

If you already use Behaviours Groovy Script to filter the values, you should be able to set the value of the formfield with the following expressions:

 

def singleGroupCF = getFieldById("customfield_11111")
singleGroupCF.setFormValue(value)

I hope that this approach will work.

 

KL Kumar June 7, 2017

Hi Thomas,

I tried the way you mentioned above. Seems the values are being set to the Group Picker field (values obtained from my logic are printing in the log). But when I click on the Group Picker icon, it seems, the Group Picker default query is executing and overriding my values in it. So, by default all the values are populating irrespective of my logic.

So I believe, there needs to be done something when we click on Group Picker icon.

Thanks!

Thomas Venekamp June 7, 2017

There is currently no way to do it, if i read this correctly:
https://jira.atlassian.com/browse/JRASERVER-61856

This was the raised issue to limit the user picker field to users from certain groups. Took only 9 years to solve.
https://jira.atlassian.com/browse/JRASERVER-7659

Suggest an answer

Log in or Sign up to answer