Multiple dependent Values

Samarendra2
Kilo Explorer

Hi Friends,

 

I have below incident form which are all dependent values. Up to "Place" field , I have defined Choice as per dependent value , but now same "Types of services" are present in different places with different "Service Identifier" , I meen both the values are dependent on Place value.

 

I have create one onChange client script as below, which is not working.

 

Can any one help me out.

Thanks

Nayak 

 

 

find_real_file.png

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}

var place = g_form.getValue('u_location');
var stype = g_form.getValue('u_type_of_service');


if(place == "SARPAVARAM" && stype == "Global VPN") {
g_form.setValue('u_service_identifier',"091KAKI623006982554");
g_form.setValue('u_service_identifier',"091KAKI623012998901");
} else if(place == "Madhurawada" && stype == "Internet Access Service") {
g_form.setValue('u_service_identifier',"091HYDE030005406685");
} else if(place == "Madhurawada" && stype == "Global VPN") {
g_form.setValue('u_service_identifier',"091VISH623006982519");
g_form.setValue('u_service_identifier',"091VISH623006982484");
} else {
g_form.setValue('u_service_identifier',"1"); }
}

5 REPLIES 5

Narendra Kota
Mega Sage

Instead of using setValue, try using g_form.addOption(); to add two available choices for the Service identifier field.

This way, you will be able to see two choices in the dropdown to select any one.

 

Mark my answer as correct or helpful if it helped.

Samarendra2
Kilo Explorer

Hi Narendra,

 

Thanks for replay,

 

I have modified the script as below but not getting actual result.(still getting 3 values, i should get 2 values). Please find below table

find_real_file.png

 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}

var place = g_form.getValue('u_location');
var stype = g_form.getValue('u_type_of_service');

if(place == "SARPAVARAM" && stype == "Global VPN") {
g_form.addOption('u_service_identifier','091KAKI623006982554','091KAKI623006982554',1);
g_form.addOption('u_service_identifier','091KAKI623012998901' , '091KAKI623012998901', 2);
} else if(place == "Madhurawada" && stype == "Internet Access Service") {
g_form.addOption('u_service_identifier','091HYDE030005406685', '091HYDE030005406685', 1);
} else if(place == "Madhurawada" && stype == "Global VPN") {
g_form.addOption('u_service_identifier','091VISH623006982519','091VISH623006982519', 1);
g_form.addOption('u_service_identifier','091VISH623006982484','091VISH623006982484' ,2 );
} else {
g_form.addOption('u_service_identifier',""); }
}

 

find_real_file.png

 

Thanks,

Nayak

Try this,

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
 if (isLoading || newValue === '') {
 return;
 }


var place = g_form.getValue('u_location'); 
 var stype = g_form.getValue('u_type_of_service');
 
 if(place == "SARPAVARAM" && stype == "Global VPN") {
 g_form.addOption('u_service_identifier','091KAKI623006982554','091KAKI623006982554',1);
 g_form.addOption('u_service_identifier','091KAKI623012998901' , '091KAKI623012998901', 2); 
 } else if(place == "Madhurawada" && stype == "Internet Access Service") {
 g_form.addOption('u_service_identifier','091HYDE030005406685', '091HYDE030005406685', 1); 
 } else if(place == "Madhurawada" && stype == "Global VPN") {
g_form.removeOption('u_service_identifier','091HYDE030005406685','091HYDE030005406685' );
 g_form.addOption('u_service_identifier','091VISH623006982519','091VISH623006982519', 1); 
 g_form.addOption('u_service_identifier','091VISH623006982484','091VISH623006982484' ,2 ); 
 } else {
 g_form.addOption('u_service_identifier',""); }
 }

gyedwab
Mega Guru

Hi Narendra,

 

Have you ever used Data Lookup Tables?

https://docs.servicenow.com/bundle/istanbul-platform-administration/page/administer/field-administra...

I believe it will allow you to set a field based on multiple other values, and it's designed to be used codelessly.