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.

Need to generate RITM based on Variables value in Record Producer

Rekha Tiwari
Kilo Guru

Hi All,

I have Record Producer. which has variable called Will you require IT's assistance for your meeting? or "it_requirement". It is multiple choice type with Values: Yes, No, Do not know.

If its variable value is 'yes' then I have to auto create a RITMXXXXXX with already created catalog item:

 

Requirement is:

  • If Will you require IT's assistance for your meeting? = Yes a new catalog item is created with the following information:
    • Item type: Can't Find What I Need   (This is a catalog item existed)
    • (Field on RITM) Requested for: Event Host (Employee Name) - variable in Record producer
    • (Field on RITM) Due date: When is your event? (1st Choice) - variable in Record producer
    • Assignment Group: SG_SN-IT-ServiceDesk Tier I
    • State: Open
    • Approval: Not Required
    • Parent: WPS record created (show in Request Item form)
    • Short Description: IT Assistance for {Event Type} for {Requested for}
    • Area you need assistance with? Other
    • Provide a short description of your request: Same as short Description
    • Provide a detailed explanation and justification of your request:
      • Reference {WPE #}
      • Event Host:
      • Event type: 
      • Event Format:
      • Event Title Name: 
      • Event Description = Describe this event, including its purpose
      • Event 1st Choice:
      • Event 2nd Choice:
      • Expected Number of Attendees:
      • Requested Country:
      • Other Requests/Notes: 

Attached is the Catalog item form

 

 

Please help me how to proceed.

1 ACCEPTED SOLUTION

Hi,

you cannot set field using Cart API

So update as this -> you need to query RITM with the REQ sysId and then update the record

if (producer.it_requirement == 'yes') {
    try {
        var cartId = GlideGuid.generate(null);
        var cart = new Cart(cartId);
        //add your requested item to the cart by sys_id of the catalog item
        var item = cart.addItem('ed8e941a1bee9010f5bef5f61a4bcb82', 1); 

        //fill in the variables on the request item form
        cart.setVariable(item, "requested_for", producer.event_host);
        cart.setVariable(item, "state", "1");
        cart.setVariable(item, "due_date", producer.virtual_event_choice_1);
        cart.setVariable(item, "assignment_group", "0a064b7f1b8bd410eda185d7cc4bcb3d"); 
        cart.setVariable(item, "approval", "not_required");
        var rc = cart.placeOrder();
        gs.info(rc.number);
        
        var ritm = new GlideRecord('sc_req_item');
        ritm.addQuery('request', rc.sys_id);
        ritm.query();
        if(ritm.next()){
            ritm.parent = current.sys_id;
            ritm.update();
        }
        

    } catch (ex) {
        gs.info(ex);
    }
}

Regards
Ankur

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

View solution in original post

17 REPLIES 17

Hi,

how are you creating RITM? you can use after insert BR on your table u_workplace_service

In that script itself you can set parent field of RITM with the current.sys_id i.e. record of table u_workplace_service

Regards
Ankur

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

Hi @Ankur Bawiskar 

I am creating RITM using script in Record producer:

if (producer.it_requirement == 'yes') {
    try {
        var cartId = GlideGuid.generate(null);
        var cart = new Cart(cartId);
        //add your requested item to the cart by sys_id of the catalog item
        var item = cart.addItem('ed8e941a1bee9010f5bef5f61a4bcb82', 1); 

        //fill in the variables on the request item form
        cart.setVariable(item, "requested_for", producer.event_host);
        cart.setVariable(item, "state", "1");
        cart.setVariable(item, "due_date", producer.virtual_event_choice_1);
        cart.setVariable(item, "assignment_group", "0a064b7f1b8bd410eda185d7cc4bcb3d"); 
        cart.setVariable(item, "approval", "not_required");
        cart.setVariable(item, "parent", current.sys_id);
        var rc = cart.placeOrder();
        gs.info(rc.number);

    } catch (ex) {
        gs.info(ex);
    }
}

 

But Parent field is still blank.

Hi,

is parent a variable on your catalog item or field on RITM table?

Regards
Ankur

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

Hi,

It is on RITM table.

Hi,

you cannot set field using Cart API

So update as this -> you need to query RITM with the REQ sysId and then update the record

if (producer.it_requirement == 'yes') {
    try {
        var cartId = GlideGuid.generate(null);
        var cart = new Cart(cartId);
        //add your requested item to the cart by sys_id of the catalog item
        var item = cart.addItem('ed8e941a1bee9010f5bef5f61a4bcb82', 1); 

        //fill in the variables on the request item form
        cart.setVariable(item, "requested_for", producer.event_host);
        cart.setVariable(item, "state", "1");
        cart.setVariable(item, "due_date", producer.virtual_event_choice_1);
        cart.setVariable(item, "assignment_group", "0a064b7f1b8bd410eda185d7cc4bcb3d"); 
        cart.setVariable(item, "approval", "not_required");
        var rc = cart.placeOrder();
        gs.info(rc.number);
        
        var ritm = new GlideRecord('sc_req_item');
        ritm.addQuery('request', rc.sys_id);
        ritm.query();
        if(ritm.next()){
            ritm.parent = current.sys_id;
            ritm.update();
        }
        

    } catch (ex) {
        gs.info(ex);
    }
}

Regards
Ankur

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