The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How to create recurring service request from service catalog or template?

jmats
Giga Contributor

Hi I'm creating a scheduled task which will generate a pref-filled service request (Request, Request Item and Catalog Task). I know how to setup the schedule but I'm having trouble generating all three task and have them linked to each other.

I tried doing it via templates but I can only either create one, but I need all three created and linked to each other. I tried Next Related Child Template and Link Element but this doesn't link the request items to request or catalog taks, they are created separately.

I also tried using Cart but it doesn't generate any ticket;

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('52ded723db92eb4081a0a03114961964');
var rc = cart.placeOrder();
gs.addInfoMessage(rc.number);

 

Please help! thank you in advance.

1 ACCEPTED SOLUTION

jmats
Giga Contributor

SOLVED!!!

Go to System Definition->  scheduled Job-> New 

Select Automatically run a script of your choosing

and use this script:

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('b6088febdbc4f7c0a9a28e35059619d5'); // sys_id of catalog item
infoMessage += 'Created cart with id: ' + cartId + '\n';

var requestingUser = new GlideRecord('sys_user');
var reqUserName = 'guest.email'; // The requested for user
requestingUser.addQuery("user_name", reqUserName);
requestingUser.query();
if(requestingUser.next()) {
infoMessage += 'Loaded user: ' + requestingUser.name + '\n';
cart.setVariable(item, "requested_for", requestingUser.sys_id);
cart.setVariable(item, "company", requestingUser.company);
} else {
infoMessage += 'ERROR: Failed to load user: ' + reqUserName + '\n';
}

// Set the short_description, description and business_justification
cart.setVariable(item, "short_description", "Your Short Description");
cart.setVariable(item, "description", "Your Description");
cart.setVariable(item, "business_justification", "Your Business Justification");

// Place the order
var rc = cart.placeOrder();
infoMessage += 'Request Number: ' +rc.number;
gs.info(infoMessage);

View solution in original post

5 REPLIES 5

Anurag Tripathi
Mega Patron
Mega Patron

You have the option to create records frm templates and schedule them, all OOB

Navigate to System Definition->  scheduled Job-> New

find_real_file.png

Then you just schedule the frequency at which you want to generate the record, and sselect the template, done.

find_real_file.png 

 

-Anurag

-Anurag

Thanks Mate, I am able to make this part with no issues.

Only part I'm having issue is where it needs to generate Request Item which includes the Request Task and Catalog Task.

find_real_file.png

in Templates, you can only generate one record(RITM), not all three records (REQ,RITM,SCTASK) - which I need to make happen.

That might be tricky, thinking , will post back if i get some idea. 

In your question you mentioned template so I thought if this way.

-Anurag

Hi,

It sounds like you have created a catalog item and you are creating a request through the below script.
It creates a RITM request fine.

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('52ded723db92eb4081a0a03114961964');  // sys_id of catalog item
var rc = cart.placeOrder();
gs.addInfoMessage(rc.number);

 

You need to check, it creates a RITM request under the REQ request.
If it is fine, then in the workflow you need to create a catalog task as per your need. It will include as REQ---> RITM--->Catalog Task.

Thanks,

Sagar Pagar

 

The world works with ServiceNow