Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Business rule advance Condition for script

dennisandrison
Kilo Expert

HI Developers.

 

I have the following script on a business rule:  

(function executeRule(current, previous /*null when async*/) {

//Get the Email record created against this Log
var grEmail = new GlideRecord("sys_email");
if(grEmail.get("sys_id", current.email)) {
//Check for a style associated with the Notification used
var grES = new GlideRecord("u_email_style");
var htmlStyle = "";
var strCSS = "";
var grSEA = new GlideRecord("sysevent_email_action");{
if(grSEA.get("sys_id", current.notification))

// if (grSEA.u_style == '') {
// //no style specifed, exit logic
// return;
// }
if(grES.get("sys_id", grSEA.u_style)) {
htmlStyle = grES.u_style_template;
strCSS = grES.u_css;
}
}
var strBody = grEmail.body;
//gs.log("DEBUG 1: Apply Email Style, strBody = " + strBody);
//gs.log("DEBUG 2: Apply Email Style, htmlStyle = " + htmlStyle);
strBody = strBody.replace("<html>", "");
strBody = strBody.replace("</html>", "");
strBody = strBody.replace("<body>", "");
strBody = strBody.replace("</body>", "");
htmlStyle = htmlStyle.replace("body_text", strBody);
//gs.log("DEBUG 3: Apply Email Style, htmlStyle = " + htmlStyle);

var strEmail = strCSS + "<html><head></head><body>" + htmlStyle + "</body></html>";
grEmail.body = strEmail;
grEmail.headers = grEmail.headers + "\n" + strCSS;
grEmail.autoSysFields(false);
grEmail.setWorkflow(false);
grEmail.update();
}
})(current, previous);

 

I only want this script to run when the sysevent_email_action.u_type is populated.   I have the following condition on the script current.sysevent_email_action.u_style!=""  but this is not working.  What is wrong with the condition? 

1 ACCEPTED SOLUTION

rzj
Giga Contributor

Your code is checking for sysevent_email_action.u_style but you said "I only want this script to run when the sysevent_email_action.u_type is populated." Is there a relation between u_type and u_style? What am I missing here?

View solution in original post

9 REPLIES 9

andrew_venables
ServiceNow Employee
ServiceNow Employee

What table is your business rule running against?

dennisandrison
Kilo Expert

sys_email_log is the table the business rule is running on

rzj
Giga Contributor

Your code is checking for sysevent_email_action.u_style but you said "I only want this script to run when the sysevent_email_action.u_type is populated." Is there a relation between u_type and u_style? What am I missing here?

dennisandrison
Kilo Expert

rzj  what is u_type and u_style in your comment?