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

Auto populate custom field

upatlo01 August 30, 2020

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.

2 answers

1 accepted

0 votes
Answer accepted
Alexey Matveev
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.
August 30, 2020

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

upatlo01 August 31, 2020

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.

upatlo01 August 31, 2020

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.

0 votes
Gustavo Félix
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.
August 30, 2020

Hi @upatlo01  Scripted Field should work. Can you post your code ?

upatlo01 September 1, 2020

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){

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, team '25, conference, certifications, bootcamps, training experience, anaheim ca,

Want to make the most of Team ‘25?

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
AUG Leaders

Upcoming Jira Events