Populate User Mobile number and location OnChange and Onload on catalog Item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2018 05:43 AM
Hi Everyone,
I have configured one Catalog Item in which I have added some varaibles as below.
1.Requestor - Reference field to User table and I have added the default value as javascript:gs.getUserName() and it is populating onload of the form
2.Phone Number - Single Line Text field and given the default value as javascript:gs.getUser().getRecord().getValue('mobile_phone').
3.Site Location - Location field reference to Location Table. Default value is javascript:gs.getUser().getRecord().getValue('location').
4.Requester on Behalf of - Reference field to User table if user wants to request on behalf of any other user.
But I have some doubts when the form loads, the Location as well as SIte Location is not populating based on the logged in user.
And when I change the Requester name as well as Request on behalf of name and put some other user's name then the phone number field is not getting clear.
Can anyone suggest me on the same how to achieve this requirement. Is there anything do I need to configure any Catalog Client Scripts to perform the task.
Thanks,
SNOW@Das
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2018 07:08 AM
Hi Das,
Sample script below:
function onChange(){
var requester = g_form.getReference('<requesterField>', popInfo);
}
function popInfo(requester){
g_form.setValue('locationField', requester.location); // use proper field for location here
g_form.setValue('mobileField', requester.mobile_phone); // use proper field for mobile here
}
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
10-30-2018 03:17 AM
Hi Das,
Any update on this?
Can you mark my answer as correct, helpful if you were able to achieve the requirement. This helps in removing this question from unanswered list and helps users to learn from your thread. Thanks in advance.
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
10-25-2018 05:57 AM
The problem with using scripts such as:
javascript:gs.getUser().getRecord().getValue('mobile_phone')
is that they are "per session" so it is entirely possible to get values for someone other than the currently logged in user; as you have experienced.
You would be better served by making the fields "user" fields that feed directly from their profile, which gives the added benefit of allowing real-time updating of the field values between the profile and record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2018 09:30 AM
Hi,
Can you please brief me in details so that I can get to know like how to implement the same.