I have a requirement to add 3 custom fields, divide it by 4th custom field and auto populate 5th field.
Tried scripted field option but it is not working for create and edit screens.
Tried live fields sil option and it is also not working, not sure how to troubleshoot.
Please help.
Hello!
You can use Live Fields. Suppose you have customfield_10101, customfield_10102, customfield_10103, customfield_10104, customfield_10105.
First create a file setValueForCustomField10105.sil:
number val = (argv["customfield_10101"] + argv["customfield_10102"] + argv["customfield_10103"]) /argv["customfield_10104"];
lfSet("customfield_10105" , val);
Then you can create a Live Field with a code like this:
number val = (customfield_10101 + customfield_10102 + customfield_10103) / customfield_10104 ;lfSet(
"customfield_10105"
,
val
);
lfWatch("customfield_10101", {"customfield_10101", "customfield_101012", "customfield_10103", "customfield_10104"}, "setValueForCustomField10105.sil");
lfWatch("customfield_10102", {"customfield_10101", "customfield_101012", "customfield_10103", "customfield_10104"}, "setValueForCustomField10105.sil");
lfWatch("customfield_10103", {"customfield_10101", "customfield_101012", "customfield_10103", "customfield_10104"}, "setValueForCustomField10105.sil");
lfWatch("customfield_10104", {"customfield_10101", "customfield_101012", "customfield_10103", "customfield_10104"}, "setValueForCustomField10105.sil");
It should solve your task
thank you for the solution Alexey.
4 of my custom fields (ustomfield_10101, customfield_10102, customfield_10103, customfield_10104 ) are strings. I am unable to calculate them.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried converting the fields to number but they are not getting auto populated in create and edit screen. Values are getting calculated only in view screen.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @upatlo01 Scripted Field should work. Can you post your code ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Gustavo,
In the scripted field documentation, it is clearly given that it will not work on create and edit screen.
https://scriptrunner.adaptavist.com/5.0.4/jira/scripted-fields.html
Add a new custom field, then choose Advanced
and then Scripted Field. Give it a name and associate it to any screens you need. Note, it won’t be displayed on Create or Edit screens.
This is my code, I just tried to populate scripted field, did not implement any calcualtion.
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.Issue;
import java.lang.*;
//import com.onresolve.jira.groovy.user.FieldBehaviours;
//import groovy.transform.BaseScript;
//import com.onresolve.jira.groovy.user.FormField;
//@BaseScript FieldBehaviours fieldBehaviours
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
def issueManager = ComponentAccessor.getIssueManager();
CustomField oerrField = customFieldManager.getCustomFieldObjectByName("OE");
def oerrValue = issue.getCustomFieldValue(oerrField);
if (oerrValue == null){
return null;
}
CustomField businessField = customFieldManager.getCustomFieldObjectByName("Business Value");
//def anotherCustNumValue = getFieldById("customfield_10003").getValue();
CustomField timecriticalityField = customFieldManager.getCustomFieldObjectByName("Time Criticality");
//def ValueA = getFieldById("customfield_16").getValue();
CustomField jobsizeField = customFieldManager.getCustomFieldObjectByName("Job Size");
//def ValueB = getFieldById("customfield_14").getValue();
/*if(custNumValue == 0 && anotherCustNumValue == 0){
def finalValue = 0;
return finalValue;
}
else if(custNumVbusinessValuealue == null && anotherCustNumValue != null){
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Spend the day sharpening your skills in Atlassian Cloud Organization Admin or Jira Administration, then take the exam onsite. Already ready? Take one - or more - of 12 different certification exams while you’re in Anaheim at Team' 25.
Learn more
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.