- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2017 07:16 PM
Hi,
I have a reference field 'employee'(which is fetching records from User table) on a form. I have few more string fields like level, status etc..
Now I want to build the functionality like if 'employee' field is filled with some value say "Sample User", then the above fields should be auto filled with level as 3 and status as 'Current Employee'
I am trying to write a client script, but I am not able to achieve this functionality by using reference field in the if condition in the below script..
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var p = g_form.getValue('u_employee');
//alert(g_form.getValue('u_employee'));
if (p && p = 'Sample User')
{
g_form.setValue('u_status', 'Current Employee');
g_form.setValue('u_level', '3');
}
Is it not correct to reference field in if condition? Also when I tried to display the employee value, it is showing me the sysId but not the actual value. Please help me out what is happening in this case.
Also please let me know how can I achieve my functionality.
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2017 07:27 PM
You need to create a "OnChange" Client script and use a call back function.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if(!isLoading && oldValue != newValue){
g_form.getReference('caller_id',changeUserInfo);
}
}
function changeUserInfo(userInfo){
g_form.setValue('u_incident_email', userInfo.email);
g_form.setValue('u_phone',userInfo.phone);
g_form.setValue('u_wing', userInfo.u_wing);
g_form.setValue('location', userInfo.location);
g_form.setValue('u_room', userInfo.u_room);
g_form.setValue('u_floor', userInfo.u_floor);
}
more info : GlideForm (g form) - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2017 07:27 PM
You need to create a "OnChange" Client script and use a call back function.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if(!isLoading && oldValue != newValue){
g_form.getReference('caller_id',changeUserInfo);
}
}
function changeUserInfo(userInfo){
g_form.setValue('u_incident_email', userInfo.email);
g_form.setValue('u_phone',userInfo.phone);
g_form.setValue('u_wing', userInfo.u_wing);
g_form.setValue('location', userInfo.location);
g_form.setValue('u_room', userInfo.u_room);
g_form.setValue('u_floor', userInfo.u_floor);
}
more info : GlideForm (g form) - ServiceNow Wiki