Trying to save select value in a Scriptrunner behaviour

Peter Ellis
Contributor
August 26, 2024

Hi,

What should be very simple has proved challenging getting the right syntax. I am successfully picking up the select fields value from the parent issue but despite the many variations I have tried to use I cannot get it copied over to the child issue,. Can someone tell me what I have done wrong?

def fldCustomer = contextIssue.getCustomFieldValue('Customer')

def fldCustomerValue = fldCustomer.toString()
getFieldByName('Customer').setFormValue(fldCustomerValue)
I have also tried using fldOptions below:

 

def fldOptions = optionsManager.findByOptionValue(fldCustomerValue)[]

 

            

1 answer

1 vote
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 27, 2024

Hi @Peter Ellis

What you are trying to achieve is not directly doable via ScriptRunner Behaviour for the Issue Create screen. It is only doable on an Issue Update screen because the Sub-task is not yet linked to the parent issue on the create screen and cannot invoke the field values from the parent issue.

On the other hand, if you have a scripted field, i.e. like the issue picker, you can use it to indicate the parent issue and pass the value from it. I have provided a solution for this in this community post.

The other alternative would be to use the Post-Function, e.g. on the Create transition, where once the issue is created, it will pass the field values from the parent issue to the child issue.

Below is a very simple code sample using the Custom Script Post-Function for the Create transition:-

if (issue.subTask) {
def parent = issue.parentObject
issue.set {
setCustomFieldValue('Sample Text Field', parent.getCustomFieldValue('Sample Text Field'))
}
}

I am looking forward to your feedback.

Thank you and Kind regards,
Ram

Peter Ellis
Contributor
August 30, 2024

Hi Ram,

Thank you for replying. I am currently copying over text and date data from the parent to the linked issue without any problem using script, see images. I just assumed that there is another syntax for select fields. I could use a post function but if there is a way to have this all in the same place that would be preferred.

SR_1.pngSR_2.pngSR_3.png  

 

 

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 10, 2024

Hi @Peter Ellis

From the screenshot you have shared, you seem to be trying to pass the value during the create screen.

As I mentioned in my previous comment, this will fail when using Behaviour because when the Create screen is displayed, the link between the parent and child issue is not yet established as the child issue doesn't yet exist.

Hence, Behaviour is not a suitable approach for this. You must instead use the Post-Function or the Listener.

However, if you intend to use Behaviour, it can only work when using the Edit screen or Transition screen.

I am looking forward to your feedback.

Thank you and Kind regards,
Ram

Peter Ellis
Contributor
September 24, 2024

Hi Ram,

I didn't mention earlier but I am creating new issues via fragments so the parent is still in context when the related issue is created but not submitted. 

I knew what I needed to do in the code for a select field (create an array, find the option ID and return it etc) I eventually worked it out and it's all working perfectly now. 

SR_1.pngSR_2.pngSR_3.pngSR_4.png

Suggest an answer

Log in or Sign up to answer