Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

issue getting value on backend

Saqib Dar March 29, 2023

Hi Community,

 I am facing an issue to fetch custom-field value in the backend(Scriptrinner) multiple times.

I am using 1 custom field and one system field to make a condition.

1- Reporter

2- Custom-Field A

I used Reporter to fetch some information and set it on the form Custom-Field A then I get the value of Custom-Field A e.g. "Apple: in the backend and make conditions to perform a certain action. I get the backend value e.g. 112233 only once. if I change the reporter the new value sets on the form e.g. "Mango" however, in the back it wont change and remain same value e.g. 112233. How i can achieve that whenever my reporter change the the value on the form and back end both change.

Scripting on CustomField A

Thanks.

 

2 answers

0 votes
Nic Brough -Adaptavist-
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.
March 29, 2023

I am not sure I understand what you are trying to do here.  Could you explain what you are trying to do with each script?

Script A looks like it gets the reporter, then sets a value on customfield_12345, then sets it readonly.

Script B looks like it is just reading a value from customfield_12345.

There is a problem with doing this - you can't know which way around the scripts are going to run.  customfield_12345 may have its original value (or default or available if it's a create screen) when the second script executes, and then the first script changes it and sets it read only. 

I would suggest changing the second script such that it runs the same logic as the first one - working out what the first script is going to do and use that value

0 votes
Radek Dostál
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.
March 29, 2023

Well, this is a tad too generic description. Any code, what you're currently doing, how?

Saqib Dar March 29, 2023

on reporter field i added scriptcode is : 

import java.lang.String
import com.atlassian.jira.component.ComponentAccessor;
import com.onresolve.jira.groovy.user.FieldBehaviours;
import com.atlassian.jira.user.ApplicationUser;

def reporterUser = getFieldById(getFieldChanged());
String reporterValue = reporterUser.getFormValue();
def userValue = ComponentAccessor.getUserManager().getUserByName(reporterValue);
def values = null;

String employeeCompany = ComponentAccessor.getUserPropertyManager().getPropertySet(userValue).getString("jira.meta.Company");
def employeeidCompany = getFieldById("customfield_12345");
employeeidCompany.setFormValue(employeeCompany);
employeeidCompany.setReadOnly(true);
**********************************************************************************************
in custom field A, I added scriptCode is: 
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
def companyField = getFieldById("customfield_12345");
String companyFieldValue = companyField.getFormValue();

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events