Not show hidden variables in mail script notification

acf
Tera Contributor

I have this mail script to show variables in a approval notification, but this shows a checked hidden variables that i dont need it, how can I hide this variables in the notification?

Thanks!

	template.print("<br/>");
			var set = new GlideappVariablePoolQuestionSet();
			set.setRequestID(current.sysapproval.toString());
			set.load();
			var vs = set.getFlatQuestions();
			for (var i = 0; i < vs.size(); i++) {
					if (vs.get(i).getLabel() != '' && vs.get(i).getDisplayValue()!='' && vs.get(i).getDisplayValue()!='false') {
					template.space(2);
					template.print(' <b>' + vs.get(i).getLabel() + "</b>: " + vs.get(i).getDisplayValue() + "<br/>");
				}
			}
1 ACCEPTED SOLUTION

Then you would need to glide into Item Option table and filter out hidden fields. Please use below script,

template.print("<br/>");
			var set = new GlideappVariablePoolQuestionSet();
			set.setRequestID(current.sysapproval.toString());
			set.load();
			var vs = set.getFlatQuestions();
			for (var i = 0; i < vs.size(); i++) {
                              var grOption=new GlideRecord("item_option_new");
                                 if(grOption.get(vs.get(i).getId())){
					if (grOption.hidden==false && vs.get(i).getLabel() != '' && vs.get(i).getDisplayValue()!='' && vs.get(i).getDisplayValue()!='false') {
					template.space(2);
					template.print(' <b>' + vs.get(i).getLabel() + "</b>: " + vs.get(i).getDisplayValue() + "<br/>");
				}
			}

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

View solution in original post

5 REPLIES 5

_ChrisHelming
Tera Guru

A variable being hidden is not something stored in the GlideappVariablePoolQuestionSet. It's in a client script that gets evaluated client-side when the page loads.

 

Your best option is probably to create a system property called something like "notification.variables.hide" and modify your script to hide any variables whose name appears in that system property.

 

// at the top of your script, get the vars and make it an array
var hiddenVars = gs.getProperty('notification.variables.hide').split(',');


// in your for loop, update your if statement to check if it's in the array
if (hiddenVars.indexOf(vs.get(i).getLabel()) == -1 && vs.get(i).getLabel()...

Abhijit4
Mega Sage

Hi,

There is one OOTB function isVisibleSummay  which will resolve your issue. Please try below,

template.print("<br/>");
			var set = new GlideappVariablePoolQuestionSet();
			set.setRequestID(current.sysapproval.toString());
			set.load();
			var vs = set.getFlatQuestions();
			for (var i = 0; i < vs.size(); i++) {
					if (vs.get(i).isVisibleSummary() && vs.get(i).getLabel() != '' && vs.get(i).getDisplayValue()!='' && vs.get(i).getDisplayValue()!='false') {
					template.space(2);
					template.print(' <b>' + vs.get(i).getLabel() + "</b>: " + vs.get(i).getDisplayValue() + "<br/>");
				}
			}

 

You can refer this link for more details.

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit

 

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

acf
Tera Contributor

Hi Abhijit,

 

I tried this "isVisibleSummary" before and it doesnt work for me, only if I unchecked the "Visible on Summaries" in the variable

Then you would need to glide into Item Option table and filter out hidden fields. Please use below script,

template.print("<br/>");
			var set = new GlideappVariablePoolQuestionSet();
			set.setRequestID(current.sysapproval.toString());
			set.load();
			var vs = set.getFlatQuestions();
			for (var i = 0; i < vs.size(); i++) {
                              var grOption=new GlideRecord("item_option_new");
                                 if(grOption.get(vs.get(i).getId())){
					if (grOption.hidden==false && vs.get(i).getLabel() != '' && vs.get(i).getDisplayValue()!='' && vs.get(i).getDisplayValue()!='false') {
					template.space(2);
					template.print(' <b>' + vs.get(i).getLabel() + "</b>: " + vs.get(i).getDisplayValue() + "<br/>");
				}
			}

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP