Unable to access value stored in one behavior script to another

Suchit Kharatmol February 17, 2021

Hi Everyone,

I have two behavior script which works fine. Now I want to access the value  stored in one script to another. I tried accessing the value in behavior script initializer but I am getting null value.

Behavior script :

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField


@BaseScript FieldBehaviours fieldBehaviours
def A = getFieldById("customfield_16355")
Object A_val = A.getFormValue() as int


def A_Hours = getFieldById("customfield_16365")

Object A_Hour = 125*A_val

A_Hours .setFormValue(A_Hour )

 

Now when I tried to get value of field which is set by using A_Hours .setFormValue(A_Hour ) in the other behavior script OR in the initializer console of behavior script but I am getting null value.

 

Could you please help me on this.

Thanks,

Suchit

1 answer

0 votes
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 19, 2021

Ok, I'll take a stab at this... I see no one is daring to answer.

The short answer is no, there is no cross-talk possible between server-side behaviour script.

The longer answer requires some explanation of what behaviour does.

When you open a screen (create, edit, transition), there is a bunch of back and forth between browser-side scripts and the jira server backup using special rest endpoints supplied by scriptrunner.

  1. Browser says:
    • hey, here is a screen for project x and issuetype y (or issue id for edit) with all the fields data currently available, are there any validators mapped that?
  2. Jira Action:
    • Jira looks at all the behaviours that match the relevant mapping and
      • looks up all the fields with some generic behaviour configuration and get their actions
      • executes each of the inilializers and gets a list of fields and action
        • any getValue() on field object is taken from the request sent by the browser
  3. Jira Responds:
    • Sure, here are all the fields that are impacted by some behaviour rule and their specific behaviour actions: readOnly, hidden, value to set etc
  4. The browser then makes the necessary adjustments to the fields
  5. The browser makes further requests for each field that have behaviours (to run their server-side script) saying. Run any validators for this field. Here are all the other field values.
  6. Jira runs those validators and sends back a list of fields and their corresponding actions.
  7. The browser makes the necessary adjustments to the fields

Then each time you modified a field included in the response listed in #3, that validator is re-un using new and updated data.

You see, each of those server-side requests are executed in a standalone transaction. So one is not aware of what is happening to the other.

Now, if you have some fields that are interdependent, you may need to combine your 2 scripts and run them from each of your fields.

Suggest an answer

Log in or Sign up to answer