How to populate data in one custom field based on other custom field?

Harsh Pruthi February 13, 2018

I am using following code snippet in Description to populate the value in field B depending on what value is selected from field A, using field A onchange trigger.

<script type="text/javascript">
sid = document.getElementById('customfield_10087');
if (sid) {
target = document.getElementById('customfield_10097');

if (sid.value == "ABBOTSFORD PUBLIC SCHOOL (ABBOTSFORD)") target.value="hi this is done";

sid.onchange=function() {
target.value=this.value
}
}
</script>

 

Field A is select list but when in use field A.Value in my code it returns a number instead of the literal value of the selection. I have to populate filed B based on what is selected in field A but I am not able to compare as I said the value returned is number and the not the literal value that I select.

 

My second if statement above never returns true because sid.value is returned as a number or id of "ABBOTSFORD PUBLIC SCHOOL (ABBOTSFORD)"

 

How do I map this id to my literal value?

1 answer

0 votes
Ivan Tovbin
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.
February 14, 2018

Perhaps the reason for this is because the value of a single select list type field is a LazyLoadedOption object and not a string representation of its value. The number you are getting is probably that very option's id.

Harsh Pruthi February 14, 2018

Thanks Ivan. 

Is there a property that provides the actual stored value and not it number representation? There definitely will be some mapping somewhere between these numbers and the actual value

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.
February 14, 2018

Not with javascript, you need to work with the numbers.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events