Create Service Request from Scheduled Job

Wade Clairmont
Tera Guru

I have a scheduled job that will run every morning 6 am to review current contractor profiles, and if they are expired, auto generate a service request for termination.

Everything works fine, just a question....   When I generate the service request using the following:

var cart = new Cart();

var item = cart.addItem("b151029edb110f00aa103c8f9d9619fd"); // System Termination

cart.setVariable(item, "sys_requested_for", usr.name);

cart.setVariable(item, "sys_delivery_date", gs.now());

cart.setVariable(item, "sys_comments", 'System generated termination request for expired contractor account.');

cart.placeOrder();

It generates the request fine, but only populates the RITM variables.   Is there a way to populate the Request fields, specifically the "requested for" field?

term.png

In order to follow the correct approval process, I need to be able to get this set to the same "requested for" as the RITM field.

Thanks in advance.

1 ACCEPTED SOLUTION

Community Alums
Not applicable

You can get the 'sys_id' of the order created and use that to query the 'sc_request' table to update those details:



var cart = new Cart();


var item = cart.addItem("b151029edb110f00aa103c8f9d9619fd"); // System Termination


cart.setVariable(item, "sys_requested_for", usr.name);


cart.setVariable(item, "sys_delivery_date", gs.now());


cart.setVariable(item, "sys_comments", 'System generated termination request for expired contractor account.');


var placeOrder = cart.placeOrder();



var request = placeOrder.getValue('sys_id');



Use the 'request' value to do your query.



Hope that helps!



Cheers,



Tim


View solution in original post

12 REPLIES 12

Tim,



It seems that this is a common question,   there is another post that may assist.


how to set requested for and opened by in a request using the cart API?



However, I resolved this issue by creating an approval within my workflow at the RITM level, and process the approval from there, even tho the request fields are incorrect, I can still control the direction after the request has started.



I don't think this is the correct way, but works.


Community Alums
Not applicable

Thanks Wade.



The other way I had considered would be to use the Service Catalog API (scripted rest api). I am not too familiar with it, though it might be a better alternative than using the Cart API or implementing additional business rules, etc to set those fields correctly.



Cheers,



Tim


Hi Tim,

Hope you all are safe and healthy ,

I have same requirement but need to generate 4 tasks and as well as 4 different assignment groups,

How can i achieve this could you help me on this please ?

Community Alums
Not applicable

I think you can use the same code as above, and kick off a flow/workflow which will create the tasks for you. 

Rohit_Burud
Tera Contributor
Hi Wade,
I have a similar kind of requirement in project.
Could you please help me with condition used in scheduled job.
 
Thanks in advance.