The CreatorCon Call for Content is officially open! Get started here.

Need to populate the value based on the selected option from the field

vinuth v
Tera Expert

Hi All,

 

I need to populate the value based on the selected option from one of the field.

 

I have written the onChange code

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
 if (g_form.getValue('u_topic') == '4a0a957187e9711053d7419e8bbb35') {
        alert('som new value:' + g_form.getValue('u_topic'));
        getSubIDSLIST();
}
function getSubIDSLIST() {
        alert("1st Test");
        var ga = new GlideAjax('SubscriptionIDs');
        ga.addParam('sysparm_name', 'getSubIDSLIST');
        ga.getXML(ajaxResponse);
 }
   function ajaxResponse(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        alert("line 26" + answer);
        //var k = answer;
        var jsonArray = JSON.parse(answer);
    g_form.clearOptions("subscription_name");
        g_form.clearOptions("assetid");
  // Loop through the JSON array and add options
for (var i = 0; i < jsonArray.length; i++) {
            var item1 = jsonArray[i].item1;
           // var item2 = jsonArray[i].item2;
 g_form.addOption("subscription_name", item1, item1);
 for (var j = 0; j < jsonArray.length; j++) {
            //var item1 = jsonArray[].item1;
            var item2 = jsonArray[j].item2;
            g_form.addOption("assetid", item2, item2);
}
}
}
}
 The above script is working fine,
 When I select the "Topic" as "Extend Expiry of Sandbox subscription" option, I can populate the values on  "Subscription Name" and "AssetID" field.
 
values from the get method like below
[{"item1":"DCO-AzurePOC-6","item2":"200158"},{"item1":"DCO-AzurePOC-5","item2":"208311"}]
Currently I can populate the values,
vinuthv_0-1696600424127.png

 

But

I need to populate the "AssetId" value based on the selected option from Subscription Name" field.

 

Please any one suggest me, how to populate the value,

Thanks in advance,

Vinuth

 

2 REPLIES 2

Vishal Birajdar
Giga Sage

Hi @vinuth v 

 

You can try like this..

 

1. First onChange client script on Topic & populate only Subscription Name.

2.Second onChange client script on Subscription Name, to populate asset id from Subscription Name.

Can use same logic used in above question.

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Hi @Vishal Birajdar 

If I used the same logic then all the values are populated on the AssetId.

 

My query based on the selected option from the "Subscription Name" name field I need to display the respective value.

 

For example:

values from the get method like below
[{"item1":"DCO-AzurePOC-6","item2":"200158"},{"item1":"DCO-AzurePOC-5","item2":"208311"}]
 
If "DCO-AzurePOC-6" is selected from the Subscription Name field I need to populate only 200158 value on the AssetID field.
 
Thank you,
Vinuth