Set assignment_group using CartAPI script

HudyssonPOntes
Tera Expert

Good evening, how are you? Could someone please help me set an assignment_group using a script with the Cart API? My script is currently written like this:

 

var cartId = GlideGuid.generate(null);
    var cart = new Cart(cartId);
    var item = cart.addItem('554c893633ddae543e29df4a7e5c7bd9');
   

    //fill in the variables on the request item form
    cart.setVariable(item, "nome_desligado", inputs.nome_desligado);
    cart.setVariable(item, "manager_tripulante", inputs.manager_tripulante);
    cart.setVariable(item, "localidade_tripulante", inputs.localidade_tripulante);
    cart.setVariable(item, "re_desligado", inputs.re_desligado);
    cart.setVariable(item, "termination_request", inputs.termination_request);
    cart.setVariable(item, "description_of_termination", inputs.motivo);
    cart.setVariable(item, "asset_model_category", inputs.asset_model_category);
    cart.setVariable(item, "asset", inputs.asset);
    cart.setVariable(item, "motivo", "Recolhimento de equipamento por motivos de desligamento.");
    cart.assignment_group = inputs.assignment_group; // <- this line does not work
    var rc = cart.placeOrder();
 
HudyssonPOntes_0-1748553362754.png

 

If anyone could assist me, I would be immensely grateful. Thank you very much!

3 REPLIES 3

James Chun
Kilo Patron

Hi @HudyssonPOntes,

 

I found an answer from another question - https://www.servicenow.com/community/developer-forum/using-cart-placeorder-return-object/m-p/1621741

 

Although I wouldn't recommend using a script to set the assignment group via a script.

You want to have a 'central' place to store the logic for assignment and using an Assignment Rule would be a better approach here.

 

Cheers

Ankur Bawiskar
Tera Patron
Tera Patron

@HudyssonPOntes 

you can't set the assignment_group field on RITM using cart API, it can only set the variables associated to catalog item

You can update the RITM once cart is submitted

something like this

// your earlier code

var reqNumber = rc.number;

var ritm = new GlideRecord('sc_req_item');
ritm.get('request.number', reqNumber);
ritm.assignment_group = 'groupSysId';
ritm.update();

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

Robert H
Mega Sage

Hello @HudyssonPOntes ,

 

As others have already pointed out it's not possible to set the Assignment group of a request via the Cart API.

That would be like ordering something at Amazon but also telling them which internal team should work on your order.

 

Instead, your Catalog Item should be tied to a Flow/Workflow, and it's there that the assignment should happen. Or you can also use Assignment Rules.

 

Regards,

Robert