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

When I went back into my mail script, I realized that I did already try this. I created a variable at the start of the script: var subcat = current.lg_subcategory.toString(); then used subcat in all the if statements. Still no luck.

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.

Thanks, Jim. I believe I have done all of that previously in an attempt to solve this issue. I will try again. Perhaps third time's the charm.

 

To clarify, the top log entry was after submitting a request using the "faulty" sys_id value in the legal category table.  I did pretty sloppy log checks and said "If this 1st value, log this. Else log that" for one of the sys_ids that has been correctly running the script, followed by another "If this 2nd value, log this. Else log that" statement for the fault sys_id. So every submission should log 3 statements: The first one which shows it's in the mail script, and either 2 log thats (it failed both ifs) or one if and one that (if passed one if but failed the other). However, this one sys_id just seems to skip over the whole conditional statements altogether. I would've expected 3 log statements for the second test as well but only got the one.

 

Amy

 

Edited for clarity

I tried current.getValue("lg_subcategory") and still the same result. Only this one subcategory gives issues. All others work as expected.

Ultimately I marked this as the solution as I ended up changing the code to use the getValue syntax. However, I also rearranged the code... I moved this particular " else if " section further up the code and then also rearranged the lines within this section to grab the variable values in a different order. I'm not sure why this worked, but it did.

 

Thanks for everyone's help.