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-26-2018 06:44 AM
Hi Vishrut,
I applied the same script on Script Include and Onload client script. But the problem is the Mobile Number is getting empty on load of the form but the requestor name as well as location are populating correctly.
and sometimes onload of the form, location shows different and again it changes to the original value.
Kindly please let me know?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2018 05:56 AM
Hi Das,
First of all the below won't work in scoped app. if you are in global scope then it is fine
javascript:gs.getUser().getRecord().getValue('mobile_phone')
javascript:gs.getUser().getRecord().getValue('location')
The phone and location won't be cleared automatically you need to clear them onchange of requester field. the default value will work only 1st time i.e. for logged in user
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-29-2018 06:18 AM
Hi Ankur,
Can you please let me know how can I achieve the same by Onchange Catalog Client Script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2018 06:24 AM
Hi Das,
You can use g_form.getReference() with callback and populate the values.
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-29-2018 07:02 AM
Hello Ankur,
Can you please paste the script here so that it will be helpful for me.
and there is one more field Requester on Behalf of - Reference field to User table if user wants to request on behalf of any other user.
By default on form load, it will populate the location and mobile number of the requested for user but when I change the requested on behalf of filed with any user then the mobile number and site location details should get cleared on the form and populate based on the user.
Please kindly guide me as this is bit urgent.