Creating one request with multiple items through a business rule

CharlesGriff
Mega Sage

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);

}

1 ACCEPTED SOLUTION

CharlesGriff
Mega Sage

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);


}


View solution in original post

5 REPLIES 5

CharlesGriff
Mega Sage

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);


}