How to use an If statement in email scripts to evaluate Incident State

Adam Robbins1
Mega Guru

Hi,

I am also struggling with an if statement in the email scripts.   I read this post, but wasn't able to resolve my issue: Struggle with 'if' statement in email script

I am trying to get to get certain text to show only if State = Resolved.   I have tried many different combinations of if (state == 'Resolved') even putting the values into variables and then comparing the variables.   I know the if statement is at lease making an evaluation, because it does print the horizontal line in the else section.   I've even used template.print to show the 2 variables and both do say Resolved, but for some reason the if doesn't think that they are equal.

If you have found something that works, please let me know.

Thank you,

Adam Robbins

1 ACCEPTED SOLUTION

Please try current.state.getDisplayValue() ?


View solution in original post

6 REPLIES 6

snowtech1
Tera Expert

On the state field is the value of resolved state 'resolved'?


Think out of the box they assign numbers to the state and only the label has text


SanjivMeher
Kilo Patron
Kilo Patron

Can you post your email script. It should be current.state=='Resolved' I think



Please mark this response as correct or helpful if it assisted you with your question.

Adam Robbins1
Mega Guru

Here is what I currently have:



(function runMailScript(current, template, email, email_action, event) {


var strState = '${state}';


var strResolved = 'Resolved';


template.print('<hr><p><font size="4" color="#999999" face="helvetica"><strong>');


template.print(gs.getMessage('State') + ': ' + '</strong>${state}<strong><br><br>');


template.print('1' + strState + '111' + strResolved + '1<br>' );


template.print(gs.getMessage('Comments') + ':');


template.print('</strong></font></p>');


template.print('<p><font size="3" color="#808080" face="helvetica">' + current.comments_and_work_notes.getJournalEntry(1) + '</font>');




if (strState === strResolved){


template.print('</p><p><font size="4" color="#999999" face="helvetica"><strong>');


template.print(gs.getMessage('Close Code & Notes') + ': ' + '</strong>${close_code}<strong>');


template.print('</strong></font></p>');


template.print('<p><font size="3" color="#808080" face="helvetica">' + gs.getMessage('${close_notes}') + '</font><hr></p>');


}


else {


template.print('<hr></p>');


}


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



Here is the result:



find_real_file.png


Please try current.state.getDisplayValue() ?