- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2021 02:45 AM
Hello All,
I have one requirement in which I have to set default value Requested for,Location,Employee Id,and Department.
I set the default value of Requested for but not able to set remaining. I attached the screen short of both
Please let me know if any one have idea.
Thanks & Regards
Keval
Solved! Go to Solution.
- Labels:
-
Script Debugger
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2021 03:03 AM
Hi,
I assume Location variable is referring to cmn_location table; so do this
javascript: gs.getUser().getLocation();
I assume Department variable is referring to cmn_department table; so do this
javascript: gs.getUser().getDepartmentID();
I assume Employee ID is string variable; so do this
javascript: gs.getUser().getRecord().getValue('employee_number');
Regards
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
04-28-2021 03:03 AM
Hi,
I assume Location variable is referring to cmn_location table; so do this
javascript: gs.getUser().getLocation();
I assume Department variable is referring to cmn_department table; so do this
javascript: gs.getUser().getDepartmentID();
I assume Employee ID is string variable; so do this
javascript: gs.getUser().getRecord().getValue('employee_number');
Regards
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
04-28-2021 03:19 AM
if user changes Requested For then you will have to write onChange client script on Requested for and get the other variable details and populate it.
you can use getReference() with callback method to do this
Example below:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if(newValue == ''){
g_form.clearValue('location'); // location variable name here
}
var ref = g_form.getReference('requested_for', callBackMethod); // requestedFor variable name
}
function callBackMethod(ref){
if(ref.location)
g_form.setValue('location', ref.location); // location variable name here
}
Regards
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
04-28-2021 04:06 AM
Hi Ankur,
The Department field is displayed properly by your help
but Location and Employee Id are still not display
Location variable is referring to cmn_location table and Employee ID is string variable
Thanks & Regards
Keval
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2021 04:08 AM
then it should work fine.
did you check you are using correct field name for employee_number and user has that employee number populated.
also location is empty or not for that user in user table?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader