Cart API / Service Catalog Script API

abelangulo
Kilo Contributor

Hello,

I'm pretty new to the SN world, and I have an issue I want to see if you guys can help me with.

I created the Inbound Email Action (shown below) for our On-Boarding process, but

1) Sometimes it works, sometimes it doesn't (giving only the following info: "Skipping 'Create OnBoarding Request', did not create or update sc_req_item"). I haven't been able to pin point how, when, or why...

2) When it does work, it doesn't populate any of the variables (values hard-coded for now), or at least they don't show in the item created.

Any help would be really appreciated.

Thank you.

=======================================================

Target Table: Requested Item [sc_req_item]

 

=======================================================

gs.include('Cart');

createRequest();

function createRequest() {

      var cart = new Cart();

      // add in cart, substitute your cat item sys_id

      var item = cart.addItem('ec2f659a6fa29100bbc6dd1cbb3ee4f6'); // On-boarding

      //var item = cart.addItem('ea77984a6f629100bbc6dd1cbb3ee452'); // Configuration Auths for testing purposes  

      // set requested for, substitute your requested for

      //Set Variables in your Cart Item

      // REQUESTOR INFORMATION

      cart.setVariable(item, 'type', 'New Employee');

      cart.setVariable(item, 'title', 'Any Title');

      cart.setVariable(item, 'email', 'Abel.Angulo@avmed.org');

      cart.setVariable(item, 'department', 'IS');

      cart.setVariable(item, 'phone', '305-671-0226');

      //gs.addInfoMessage("Requestor finish");

      //EMPLOYEE INFORMATION

      cart.setVariable(item, 'full_name', 'Pepito Perez'); //email.body.name);

      cart.setVariable(item, 'emp_title', 'Empl Title'); //email.body.title);

      cart.setVariable(item, 'emp_department', 'IS'); //email.body.department);

      cart.setVariable(item, 'emp_location', 'Miami'); //email.body.location);

      cart.setVariable(item, 'eff_date', '2014-05-01'); //email.body.start_date);

      //gs.addInfoMessage("Employee finish");

      //HARDWARE REQUIREMENTS

      cart.setVariable(item, 'service_desk_system', 'Desktop');

      var cartmsg = "Received from: " + email.origemail + "\n\n" + email.body_text;

      cart.setVariable(item, 'description', cartmsg);

      var rc = cart.placeOrder();

      //gs.addInfoMessage(rc.number);

}

26 REPLIES 26

Also, I think your inbound action will have to have the Target Table: Shopping Cart [sc_cart]


Even though I changed the   Target Table to sc_cart it still generates the same error.


"Skipping 'Create OnBoarding Request', did not create or update sc_req_item")


Hi Kate,



I think you need to add a current.update(); RIGHT AFTER the var rc = cart.placeOrder(); line at the end. See my other reply in this thread for more information. Hope it helps!



Regards,


Bryce


Hi Kate,



Were you able to get the final solution. It would be helpful if you post it here.



Thanks,


Dedeepya


Hi dedeepyatirugu,



I've got it working by using sc_request as Target Table.



//1. Creates a new cart, with cartID as the name and the sys ID as the creator  


var cartId = GlideGuid.generate(null);  


var cart = new Cart(cartId);  



//2. Adds the "onboarding" form to the cart  


var item = cart.addItem('a0700cba13be16405d02735fd144b04d');  



//3. Get the values from the email


var uName = email.body.user_name;


var nCompany = email.body.company;


var nDprt = email.body.department;


var nComments = email.body.comments;



//4.Populate values from email to variable form


cart.setVariable(item, 'comments', "received from: " + email.origemail + "\n\n" + nComments + "\n\n" + email.body_text);  


cart.setVariable(item, 'company', nCompany);


cart.setVariable(item, 'uname', uName );


cart.setVariable(item, 'department', nDprt);



//5. Submits the RITM/cart  


var rc = cart.placeOrder();  




regards,


Kate