Create Requested Item with all variables from Inbound Action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2023 09:02 AM
Hi All,
I have a requirement to create Requested Item with all the variables from Inbound Action.
Catalog form name: Generic Request
Variables- Requested for -(referring to sys_user)
Email- Autopopulate based on Requested for
Account - lookup select box(refer to customer_account)
Client - lookup select box(refer to customer_account, name= Id. I have added reference qualifier. based on account Id will show)
Short description- Single text line
Description- HTML text
I have created Inbound action on sc_request table( I take help from this community link https://www.servicenow.com/community/developer-forum/create-requested-item-from-inbound-action-with-... )
(function runAction( /*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
var user = new GlideRecord('customer_contact');
user.addQuery('email', email.from.toLowerCase());
user.query(); //search contact table for user
if (user.next()) {
var requested_for = user.sys_id;
if (user.account) {
var account = user.account.getDisplayValue();
var account_id = new GlideRecord('customer_account');
account_id.addEncodedQuery('name=' + account);
account_id.query();
if (account_id.next()) {
var client = account_id.u_client.getDisplayValue();
}
} else {
//do nothing
}
}
var cartID = GlideGuid.generate(null);
var cart = new Cart(cartID);
var item = cart.addItem('562790589388b11034dbbb2c5cbu1908');
cart.setVariable(item, 'account_hidden', account);
cart.setVariable(item, 'client', client);
cart.setVariable(item, 'short_description', email.subject);
cart.setVariable(item, 'description', email.body_html);
var rc = cart.placeOrder();
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request', rc.getValue('sys_id'));
ritm.query();
if (ritm.next()) {
ritm.short_description = email.subject;
ritm.description = email.body_html;
ritm.comments = email.body_text;
ritm.requested_for = gs.getUserID();
ritm.contact_type = "email";
ritm.update();
}
})(current, event, email, logger, classifier);
I am only receiving the mail. Request , requested item nothing is generating.
Please help in this.
Thanks,
Samiksha
- Labels:
-
Request Management
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2023 09:40 AM
@Samiksha2 in the above part your variables are scoped and you need to make it global by declaring them outside if statements
try this
var account='';
var requested_for='';
var client='';
var user = new GlideRecord('customer_contact');
user.addQuery('email', email.from.toLowerCase());
user.query(); //search contact table for user
if (user.next()) {
requested_for = user.sys_id;
if (user.account) {
account = user.account.getDisplayValue();
var account_id = new GlideRecord('customer_account');
account_id.addEncodedQuery('name=' + account);
account_id.query();
if (account_id.next()) {
client = account_id.u_client.getDisplayValue();
}
} else {
//do nothing
}
}
And then try Cart API ...if not try with cart JS but make sure the upper part of the code is replaced with above code where variables are made global
Hope this helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2023 10:10 AM
not working @Mohith Devatte .
I removed account,client, requested for and email from the form and just leave short description and description.
and tried with both Cart API and cart JS. Still nothing is creating. What I am doing wrong? I have selected table as sc_request.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2023 10:21 AM
I uncheck the Hide Add to cart check box also. Still nothing is generating.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2023 10:28 AM
@Samiksha2 try enable the cart option and run the script with both cart and cart JS
also put few logs in the script like try to print account , client and requested for and see if the values are getting generated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2023 10:32 AM
Hi @Mohith Devatte ,
I have removed all variables except short description and description. And change Submit to Order.
Tried with both ways still request is not generating.😑