Catalog item submission from inbound action

LaraReddy
Tera Guru

Hi All,

We have used the below inbound action script to submit the catalog item and it's working fine BUT the variable set variables are not populating even through variable set variables are populated during the submission of catalog item.

Since we are new to these inbound actions, we are not sure how to pass the requested for user's manager name to variable set variable and call the same on below script level.

(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {

    var cartID = GlideGuid.generate(null);
    var cart = new Cart(cartID);
    var item = cart.addItem('c1841dde1bb63f806c47419ead4bcbc5');
    cart.setVariable(item,'oar_additional_access',email.body_text);
    var rc = cart.placeOrder();

 var ritm = new GlideRecord("sc_req_item");
 ritm.addQuery("request",rc.sys_id);
 ritm.query();
 if(ritm.next())
{
ritm.short_description = email.subject.toString();
ritm.contact_type = "email";
ritm.update();

}
})(current, event, email, logger, classifier);


Advance thanks.
6 REPLIES 6

Community Alums
Not applicable

Hi @LaraReddy ,

 

To pass the requested user's manager name to variable in script for submitting a catalog item, you need to retrieve the manager's name from the user's profile and then set it as a variable in the cart.

 

Please use the below script to solve your issue-

 

(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {

    var cartID = GlideGuid.generate(null);
    var cart = new Cart(cartID);
    var item = cart.addItem('c1841dde1bb63f806c47419ead4bcbc5');
    cart.setVariable(item, 'oar_additional_access', email.body_text);

    // Get the user's manager name
    var userGr = new GlideRecord('sys_user');
    if (userGr.get(current.requested_for)) {
        var managerName = userGr.manager.getDisplayValue();
        cart.setVariable(item, 'manager_name', managerName); // set the correct variable name used in the cart item for manager, here we have used manager_name
    }

    var rc = cart.placeOrder();

    var ritm = new GlideRecord("sc_req_item");
    ritm.addQuery("request", rc.sys_id);
    ritm.query();
    if (ritm.next()) {
        ritm.short_description = email.subject.toString();
        ritm.contact_type = "email";
        ritm.update();
    }

})(current, event, email, logger, classifier);

 

 

If my response has resolved your query, please consider giving it a thumbs up ‌‌ and marking it as the correct answer‌‌!

 

Thanks & Regards,

Sanjay Kumar

 

Hi Sanjay, 

Thanks for the response.

We tried your suggestion but still the manager variable is not populating.

Earlier we used to see the manager field as mandatory on RITM variable section level but due to the above script mandatory not showing but data is not populating.

 

@Sandeep Rajput  and @Community Alums  Could you please help us here.


Advance thanks.

LaraReddy
Tera Guru

Hi All,
Can anyone please help us here.

Thanks.

@LaraReddy 

in your script you are not populating/setting the variable values hence it's not getting populated

this is the syntax to set the value

cart.setVariable(item, "managerVariableName", "userSysId");

If my response helped please mark it correct and close the thread so that it benefits future readers.

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