- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2018 02:19 AM
I want to auto populate the Manager, Location and Department based on 'Requested_For' under Variable Set. Also want to auto populate the same when logged in user try to change the 'Requested_For'.
I tried writing "OnChange" Client script but facing an error on Portal page as "There is a JavaScript error in your browser Console". Attached the screenshot.
Also tried as per below URL but still the issue exists.
https://community.servicenow.com/community?id=community_question&sys_id=196b8b21db9cdbc01dcaf3231f96193b
Can anyone please help me with the Script?
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2018 04:45 AM
Hi Sai,
try below one-
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var gr = g_form.getReference('requested_for',callBack);
}
function callBack(gr){
g_form.setValue('manger',gr.manager);
g_form.setValue('phone_number',gr.mobile_number);
g_form.setValue('email',gr.email);
g_form.setValue('location',gr.location);
g_form.setValue('zipcode',gr.zip);
g_form.setValue('country',gr.country);
g_form.setValue('company_code',gr.company);
}
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2018 02:36 AM
Hi Sai,
You need to use getReference() with callback since without callback function it won't work in portal.
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2018 02:41 AM
Hi Ankur,
I did the same. Please refer to attached screenshot of Client Script. If there is any issue, can you please try to add the script when you reply?
- Sai
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2018 02:51 AM
Hi Sai,
There is a OOB client script "(BP) Set Location to User" on incident table. You can refer same to see how getReference works.
I don't see a callback function parameter parameter in your getReference.
var abc = g_form.getReference('Requested_for'); >> callback function parameter is missing.
Please update this code as below.
var abc = g_form.getReference('Requested_for', setUserInfo);
function setUserInfo(abc) {
if (abc){
g_form.setValue('location', abc.location);
}
}
Thanks,
Akshay.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2018 03:35 AM
Hi Akshay,
I tried the code as per your suggestion, but it is not populating the values on Portal page.
- Sai.