- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2022 10:14 PM
i have been trying to generate Request ticket from Schedule Jobs using the following script
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
//gives sys_id of catalog item
var item = cart.addItem('5104596487ed0910d0d4ca27cebb35fc', 1);
item.setVariable("requested_for", gs.getUserID());
var rc = cart.placeOrder();
everything is works fine but not displaying the Requested_for value by default. Please help
Solved! Go to Solution.
- Labels:
-
Multiple Versions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2022 12:40 AM
I have written this in a Scheduled Job as you need, but in case you need to write or use this in an Server side function you can do it as well :
Scheduled Job screenshot for reference as well:
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2022 11:46 PM
again:
interactive session: user goes inside the system adn clicks. In this case you are able to get gs.getUserID.
non-interactive session: system is generating something (like scheduled job). then you can't access gs.getUserID and your value will be empty. that is why it is not populating.
IF you want to put something there, you myst either hardcode sys_id of some user OR set someoune in the Run as field and then passit to the script:
instead of item.setVariable("requested_for", gs.getUserID());, put item.setVariable("requested_for", current.run_as);
Mark Correct AND Helpful. Thanks!
Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2022 11:47 PM
item.setVariable("requested_for",current.run_as);
still not displaying
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2022 11:48 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2022 11:51 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2022 11:52 PM
try with item.setValue("requested_for", current.run_as);
Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024