- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-04-2022 02:10 PM
I finally got help with retrieving variables form the email body text. eg. Cost_Center:2258
I've set my logs to verify the value e.g.2258
My Inbound action will set the catalog item I'm using with the value.
YEAH!!!
Now, the issue is I can't find the related assignment group based on the value.
I've tried this in the workflow and also in the inbound action. Here is what i'm doing in my inbound action.
I tried this in the workflow as well with the same results (only changed the set values accordingly)
var splitext=email.body_text;
var splittoget=splitext.split('Cost_Center:')[1];
var splittogetfinal=splittoget.split(' ')[0]; //This will give final result
var fmcCC = splittogetfinal.toString();
var fmcG = '';
gs.log('DEBUG - the final answer is '+splittogetfinal);
gs.log('DEBUG - the fmc is '+fmcCC);
var assgn = new GlideRecord('u_fmc_list');
assgn.addEncodedQuery('u_active=true^u_fmc_codeLIKE'+fmcCC);
assgn.query();
if(assgn.next()){
fmcG = assgn.u_user_name;//reference field to groups table
}else{
fmcG = 'e7571637db412b807317323b7c9619a6';
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-08-2022 10:58 AM
Finally got this to work, after consulting with a local buddy of mine on the phone.
Apparently the there is an issue with getting the recommend script to work in Text fields or HTML fields
Ended up using a combination of indexOf and State/End positions to split out the desired data.
This was then usable in the gliderecord quest to pull Support Group assign ticket correctly.
function runAction( /*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
var fmcCC = '';;
var fmcG = '';
//************************
var fmcCCstart = '';
var fmcCCend = '';
var fmcCCtxt = '';
fmcCCstart = email.body_text.indexOf("Cost_Center:");
if (email.body_text.indexOf("Cost_Center:") > -1) {
fmcCCstart = fmcCCstart + 12;
fmcCCend = fmcCCstart + 4;
fmcCCtxt = email.body_text.slice(fmcCCstart,fmcCCend);
// gs.log('Eric - fmcCCtxt with slice is: ' + fmcCCtxt);
}
fmcCC = fmcCCtxt;
var assgn = new GlideRecord('u_pl_fmc_approval_list');
assgn.addEncodedQuery("u_active=true^u_cost_centerLIKE"+fmcCC);
assgn.query();
if(assgn.next()){
fmcG = assgn.getValue('u_support_group');
}else{
fmcG = 'e7571637db412b807317323b7c9619a6';
}
var sender = email.origemail;
var other = email.origemail;
var ritmSysID = '';
var me = new GlideRecord('sys_user');
me.addQuery('email', sender);
me.query();
while (me.next()) {
other = me.sys_id;
}
var emailBody = "received from: " + email.origemail + "\n\n" + email.body_text;
// Implement email action here
createRequest();
function createRequest() {
var cart = new Cart(); //calling the cart API
var item = cart.addItem('464562161b8ec1107bf5fd951a4bcbf6'); //sys_id of the General Request catalog item I want to fire
cart.setVariable(item, 'caller', other);
cart.setVariable(item, 'Comments', email.body_text); //sets catalog variable to email's body
cart.setVariable(item,'cost_center',fmcCC);
cart.setVariable(item,'assignment_group',fmcG);
var rc = cart.placeOrder(); //this launches the catalog item, and creates a request object. rc = the request object
updateRITM(rc.sys_id); //call a function immediately to update the ritm. This must be a nested function, otherwise inbound actions get weird.
//also, we're passing the sys_id of the request so we know what RITM to grab.
}
function updateRITM(req) {
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request', req); //req is what we passed from the previous function. the sys_id of the request.
ritm.query();
while (ritm.next()) {
ritm.description = email.body_text;
ritm.u_original_email = sys_email.sys_id;
ritm.short_description = email.subject;
ritmSysID = ritm.sys_id;
var assgn2 = new GlideRecord('u_pl_fmc_approval_list');
assgn2.addEncodedQuery("u_active=true^u_cost_centerLIKE"+fmcCC);
assgn2.query();
if(assgn2.next()){
ritm.assignment_group = assgn.getValue('u_support_group');
'+assgn.getValue('u_support_group'));
}else{
ritm.assignment_group = 'e7571637db412b807317323b7c9619a6';
}
ritm.update();
}
//This added attachments to the RITM and updates the sys_email instance field with the RITM #
var emailRec = new GlideRecord("sys_email");
emailRec.addQuery("uid", email.uid);
emailRec.orderByDesc("sys_created_on");
emailRec.query();
if (emailRec.next()) {
GlideSysAttachment.copy("sys_email", emailRec.sys_id, "sc_req_item", ritmSysID);
emailRec.instance = ritmSysID;
emailRec.target_table = "sc_req_item";
emailRec.update();
}
}
event.state = "stop_processing"; //stop evaluating inbound actions. This is why I keep this record's order lower than my incident from email rules.
})(current, event, email, logger, classifier);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-08-2022 11:11 AM
Hi,
I hope at least one of my replies above helped somewhat?
Not really sure what you mean by the script wasn't working well with text fields or HTML when you were grabbing the email.body_text, which coverts everythings to string and then you were using split and others to get what you wanted from it. Your original question was about the small bit of script you initially provided.
As I had mentioned above, using log statements, like gs.info() would help you see what you're getting from that split and could help ensure things.
It seems that your previous approach with that may not have been resulting in the actual outcome you needed and had other characters, etc. in it.
In any case, glad you got it resolved.
If any of my replies above did end up helping and/or guiding you correctly, please mark that reply appropriately.
Thanks and take care! š
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-08-2022 11:37 AM
Yes - very. It was what got me down the road with my pal.
Thanks again.
That's what I thought as well, however, the queries would not return the value wanted and always default to the "Else" clause.
We both experienced the same thing in our PDI's and discovered the cause in debugging.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-17-2025 07:24 AM
Hi Eric,
In my Catalog Item, there are about 15 variables. Is there a way we can parse these values from the email?