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

Paul35
ServiceNow Employee
ServiceNow Employee

Hi Chuckn,

Sorry my memory is a little hazy on what version of ServiceNow I was using when I wrote that post. At the time, I didn't run into any number generation issues.

I have however, tested on a more recent version of ServiceNow (London) and have encountered the same issue you have where the number has incremented by 2 when the cart order is placed.

I suspect that the inbound action is creating a temporary record as the "current" object which is the next number in the table so when you call the Cart API it creates another new record which is then the next number after the "current" object. 

I have tried to clear the current record (current.initialize) so that the cart would have the correct number to no avail so I would suggest creating a case for ServiceNow Support so that we can investigate further.

 

Regards,

 

Paul

 

Thanks for your reply, Paul!  I think the same thing is happening regarding current.  As a workaround, I may use a custom table that has no number field...that seems to work (as wonky as it would be).  I think I will open a support case on it--will let you know the outcome!

-Chuck

Hi Chuck, 

You can try System Properties > System > Assign a task number only upon insert (prevents unused numbers). Check the box to mark it yes. 

I'm thinking that should fix your issue. 

Wow, I had no idea that property existed!! (https://docs.servicenow.com/bundle/kingston-platform-administration/page/administer/field-administra...)

Have you used it before yourself?  If so, did you encounter any issues where scripts/code may have been initializing a record and then grabbing the number to use before that record was actually saved/inserted?

Thank you!

No prob! 

Yes I have used it before when I was having this issue actually. I was on Jakarta at the time and I seem to remember it fixing the issue. Since my upgrade to Madrid it doesn't appear to be happening anymore even though the box isn't checked.