- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2022 07:24 AM
Hello All,
I have been trying to achieve the functionality where when i send an email to my service now my developer instance, it should trigger the inbound email action and should create the request and requested item for the service catalog demo Need Access card.
I have created an inbound action as below:-
Target Table - sc_req_item
Action Type - Record action
Type - New
From - System Administrator where i have put the email address of my gmail account.
The script is like below:-
(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
// Implement email action here
gs.include('Cart');
createrequest();
function createrequest(){
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId,'6816f79cc0a8016401c5a33be04be441'); // (cartId, sys_id of the requested_for_user)
var item = cart.addItem('d34870c01bdfc110b9aa40c6cc4bcb43');// (sys_id of the cart item, i got from sc_table form, attached screenshot for more reference);
cart.setVariable('item','requested_for','6816f79cc0a8016401c5a33be04be441');
cart.setVariable('item','state','maharashtra');
cart.setVariable('item','city','shanisignapur');
cart.setVariable('item','employee_details',email.subject.toString());
var rc = cart.placeOrder();
current.update();
var reqrecord = new GlideRecord('sc_request');
reqrecord.get(rc.sys_id);
reqrecord.requested_for = '6816f79cc0a8016401c5a33be04be441';
reqrecord.update();
}
})(current, event, email, logger, classifier);
The issue is that the above script is only creating requested_item with all the blank values, it is even not picking the item which should be service catalog name). when i check the system Logs , it is mentioned like this
Item does not exist : d34870c01bdfc110b9aa40c6cc4bcb43
Any leads would be appreciated
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2022 10:24 AM
I think the problem is in your cart.addItem statement. The .addItem is the sys_id of the Catalog Item that you are looking to add, and from your screenshot I am not sure if that's the sys_id you are adding.
For example, this is an item that ServiceNow provides out of the box. You would use the sys_id of this item (d0b15e33d7033100a9ad1e173e24d49e) in your .addItem statement. Ultimately the sys_id needs to come from sc_cat_item table (or another table extending from it like Record Producer).
Also, I am not sure if your call is correct. For example, I see you used 'item' in quotes, and I know I never have. This does not mean you are doing it wrong, I might have been doing it wrong all these years. But here is an example of a call we use in a scheduled job:
gs.include('Cart');
var hddcart = new Cart();
//add your requested item to the cart by sys_id of the catalog item
var item = hddcart.addItem('fb16c1dfacbe2400f9dbe56e438907ad', 1);
//fill in the variables on the request item form
hddcart.setVariable(item,"assigned_to", "4bbdb4c64f6e31801b7a1b8ca310c7c3");
hddcart.setVariable(item,"assignment_group", "fefdf85facbe2400f1dbe56e43890705");
hddcart.setVariable(item,"requested_for", "4bbdb4c64f6e31801b7a1b8ca310c7c3");
hddcart.setVariable(item,"short_description", "Nessus - Upload Nessus Scans from previous Month");
hddcart.setVariable(item,"description", "1: Check Nessus scans completed for previous month \n2: Download CSV files from Nessus \n3: Create task for Trevor to upload CSV files to Service-Now");
hddcart.placeOrder();
This should hopefully be enough to get you going and then we can modify to your exact use case. Any questions let me know!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2022 10:24 AM
I think the problem is in your cart.addItem statement. The .addItem is the sys_id of the Catalog Item that you are looking to add, and from your screenshot I am not sure if that's the sys_id you are adding.
For example, this is an item that ServiceNow provides out of the box. You would use the sys_id of this item (d0b15e33d7033100a9ad1e173e24d49e) in your .addItem statement. Ultimately the sys_id needs to come from sc_cat_item table (or another table extending from it like Record Producer).
Also, I am not sure if your call is correct. For example, I see you used 'item' in quotes, and I know I never have. This does not mean you are doing it wrong, I might have been doing it wrong all these years. But here is an example of a call we use in a scheduled job:
gs.include('Cart');
var hddcart = new Cart();
//add your requested item to the cart by sys_id of the catalog item
var item = hddcart.addItem('fb16c1dfacbe2400f9dbe56e438907ad', 1);
//fill in the variables on the request item form
hddcart.setVariable(item,"assigned_to", "4bbdb4c64f6e31801b7a1b8ca310c7c3");
hddcart.setVariable(item,"assignment_group", "fefdf85facbe2400f1dbe56e43890705");
hddcart.setVariable(item,"requested_for", "4bbdb4c64f6e31801b7a1b8ca310c7c3");
hddcart.setVariable(item,"short_description", "Nessus - Upload Nessus Scans from previous Month");
hddcart.setVariable(item,"description", "1: Check Nessus scans completed for previous month \n2: Download CSV files from Nessus \n3: Create task for Trevor to upload CSV files to Service-Now");
hddcart.placeOrder();
This should hopefully be enough to get you going and then we can modify to your exact use case. Any questions let me know!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2022 11:41 PM
Thank you so much for your response. I made the changes that you suggested and the code is working for me.