- 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 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:52 PM - edited 12-12-2022 10:53 PM
- 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-12-2022 11:02 PM
@kundusuman328 It means that the field location is empty. Please check that.
ServiceNow Community Rising Star, Class of 2023