Once create a cat item (cart.placeOrder() method)u sing a business rule , Request variables are not set.

Dushan
Kilo Contributor

I'm involved in developing a  onboarding task which takes an excel sheet. There I have created a data source  ( for excel in [sys_data_source]) which will be uploaded to a importset table from there the data is transformed to a staging table with the help of Transform Map. The staging table contains onbefore business rule that creates a cart item to populate an existing catalog item called  onboarding. 

My issue is once I create the cat item then try to set some Request variables (requested_for, description ) after executing ' cart.placeOrder() '. that does not work. Plesae explane why is it, and a work arround to set Request parameters.


var cart = new Cart();

var item = cart.addItem(itemsysid)

cart.setVariable(item, 'rr_id', current.u_rr_id);

cart.setVariable(item, 'irec_vacancy_id', current.u_irec_vacancy_id);

cart.setVariable(item, 'irec_status', current.u_irec_status);

cart.setVariable(item, 'applicant_id', current.u_applicant_id);

cart.setVariable(item, 'nationality', current.u_nationality);

cart.setVariable(item, 'location', current.u_location);

cart.setVariable(item, 'first_name', current.u_name_of_the_candidate);

cart.setVariable(item, 'name_in_upload_file', current.u_name_of_the_candidate);

cart.setVariable(item, 'name_of_the_candidate', current.u_name_of_the_candidate);

 

 

var rc = cart.placeOrder();

rc.description ="Created via Excel import"; // is not set

rc.requested_for=current.u_requested_by;// is not set

current.u_request_number=rc.number;

rc.update();

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

why not create/set the variables during the creation itself?

why to update it later?

Are you willing to update the REQ record? if yes then update as below

var rc = cart.placeOrder();

var req = new GlideRecord('sc_request');

req.addQuery('number', rc.number);

req.query();

if(req.next()){

req.description ="Created via Excel import"; // is not set

req.requested_for = current.u_requested_by;// is not set

current.u_request_number=rc.number;

req.update();

}

Regards
Ankur

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

View solution in original post

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

why not create/set the variables during the creation itself?

why to update it later?

Are you willing to update the REQ record? if yes then update as below

var rc = cart.placeOrder();

var req = new GlideRecord('sc_request');

req.addQuery('number', rc.number);

req.query();

if(req.next()){

req.description ="Created via Excel import"; // is not set

req.requested_for = current.u_requested_by;// is not set

current.u_request_number=rc.number;

req.update();

}

Regards
Ankur

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

Hi Ankur,

 

How to set description in RITM form?

 

Please help

 

Thanks

Hi,

I posted solution to your question.

Please run, test and mark my response as correct and helpful.

Set Values in Scheduled Job

Regards
Ankur

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

Ankur Bawiskar
Tera Patron
Tera Patron

@Dushan 

Any update on this?

Regards
Ankur

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