Need to pass ritm field values to work flow which is calling from the script

Indup
Tera Expert

I am creating a request from inbound action. And I am creating corresponding ritm using business rule. In the business rule after creating the ritm, I am calling a workflow which is on requested item table. There is only one run script activity in the workflow. In that run script activity, I want the ritm number and requested for values in a scratchpad variable. Workflow is triggering but the related ritm number and requested for is not coming . I checked with log messages also. Can someone help me here. It's a bit urgent

For my code, please see this link

https://community.servicenow.com/community?id=community_question&sys_id=b1745ecd1b946410305fea89bd4bcb41

 

 

Regards,

Indup

21 REPLIES 21

Yeah, right!

That's the correct way to do it.

But for this, you need to have a catalog item (without any variables/scripts as required by you), item should have name and workflow that you want to attach. As, this cart API automates everything, request/RITM will be created and workflow will be automatically attached.

Catalog Item (fill it acc to your requirement)

find_real_file.png

find_real_file.png

 

Script in Inbound Action:

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem(<sysid of catalog item>);

var rc = cart.placeOrder();
gs.addInfoMessage("Request Created " + rc.number);
var popFields = new GlideRecord("sc_request");
popFields.addQuery("number",rc.number);
popFields.query();
if(popFields.next())
{

popFields.u_title = email.body.title; // fields that you want to populate
.
.
.
popFields.update();
}

Workflow (Run script)

current.number gives RITM Number

current.request.requested_for gives Requested for 

 

Hello Shivani,

Thanks for the code. But once i send mail to snow, request is not getting created. When i check the email received, it is showing like this,

find_real_file.png

 

Body Text Contains1 is the name of my inbound action. And i have a doubt, in your code why did u glide record request table when inbound action is already present on Request?

 

 

Regards,

Indup

This is my Inbound action code:

find_real_file.png

Oh, didn't notice that then keep it this way

 

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem(<sysid of catalog item>);

var rc = cart.placeOrder();
gs.addInfoMessage("Request Created " + rc.number);

rc.u_title = email.body.title; // fields that you want to populate
.
.
.
rc.update();
}

Shivani,

 

Request is getting created now. But RITM is not created. And find_real_file.png

Log messages:

Cart here is [object Object]

Item here is null

 

& i checked info message in system logs, Request here is not coming

 

 

Regards,

Indup