Create RITM and Catalog task through Inbound email

N Afreen
Tera Contributor

Hi
I have a requirement, RITM and Catalog task will be created when an email sent to SNow. I tried through Inbound Action. Ritm is creating but Catalog task is not creating.

Requested for is not populating in RITM as it should be taken from email body. Any one can help me please
Here is my Inbound action Script:
RITM ---

var REQ = new GlideRecord('sc_request');
REQ.requested_for = email.body.userid;

current.stage = 'fulfillment';
current.approval='approved';
current.state = 'New';
current.description = email.body_html;
current.cat_item.setDisplayValue('User update');
current.insert();
event.state = "stop_processing";

----
Catalog Task ---
var REQ = new GlideRecord('sc_request');
REQ.requested_for = email.body.userid;
current.location = email.body.location;
current.description = email.body_html;
current.state = 'Assigned';
current.insert();
----

4 ACCEPTED SOLUTIONS

Saurabh Gupta
Kilo Patron
Kilo Patron

Hi,
Do you have a catalog in the system that needs to be submitted by inbound action?
If yes, please use cart API to submit the catalog. If there is a flow/workflow attached to it you can easily create catalog inside flow/wf.

 

Below is a sample script.

 

 var cartId = GlideGuid.generate(null);
var catalogItemID = "526c35c71b8005508a6c9821b24bcb36";
var cart = new Cart(cartId);
var item = cart.addItem(catalogItemID);
cart.setVariable(item, "requestedby",gs.getUserID());//name of catalog item variable
cart.setVariable(item, "requestedfor",gs.getUserID());///name of catalog item variable
cart.placeOrder();

 

 

 

 


Thanks and Regards,

Saurabh Gupta

View solution in original post

Hi,
In servicenow, you should create the task using workflow/flow.
Technically it possible to create catalog task using script as it is just a record of table but we should not be creating the task in this way.

Anyways Catalog management in servicenow having three table involved-

REQ (Always created if a catalog is raised)
RITM (Always created)
SCTASK (Optional)

First you should raise a catalog using cart API, after that you can create catalog task using script.

 

  


Thanks and Regards,

Saurabh Gupta

View solution in original post

Please share you ritm record screenshot as well.


Thanks and Regards,

Saurabh Gupta

View solution in original post

Hi,
Use below code (Be aware this all is ok for practice purpose but in projects you should do in a way that servicenow recommend)

var REQ = new GlideRecord('sc_request');
var usr=new GlideRecord('sys_user');
usr.get('user_name',email.body.userid)
REQ.requested_for = usr.sys_id;
REQ.insert();
current.request=REQ.sys_id;
current.stage = 'fulfillment';
current.approval='approved';
current.state = 'New';
current.description = email.body_html;
current.cat_item.setDisplayValue('User update');
current.insert();

event.state = "stop_processing";


 


Thanks and Regards,

Saurabh Gupta

View solution in original post

9 REPLIES 9

Share you script please.


Thanks and Regards,

Saurabh Gupta

var REQ = new GlideRecord('sc_request');
REQ.requested_for = email.body.userid;

current.stage = 'fulfillment';
current.approval='approved';
current.state = 'New';
current.description = email.body_html;
current.cat_item.setDisplayValue('User update');
current.insert();
event.state = "stop_processing";

Please share you ritm record screenshot as well.


Thanks and Regards,

Saurabh Gupta

 

Email body:

UserID: ABELT

Last Name: Tuter

First Name: Abel

 

Requested for should be populate by "Abel Tuter"

Hi,
Use below code (Be aware this all is ok for practice purpose but in projects you should do in a way that servicenow recommend)

var REQ = new GlideRecord('sc_request');
var usr=new GlideRecord('sys_user');
usr.get('user_name',email.body.userid)
REQ.requested_for = usr.sys_id;
REQ.insert();
current.request=REQ.sys_id;
current.stage = 'fulfillment';
current.approval='approved';
current.state = 'New';
current.description = email.body_html;
current.cat_item.setDisplayValue('User update');
current.insert();

event.state = "stop_processing";


 


Thanks and Regards,

Saurabh Gupta