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

abelangulo
Kilo Contributor

Just to update the community:


The script does work and populates the variables, but for some reason, the log keeps giving the "Skipping 'Create OnBoarding Request', did not create or update sc_req_item" message... I haven't had the time to add do debugging...


Also, in case somebody is wondering/looking for an answer (this wasn't clear to me at the beggining), if the incoming email contains a line like this:


Full Name: Abel Angulo


...the variable created will be email.body.full_name with value "Abel Angulo"


What is the condition you have on the inbound action?


The only condition I have for now is: email.subject.startsWith("New Hire")


I've always used indexOf in my inbound action conditions, but according to the wiki, your method should be fine.



Condition on the request


email.subject.toLowerCase().indexOf('new hire') > -1



Opposite condition on the incident create catch all inbound action


email.subject.toLowerCase().indexOf('new hire') == -1