Setting a string variable value based on a reference variable

Cirrus
Kilo Sage

Good morning all,

We are building a new starter catalogue request and need to populate a contact email variable based on the location of the user. Within a variable set, we have a reference field, starter_location, which is filtered to show just 4 specific locations, say north, south, east and west. If the new starters location is north, we want to automatically populate a single line text field, starter_email, with a defined email address. Note this email is not part of the user record, otherwise we could have referenced it from the sys_user table.

I have the following on change client script, but its not working. Is there anything obvious wrong with this approach please:

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {

g_form.setValue('starter_email,"");
}

var loc = g_form.getValue('starter_location');
if(loc =='North'){
g_from.setValue('starter_email',"north@xyz.com");
}
else if(loc =='South'){
g_from.setValue('starter_email',"south@xyz.com");
}
else if(loc =='East'){
g_from.setValue('starter_email',"east@xyz.com");
}
else if(loc =='West'){
g_from.setValue('starter_email',"west@xyz.com");
}
return;
}

1 ACCEPTED SOLUTION

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var val=g_form.getDisplayBox('cmdb_ci').value;
if(val=='All')
{
alert('inside');
g_form.setValue('specific_transaction','1232131231');
}
//Type appropriate comment here, and begin script below

}

 

I wrote this and it was able to set the value in the specific_transaction field. Can you check if the field in which you are setting the value has the correct data type.

 

Regards,

Gundeep Singh

View solution in original post

18 REPLIES 18

Jaspal Singh
Mega Patron
Mega Patron

Hi Cirrus,

 

If the values for North, South, East, West location are being stored in some table then you can pass sys_ids instead of lables for the location while setting.

For instance,

var loc = g_form.getValue('starter_location'); 
if(loc =='North'){
g_from.setValue('starter_email',"north@xyz.com");
}

 

would be

 

var loc = g_form.getValue('starter_location'); 
if(loc =='North'){
g_from.setValue('starter_email',"sys_id_of_north");
}

 

Thanks,

Jaspal Singh

 

Hit Helpful or Correct on the impact of response.

Jaspal,

the values for N,S,E,W are in the locations table. However, I am not sure what you are saying here. Surely your code would just set the value to "North" rather than north@xyz.com (note the email is not defined in any table/field, it is just defined in the script) 

Ajaykumar1
Tera Guru

Hi,

Try below code,

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {

g_form.setValue('starter_email,"");
}

var loc = g_form.getDisplayBox('starter_location').value; 

if(loc =='North'){
g_from.setValue('starter_email',"north@xyz.com");
}
else if(loc =='South'){
g_from.setValue('starter_email',"south@xyz.com");
}
else if(loc =='East'){
g_from.setValue('starter_email',"east@xyz.com");
}
else if(loc =='West'){
g_from.setValue('starter_email',"west@xyz.com");
}
return; 
}

 

Mark If Correct/Helpful.

Regards,
Ajay.

Ajay,

This results in the locations table popup constantly refreshing on selection!

Hi Cirrus,

Cross check on change of which field you are writing onChange client script.

Also, try removing/commenting the g_form.setValue('starter_email',"");

Can you provide screenshots..?

Regards,
Ajay