- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2022 07:30 AM
I am working with a catalog item. I have a delivery location field which is referenced with location table. Now I want to auto populate the delivery location field based upon a requested_by field. The delivery location should be requested_by user's location. I tried to achieve this using script include, but when I am alerting the location value sent from script include it is showing "[object] [Object]".
How do I send the location value from script include?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2022 08:11 PM
In your script include can you do:
user.location.name.toString();
Make sure the user you are checking for has location populated in location field in his user record.
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2022 08:41 PM
@kundusuman328 Please try below:
in script include add the toString() to location as well. As reference field also is a string field in backend which stores the sys_id of the referred element.
userDetails.location = user.location.toString();
One tip:
Please use the get function in a if block, that is best practice recommended by ServiceNow. And no need to add the 'sys_id' as first param when we are adding sys_id to the get function. if its some other field than sys_id then we need to pass the field name as first param
So please change the get function as below
if(user.get(userID)){
//Add lines to populate userDeatails object
}
Please mark as correct answer if this solves your issue.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2022 10:55 PM
@kundusuman328 did you check what is the display field on location table.
This issue only occurs if location value is not populated in your user table. Your code is correct, if it is fetching other values, it should fetch location as we..
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2022 07:51 AM - edited ‎12-10-2022 08:42 AM
You are alerting user.location before parsing it.
Try alerting user.loaction after the JSON.parse() line i.e. after line no. 19 in client script.
Also in your script include .toString() is missing from user.location, you need to add that.
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2022 09:16 AM - edited ‎12-10-2022 09:17 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2022 09:30 AM
@kundusuman328 are you getting other values in alert?
Also does that specific user have location value in user table?
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2022 07:15 PM
Yes I am getting all the values in alert except the reference fields(I tried with other reference field also). And yes, the location value exists in user table. I am using out of the box user table with no modifications