Odd behavior in Mail Script

Amy V2
Mega Sage

We are using a mail script to populate the rest of a sentence based on the subcategory of a request in the Conflict of Interest scoped application in Legal Service Delivery. The catalog item submission creates a Legal Request. The Practice Area, Category, and Subcategory fields for the Legal Request are populated via the Record Producer script.

 

After submitting, a "we got it" email is sent to the Requested For (same as Opened By in this case). The mail script checks current.lg_subcategory's sys_id to know what to print for the rest of the sentence. For all but one of the subcategories, the mail script works as expected. For one subcategory only, the condition doesn't evaluate to true. I have wracked my brain for why this is happening.

 

I added a gs.info at the top of the mail script that lets me know that the mail script was called and what the subcategory is and I've confirmed the sys_id is being fed into the mail script and matches the condition. I added another gs.info if/else check immediately after, checking that specific sys_id. It does not run. The sys_id matches exactly so I have no idea why it's not performing the steps that follow.

 

Has anyone seen this? Any ideas how to fix? Below is an extremely simplified script that I used to just check the If condition and it still didn't work... not even the Else?

 

 

 

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {

    // Update email message body based on type of conflict
gs.info('AV - In coi_type_of_conflict mail script and subcategory sysID is ' + current.lg_subcategory);

if(current.lg_subcategory == '2161f2481bc9bd10c7f16316624bcbd2'){   //ADDED THIS TO CHECK THE EVALUATION AND THE SYS_ID MATCHES EXACLTY, BUT THESE INFO STATEMENTS ARE NOT LOGGED AT ALL, NOT EVEN THE ELSE ONE?
	gs.info('AV - For Subcategory 4, sys_id is ' + current.lg_subcategory);
} else {
	gs.info('AV - Failed Subcategory 4 check somehow');
}

if(current.lg_subcategory == 'ceb3f24c1bc9bd10c7f16316624bcb19'){
	gs.info('AV - For Subcategory 3, sys_id is ' + current.lg_subcategory);
} else {
	gs.info('AV - Failed Subcategory 3 check somehow');
}

})(current, template, email, email_action, event);

 

 

 

 

EDITED TO ADD: I added another check for a different subcategory. When I submit a request that falls under Subcategory 3, the Subcategory 4 "else" statement DOES add a log message. See messages logged at 3:46:05 from that submission. Then when I submit another request for the Subcategory 4, ONLY the initial log message in the mail script occurs, not either of the if/else statements in the code above. ODD!

AmyV2_0-1714769269962.png

 

1 ACCEPTED SOLUTION

Jim Coyne
Kilo Patron

As @Sandeep Rajput mentions, you should use either current.getValue("lg_subcategory")  (I prefer this one) or current.lg_subcategory.toString() to get an actual string value to do your compares against.

 

However, the screenshot you supplied does not actually show a problem.  The bottom 3 logs are from the same running of the Mail script at 03:46:05 and, of course, only 1 of your Subcategories will match (#3 in this case).

 

The top log entry just shows the Mail script is running with the sys_id for #4 but not the results.

View solution in original post

9 REPLIES 9

Ravindra Yadav
Tera Contributor

Hi @Amy V2  
Is the subcategory Reference type field?

Hi Ravindra,

 

Yes, it is a Reference field. I imagine you'll give the same advice to use getValue or to convert to string. Both things I have tried with no success, but just in case my syntax was wrong, I will try again. Also, I think it's interesting to note that all the "if" statements are pointing to a reference field and all of them correctly evaluate to true except this ONE value. That's what is odd to me. Wouldn't they all not work if what was needed was a string value?

 

Amy

Sandeep Rajput
Tera Patron
Tera Patron

@Amy V2 Could you please try converting the subcategory to string as follows.

if(current.lg_subcategory.toString() == '2161f2481bc9bd10c7f16316624bcbd2'){ 

and see if it works.

Thanks Sandeep. I will try this again. As I stated in the reply to Ravindra, what is odd to me is that all of the "if" statements are pointing to this reference field and all of them correctly evaluate to true except this ONE value. I imagine I should convert them all to string just to be safe, but why do they all work except this one record's sys_id?

 

Amy