Request several items via Inbound Email Action using CartJS API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2024 04:12 AM - edited 02-27-2024 04:13 AM
Hi developers,
here is my example of how to request several catalog items from Inbound Email Action using CartJS API.
In my case, I receive an email determining following action e.g. deletion of a user. I need to check him for each system if he has an account of that system or not. If he does, Catalog Item for each system and deletion action will be requested.
My code might does not look the best but it is working well. Please, let me know your solutions for such case I am using it for. If you have any better solution/improved piece of code, please, let me know. Otherwise I hope this helps someone who is struggling with CartJS API.
createRequest();
function createRequest() {
var coupa = false;
var unix = false;
var vpn = false;
var b4recovery = false;
//Get User WindowsID
var sub = email.subject.toString(); //Get String from Subject
var mailuser = sub.substring(sub.indexOf('(') + 1, sub.lastIndexOf(')')); //Windows ID between (....)
var rname = sub.substring(sub.indexOf("'") + 1, sub.lastIndexOf("'")); //Windows ID between '.....'
var gr = new GlideRecord('sys_user');
gr.addNotNullQuery('u_idmobjectidentifier'); //Only Users with IDM Object Identifier value
gr.addQuery('u_uid', mailuser).addOrCondition('u_uid', rname);
gr.query();
if (gr.next()) {
if (gr.u_is_unix_user == true)
unix = true;
if (gr.u_is_coupa_user == true)
coupa = true;
if (gr.u_is_vpn_user == true)
vpn = true;
if (gr.u_is_b4_recovery_user == true)
b4recovery = true;
}
var cart = new sn_sc.CartJS();
//Rename
if (email.subject.startsWith("User Rename from")) {
if (unix == true) {
var itemDetails = [
{
'sysparm_id': 'CATALOG ITEM SYS ID',
'sysparm_quantity': '1',
'variables': {
'action': 'rename',
'subject': email.subject,
'description': email.body_text
}
} //CAX DXM
];
for (var i = 0; i < itemDetails.length; i++) {
var cart = new sn_sc.CartJS();
cart.addToCart(itemDetails[i]);
}
cart.checkoutCart();
}
var itemDetails1 = [{
'sysparm_id': 'CATALOG ITEM SYS ID',
'sysparm_quantity': '1',
'variables': {
'action': 'rename',
'subject': email.subject,
'description': email.body_text
}
}, //Webcycle
{
'sysparm_id': 'CATALOG ITEM SYS ID',
'sysparm_quantity': '1',
'variables': {
'action': 'rename',
'subject': email.subject,
'description': email.body_text
}
}, //BDE MES
];
for (var i = 0; i < itemDetails1.length; i++) {
var cart = new sn_sc.CartJS();
cart.addToCart(itemDetails1[i]);
}
cart.checkoutCart();
cart.submitOrder(itemDetails1[0]);
}
//Deactivation
if (email.subject.startsWith("Complete deactivation for")) {
var itemDetails = [{
'sysparm_id': 'CATALOG ITEM SYS ID',
'sysparm_quantity': '1',
'variables': {
'action': 'deactivation',
'subject': email.subject,
'description': email.body_text
}
}, //Webcycle
{
'sysparm_id': 'CATALOG ITEM SYS ID',
'sysparm_quantity': '1',
'variables': {
'action': 'deactivation',
'subject': email.subject,
'description': email.body_text
}
}, //BDE MES
{
'sysparm_id': 'CATALOG ITEM SYS ID',
'sysparm_quantity': '1',
'variables': {
'action': 'deactivation',
'subject': email.subject,
'description': email.body_text
}
} //UC
];
for (var i = 0; i < itemDetails.length; i++) {
var cart = new sn_sc.CartJS();
cart.addToCart(itemDetails[i]);
}
cart.checkoutCart();
cart.submitOrder(itemDetails[0]);
}
//Deletion
if (email.subject.startsWith("Final Account Deletion for")) {
if (unix == true) {
var itemDetails = [
{
'sysparm_id': 'CATALOG ITEM SYS ID',
'sysparm_quantity': '1',
'variables': {
'action': 'deletion',
'subject': email.subject,
'description': email.body_text
}
} //CAX DXM
];
for (var i = 0; i < itemDetails.length; i++) {
var cart = new sn_sc.CartJS();
cart.addToCart(itemDetails[i]);
}
cart.checkoutCart();
}
if (coupa == true) {
var itemDetails = [
{
'sysparm_id': 'CATALOG ITEM SYS ID',
'sysparm_quantity': '1',
} // Coupa
];
for (var i = 0; i < itemDetails.length; i++) {
var cart = new sn_sc.CartJS();
cart.addToCart(itemDetails[i]);
}
cart.checkoutCart();
}
if (vpn == true) {
var itemDetails = [
{
'sysparm_id': 'CATALOG ITEM SYS ID',
'sysparm_quantity': '1',
} // VPN
];
for (var i = 0; i < itemDetails.length; i++) {
var cart = new sn_sc.CartJS();
cart.addToCart(itemDetails[i]);
}
cart.checkoutCart();
}
var itemDetails1 = [{
'sysparm_id': 'CATALOG ITEM SYS ID',
'sysparm_quantity': '1',
'variables': {
'action': 'deletion',
'subject': email.subject,
'description': email.body_text
}
}, //Webcycle
];
for (var i = 0; i < itemDetails1.length; i++) {
var cart = new sn_sc.CartJS();
cart.addToCart(itemDetails1[i]);
}
cart.checkoutCart();
cart.submitOrder(itemDetails1[0]);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2024 09:21 AM
Hi @zaneta_cisarova ,
Great job! Could you DRY it a bit? 🙂
As I was making a couple of videos recently about exactly the same topic, I see the clear benefit of CartJS.
I was asked however, if we can make it low-code/no-code with Flow Designer for those who are not familiar with coding. Your use case has some complexity for you to try it out 🙂
Anyway I encourage you to continue and share you approached with the community!
Regards, Ivan