- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2020 10:42 PM
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();
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2020 11:06 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2020 03:05 AM
Hi
"At the creation time" means, is that the time the catalog item was created via [catalog definition >maintain item]? or In the Business rule execution.(Did you mean to create the variable in cart like beneath?)
cart.setVariable(item, 'requested_for', <set the value>);
Or first to create the variable in catalog item at variable section and include the above code in Business rule?
If we include the code shown above will it be an issue as I haven't created the requested_for currently in catalog item seperately under variable section
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2020 03:26 AM
Hi Dushan,
the CART API will set variable value if the variable exists for that catalog item.
If the variable is present and you don't wish to set it via Cart API then you can still update it after RITM creation after this line
var rc = cart.placeOrder();
So what is exactly required here?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2020 03:35 AM
Ok , In that case the 'requested_for' variable was not created by the time the catalog item had been initially created . But my requirement is to set this value in the created Request as a result of submitting the cat item.
So I will go for the code that you have shared. many thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2020 03:49 AM
You are welcome
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader