- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2017 03:24 AM
Hi
I have created a business rule that creates requests when I do an import on a custom table, this is so that the client can import requests from their clients and then it creates the necessary requests with workflow etc, but I want the script to rather just create one Request with multiple Requested Items. How can I update the cart after each new table entry and then after lets say 30 entries submit the cart.
The script runs after Insert.
createRequest();
function createRequest(current, previous) {
//Create Request
var cart = new Cart();
//substitute your cat item
var item = cart.addItem('0ce5ac3fdb266200afbcfc45ae961965');
//Set Variables in your Cart Item
//substitute your req for
cart.setVariable(item, 'name', current.u_name) ;
cart.setVariable(item, 'job_title', current.u_job_title) ;
cart.setVariable(item, 'email', current.u_email) ;
cart.setVariable(item, 'telephone', current.u_telephone) ;
cart.setVariable(item, 'cell_phone', current.u_cell_phone) ;
cart.setVariable(item, 'physical_install_address', current.u_physical_install_address) ;
cart.setVariable(item, 'latitude', current.u_latitude) ;
cart.setVariable(item, 'longitude', current.u_longitude) ;
cart.setVariable(item, 'link_size', current.u_link_size) ;
cart.setVariable(item, 'additional_comments', current.u_additional_comments) ;
cart.setVariable(item, 'End_Client', current.u_end_company_name) ;
cart.update();
var rc = cart.placeOrder();
cart.description = 'Bulk Import';
gs.addInfoMessage('Request Item Created: ' + rc.number);
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2017 11:31 PM
In the end I used the cart and we had to change the default cart script not to create a new request with every new item being imported, we then just click checkout after the cart has been created from the bulk import. So the Business rule and the script include needs to be changed to accommodate the needed effect.
//First function of script include//
initialize: function(cartName, userID) {
this.cartName = !cartName ? null : cartName;
this.userID = !userID ? null : userID;
this.cart = this.getCart();
//this.clearCart();
},
//Business rule//
createRequest();
function createRequest() {
//Create Request
var cart = new Cart("DEFAULT", gs.getUserID());
//substitute your cat item
var item = cart.addItem('0ce5ac3fdb266200afbcfc45ae961965');
//Set Variables in your Cart Item
//substitute your req for
cart.setVariable(item, 'name', current.u_name_and_surname) ;
cart.setVariable(item, 'job_title', current.u_job_title) ;
cart.setVariable(item, 'email', current.u_email) ;
cart.setVariable(item, 'telephone', current.u_telephone) ;
cart.setVariable(item, 'cell_phone', current.u_cellphone) ;
cart.setVariable(item, 'physical_install_address', current.u_physical_installation_address) ;
cart.setVariable(item, 'latitude', current.u_latitude) ;
cart.setVariable(item, 'longitude', current.u_longitude) ;
cart.setVariable(item, 'link_size', current.u_link_size) ;
cart.setVariable(item, 'additional_comments', current.u_additional_comments) ;
cart.setVariable(item, 'End_Client', current.u_end_company_name) ;
cart.update();
//var rc = cart.placeOrder();
cart.description = 'Comsol CFX Bulk Import';
gs.addInfoMessage('Request Item Created: ' + rc.number);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2017 03:49 AM
Hi,
In my opinion, kindly see transform map scripts. Since the script action you needed is after the upload.
http://wiki.servicenow.com/index.php?title=Transform_Map_Scripts#gsc.tab=0
and then your script should be like this.
var cartId = GlideGuid.generate(null);
//query on the table where the data is
var getData = new GlideRecord(<insert table name here>);
getData.addQuery('u_import_set_id',source.sys_import_set.sys_id); //u_import_set_id column should be included in the table.. I have little idea about this sorry
getData.query():
//generate id
var cartId = GlideGuid.generate(null);
while(getData.next()){
//pass cart id
createRequest(cartId);
}
function createRequest(p_cartId){
var cart = new Cart(p_cartId);
var item = cart.addItem('0ce5ac3fdb266200afbcfc45ae961965');
//replace variables then update
cart.addVariable(item,'var1',getData.u_fieldName);
cart.update();
var rc = cart.placeOrder();
cart.description = 'Bulk Import';
}
Its not tested but the idea is the script will run after the import is done, that's the Transform map script... Since business rule triggers every after a record has been inserted/updated in the table..
I know this is not the answer but I hope this can help at least a bit.
Thanks,
a.c.manlangit
ServiceNow Developer - Philippines

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2017 04:10 AM
Hi Charles,
Have you tried adding multiple items in the same cart, before placing the order. I believe, that would keep adding mulitple items to a same request. Also, I agree with ariesmanlangit above and you could put all this processing into an onComplete transform map script.
-Mandar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2017 12:05 AM
Hi Mandar
The cart is working perfectly and we have built our service portals to make use of the shopping cart so that is fine and the idea is that the end customer will make use of this in the future rather than emailing bulk excel sheets with orders, but in the meantime we need to cater for both scenarios.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2017 12:03 AM
Hi Guys
Just to give you some more information I am not using a transform map and the reason for that is due to the fact that we are going to have a sales person handling the importing and they will be doing it directly on the table with the excel template, so there goes the idea of a transform script. If I cannot do this with a business rule then I would not do it at all.