The CreatorCon Call for Content is officially open! Get started here.

RITM field not poulating from inbound email rule

Sooriya3
Giga Guru
hi
I have the following script running on my inbound email rule
 
var req = new GlideRecord('sc_request');
req.initialize();
req.requested_for = email.from; // or use gs.getUserID() if appropriate
req.short_description = "Request from email: " + email.subject;
req.description = "Email body: " + email.body_text;
req.insert();
gs.log('line7:');
// Step 2: Create a new Requested Item (RITM)
var ritm = new GlideRecord('sc_req_item');
ritm.initialize();
ritm.request = req.sys_id; // Link RITM to REQ
ritm.short_description = req.short_description;
ritm.description = req.description;
 
while the desc and short desc in REQ is filling from the email.
And the short desc of the RITM is the same as the REQ, the desc field in the RITM is always empty.
 
There is nothing but the script populating fields and the table selected is the sc_req table. 
Anyone faced this kind of issue?
 
4 REPLIES 4

Sarthak Kashyap
Tera Guru

Hi @Sooriya3 ,

 

Please check below script 

var req = new GlideRecord('sc_request');
req.initialize();
req.requested_for = email.from;
req.short_description = "Request from email: " + email.subject;
req.description = "Email body: " + email.body_text;
req.insert();
gs.log('Request created: ' + req.sys_id);

var ritm = new GlideRecord('sc_req_item');
ritm.initialize();
ritm.request = req.sys_id;
ritm.short_description = req.short_description;
ritm.description = req.description;
ritm.cat_item = 'catalog_sys_id';

ritm.insert();
gs.log('RITM created: ' + ritm.sys_id);

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards,

Sarthak

Nehal Dhuri
Mega Sage

Hello @Sooriya3 ,
You forgot to add ritm.insert() after initializing the RITM details.
Just like you called req.insert() at the beginning of the log line 7, it's important to also call ritm.insert() after setting up the RITM object. This ensures the RITM data is properly saved.

Please hit like and mark my response as correct if that helps

kaushal_snow
Mega Sage

@Sooriya3 ,

 

The reason your sc_req_item record description isn’t populating even though the parent sc_request is is likely because you’re inserting the RITM manually via initialize()/insert() instead of going through the catalog flow  which handles the correct relationships and triggers; by default when you use the catalog API (for example var cart = new sn_sc.CartJS(); cart.addItem(...); cart.setVariable(...); var rc = cart.placeOrder();) the request and request item are created together and you can then reliably update the description and short_description on the RITM after the API completes.

If you stick with your manual script approach you should confirm that you’re: properly linking the RITM to the REQ via ritm.request = req.sys_id, then filling the fields after insert() of the REQ and before the insert() of the RITM, and lastly confirming that the description field on the RITM table is writable (no UI policy/business rule overwriting/clearing it)......

 

If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/

Ankur Bawiskar
Tera Patron
Tera Patron

@Sooriya3 

that's not an ideal way to create REQ and RITM as you are using GlideRecord

It won't trigger the associated Workflow or Flow linked to that item

your can use Inbound flow low-code, no-code approach and use "Submit Catalog Item Request" flow action to generate REQ, RITM and once that item is submitted it's associated Flow/Workflow will create the catalog task

check this link for help

Easiest way to Trigger Catalog Item Request via Inbound Email 

OR

You can also use inbound action and CartJS API to submit that catalog item

something like this

var cart = new sn_sc.CartJS();

var request1 = {

               'sysparm_id': 'ec10f4fd47266110b81cd855d36d4308', // sys_id of catalog item

               'sysparm_quantity': '1',

               'variables': {

                              'requested_for': '8efae6cbdb038b00d6563cae7c961',

                              'short_description': 'my short description',

                              'description': 'my description'

               }

};


var checkoutInfo = cart.checkoutCart();

var cartDetails = cart.orderNow(request);

var requestDetails = cart.submitOrder(request);

// you can parse the above JSON and query RITM and then update the fields you want

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader