- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2024 01:10 PM
Hey everyone,
I created a scheduled job for a catalog task to create an assigned task weekly, I am able to get single line text fields to populate but am struggling with the reference fields. I want to auto populate requested for when the task is generated. Below is the script, requestor is the name of the reference variable but I cannot get it to auto populate the others in the script will populate when the task is generated. How can I get the reference field to populate? Below is the script and a picture of the variable I am trying to get to populate.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2024 01:25 PM
Hi @jonsr20
You need to pass the sys id for the reference fields because of that it is not working for you.
Below is the code that I have tried in my PDI , it is working Fine.
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('c112f7fcc30e8210d30c564ed4013101'); // Put the sys_id of the catalog item that you want to raise the request
// Set other variables of your catalog item accordingly
cart.setVariable(item, 'prefered_location', '25ab9c4d0a0a0bb300f7dabdc0ca7c1c');//it is reference field
cart.setVariable(item, 'description', 'Testing1234');
// Query the sys_user table to get the sys_id of the requester
var rc = cart.placeOrder();
gs.info(rc.number);
Thanks and Regards
Sai Venkatesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2024 01:25 PM
Hi @jonsr20
You need to pass the sys id for the reference fields because of that it is not working for you.
Below is the code that I have tried in my PDI , it is working Fine.
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('c112f7fcc30e8210d30c564ed4013101'); // Put the sys_id of the catalog item that you want to raise the request
// Set other variables of your catalog item accordingly
cart.setVariable(item, 'prefered_location', '25ab9c4d0a0a0bb300f7dabdc0ca7c1c');//it is reference field
cart.setVariable(item, 'description', 'Testing1234');
// Query the sys_user table to get the sys_id of the requester
var rc = cart.placeOrder();
gs.info(rc.number);
Thanks and Regards
Sai Venkatesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2024 04:27 PM
Thank you very much Sai,
That worked for me I could've swore I tried to sys_id earlier and it did not work but maybe I copied it wrong. Really appreciate your help!!
Regards,
Jonathan Ross
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2024 05:19 PM
Hello Sai,
I was wondering if you could help with one more thing, I placed a MRVS in this catalog item and would like to populate the fields of it also. I am new to writing the script so any assistance would be greatly appreciated, if is on the same item as above I am trying to populate the fields in the MRVS also. I attached a picture of the MRVS name and the variables within, would really appreciate any guidance!