Hide empty fields in notification

RudhraKAM
Tera Guru

I know it can be done with Mail script not sure how 

Below is the content in the Notification  Message which is on KB_feedback  , if the useful is not selected we need to hide it or if comments is empty then it need to hide in the notification ,, can some one help me with the mail script .


Knowledge Article: ${article} has received feedback from User: ${user}.

Article Short description: ${article.short_description}

Rating: ${rating}

Useful: ${useful}

Comments: ${comments}

Click on link to view Knowledge Feedback ${URI}

1 ACCEPTED SOLUTION

Brian Lancaster
Tera Sage

I think you could keep most of the notification the same just replace the two lines for useful and comments with ${mail_script:Your mail script name here}.  Then the code of your mail script should be below.

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

          // Add your code here
	if (current.useful != ''){
		template.print("Useful: " + current.useful);
		template.print("<br />");
	}
	if (current.comments != ''){
		template.print("Comments: " + current.comments);
		template.print("<br />");
	}

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

Over all your notification would then look like this.

Knowledge Article: ${article} has received feedback from User: ${user}.

Article Short description: ${article.short_description}

Rating: ${rating}

${mail_script:Your mail script name here}

Click on link to view Knowledge Feedback ${URI}

View solution in original post

1 REPLY 1

Brian Lancaster
Tera Sage

I think you could keep most of the notification the same just replace the two lines for useful and comments with ${mail_script:Your mail script name here}.  Then the code of your mail script should be below.

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

          // Add your code here
	if (current.useful != ''){
		template.print("Useful: " + current.useful);
		template.print("<br />");
	}
	if (current.comments != ''){
		template.print("Comments: " + current.comments);
		template.print("<br />");
	}

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

Over all your notification would then look like this.

Knowledge Article: ${article} has received feedback from User: ${user}.

Article Short description: ${article.short_description}

Rating: ${rating}

${mail_script:Your mail script name here}

Click on link to view Knowledge Feedback ${URI}