Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

To set value to the RITM catalog item variables in inbound actions script

Suprithabhonsle
Tera Expert

Hi,

I have catalog with variables like user id, name, email etc.

I am sending an email to servicenow with details like user id: 1234, name: example etc. I am using inbound actions script to fetch details and create a RITM for this. But when I am trying to set values to the catalog variables, the created RITM which has catalog variables is not seen. How can I solve this issue.

 

Below script to fetch from the email and creating RITM.

 

(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
    // Extract the email subject and body
    var email_subject = email.subject;
    var email_body = email.body_text;

    // Parse the email body to extract necessary details
    var details = {};
    var lines = email_body.split('\n');
    lines.forEach(function(line) {
        var parts = line.split(':');
        if (parts.length === 2) {
            var key = parts[0].trim().toLowerCase();
            var value = parts[1].trim();
            details[key] = value;
        }
    });

    // Create a new request
    var requestGr = new GlideRecord('sc_request');
    requestGr.initialize();
    requestGr.setValue('short_description', 'Request from email for employee: ' + details['employee id']);
    var requestSysId = requestGr.insert();

    // Create a new request item for the custom catalog item
    var itemGr = new GlideRecord('sc_req_item');
    itemGr.initialize();
    itemGr.setValue('cat_item', 'dc3b44591b7b8e545e056531604bcb5f'); // sys_id for catalog 
    itemGr.setValue('request', requestSysId);
    itemGr.setValue('short_description', 'Request for employee: ' + details['employee id']);

    // Set the catalog item variables
    itemGr.setValue('employee_id', details['employee id']);  // Custom variable field name
    itemGr.setValue('user_id', details['user id']);          // Custom variable field name
    itemGr.setValue('first', details['firstname']);       // Custom variable field name
    itemGr.setValue('last_name', details['lastname']);         // Custom variable field name
    itemGr.setValue('phone_number', details['phone number']); // Custom variable field name
    itemGr.setValue('email', details['email']);               // Custom variable field name
    itemGr.setValue('manager', details['manager']);           // Custom variable field name

    var itemSysId = itemGr.insert();
    // gs.eventQueue('sc_req_item.create', itemGr, '', '');
})(current, event, email, logger, classifier);
 
Help me to solve the issue.
Thanks in advance.
1 REPLY 1

Hemanth M1
Giga Sage
Giga Sage

Hi @Suprithabhonsle , 

 

Use Cartapi to create request and RITM in your inbound

 

ex:

 var cartId = GlideGuid.generate(null);
        var cart = new Cart(cartId);
        var item = cart.addItem('xyz'); ///substitute your cat item sys_id
        cart.setVariable(item, 'variable backend name', 'value');      //Set Variables in your Cart Item
        var rc = cart.placeOrder(); // retuns sys_id of the Req , this would generate Req and RITM

 

Hope this helps!!

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025