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

Gundeep Singh
Giga Expert

Hi ,

 

Useg_form.getDisplayBox('<field_name').value to get the Value of reference fields.

 

 

 

Mark it Helpful or correct if it works for you.

 


You can ask your Query if have any further questions.

 

Regards,

Gundeep Singh

Gundeep,

If I change this, I get an error under the location field:

onChange script error: TypeError: Cannot read property 'value' of null function h_7a421810db313340d4d79414db9619f1(control, oldValue, newValue, isLoading) { if (isLoading || newValue == '') { g_form.getDisplayBox('<starter_location').value; } 

 

I changed 

if (isLoading || newValue == '') {

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

var loc = g_form.getValue('starter_location'); 

 

to 

 

if (isLoading || newValue == '') {

g_form.getDisplayBox('starter_location').value;
}

var loc = g_form.getValue('starter_location'); 

I just tried for one of my catalog item it worked fine. Could you please check your reference table 

 

 

 

find_real_file.png

 

 

find_real_file.png

 

 

Regards,

Gundeep Singh

 

 

 

 

 

 

 

Thanks Gundeep,

I get the same as you in that the alert is picking up the selected location name, but putting it into the code still doesnt return an email address

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


g_form.setValue('starters_mailbox',"");

 

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


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

}
alert(g_form.getDisplayBox('starters_location').value);
}