Scheduled job for a catalog task, Unable to autopopulate reference type fields

jonsr20
Tera Expert

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.

 

var cartId = GlideGuid.generate(null);


var cart = new Cart(cartId);


var item = cart.addItem('335e0d7747fb8950d94457cbd36d4372'); // Put the sys_id of the catalog item that you want to raise the request


cart.setVariable(item, 'requestor_s_call_back_number',  '999999999'); // set the other variables of your catalog item accordingly
cart.setVariable(item, 'description',  'Testing1234');
cart.setVariable(item, 'requestor_s_email',  'Germaine.Beter@bmcjax.com');
cart.setVariable(item, 'requestor',  'john smith');

var rc = cart.placeOrder();


gs.info(rc.number);
 
jonsr20_0-1716927002010.png

 

1 ACCEPTED SOLUTION

SAI VENKATESH
Tera Sage
Tera Sage

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

View solution in original post

3 REPLIES 3

SAI VENKATESH
Tera Sage
Tera Sage

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

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

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!