Need to show true checkbox on notification

Nivedita9
Tera Contributor

Hi All,
I have few checkbox on catalog task form. Where assign to person has to check those boxes if user has returned those items.
The checkbox which are true needs to be shown on notification. Attaching the screenshot for reference:find_real_file.png

So in the notification it should come as:
Hardware Returns:
Mobile Phone,

Bag/Pack
Can anyone help??

1 ACCEPTED SOLUTION

since your notification is on sc_task

use this

var reqitem = new GlideRecord('sc_req_item');
reqitem.addQuery("sys_id", current.request_item);
reqitem.query();
if(reqitem.next()) {
	template.print("Hello3");

	// add here logic to check variable value is true then only print
	
}

I already shared link for solution above

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

9 REPLIES 9

Hi,

in email script you cannot determine which variable was visible and which was hidden as that part works on client side

what you can do is check variable is of type checkbox and if true then print it

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Ankur Bawiskar 
var reqitem = new GlideRecord('sc_req_item');
reqitem.addQuery("sys_id", current.sys_id);
template.print("Hello");
reqitem.query();
template.print("Hello2");
while(reqitem.next()) {
template.print("Hello3");

Note - I don't know I'm trying to see the issue the step by step. This hello 3 is not printing. Do you know the reason?

since your notification is on sc_task

use this

var reqitem = new GlideRecord('sc_req_item');
reqitem.addQuery("sys_id", current.request_item);
reqitem.query();
if(reqitem.next()) {
	template.print("Hello3");

	// add here logic to check variable value is true then only print
	
}

I already shared link for solution above

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Martin Ivanov
Giga Sage
Giga Sage

You can create a mail script where you will retrieve the variables from the cat_item (current).

 

if the checkbox is trued, then template print that variable.


Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024

shloke04
Kilo Patron

Hi @Nivedita 

Please follow the steps below to achieve your requirement:

1) Navigate to Notification Script module and use the script shared below:

var table = current.getTableName();
var count = 0;
if (table == 'sysapproval_approver') {
	count = 1;
} else {
	for(vars in current.variable_pool){
		count++;
		break;
	}
}

if(count > 0){
	var mvalue = '';
	var list = [];
	var display = [];
	template.print('<table border="1">');
	
	//Query for the non-empty variables for this record
	//Catalog item and task variables pull from 'sc_item_option_mtom' table
	if(table == 'sc_req_item' || table == 'sc_task' || table == 'sysapproval_approver') {
		var itemVars = new GlideRecord('sc_item_option_mtom');
		
		if(table == 'sc_req_item'){
			itemVars.addQuery('request_item', current.sys_id);
			
		}
		if(table == 'sc_task'){
			itemVars.addQuery('request_item', current.request_item.sys_id);
			
		}
		if(table == 'sysapproval_approver'){
			itemVars.addQuery('request_item', current.sysapproval.sys_id);
		}
		itemVars.addNotNullQuery('sc_item_option.value');
		
		//Exclude Label and Container variables
		itemVars.addQuery('sc_item_option.item_option_new.type', '!=', 11);
		itemVars.addQuery('sc_item_option.item_option_new.type', '!=', 19);
		itemVars.addQuery('sc_item_option.item_option_new.type', '!=', 20);
		itemVars.addQuery('sc_item_option.item_option_new.type', '!=', 24);
		itemVars.orderBy('sc_item_option.order');
		
		itemVars.query();
		while(itemVars.next()){
			template.print("<tr>");
			template.print("<td>"+itemVars.sc_item_option.item_option_new.question_text+"</td>");
			mvalue = itemVars.sc_item_option.value;
			
			// Check if the value is from the reference field
			if (itemVars.sc_item_option.item_option_new.type == '8') {
				var grRefTable = new GlideRecord(itemVars.sc_item_option.item_option_new.reference);
				grRefTable.addQuery('sys_id',mvalue);
				grRefTable.query();
				if (grRefTable.next()) {
					mvalue = grRefTable.getDisplayValue();
				}
				template.print("<td>"+mvalue+"</td>");
				template.print("</tr>");
			}
			
			// Check if the type is List Collector
			if(itemVars.sc_item_option.item_option_new.type == '21') {
				list = itemVars.sc_item_option.value.split(',');				
				for(var i=0; i<list.length; i++){
					var grListTable = new GlideRecord(itemVars.sc_item_option.item_option_new.list_table);
					grListTable.addQuery('sys_id',list[i]);
					grListTable.query();
					if (grListTable.next()) {
						display.push(grListTable.getDisplayValue());						
					}
				}
				template.print("<td>"+display+"</td>");
				template.print("</tr>");
			}
			
			// Check if the type is Select Box
			if(itemVars.sc_item_option.item_option_new.type == '5') {
				var grQuestion = new GlideRecord('question_choice');
				grQuestion.addQuery('question', itemVars.sc_item_option.item_option_new);
				grQuestion.addQuery('value', itemVars.sc_item_option.value.toString());
				grQuestion.query();
				if(grQuestion.next()){
					mvalue = grQuestion.getValue('text');
				}
				template.print("<td>"+mvalue+"</td>");
				template.print("</tr>");
			}
			
			//For rest of the types
			if(itemVars.sc_item_option.item_option_new.type != '21' && itemVars.sc_item_option.item_option_new.type != '8' && itemVars.sc_item_option.item_option_new.type != '5' )
				{
				template.print("<td>"+mvalue+"</td>");
				template.print("</tr>");
			}
		}
	}
	template.print("</table>");
}

Screenshot below for reference as well:

find_real_file.png

Now once this Notification script is configured you just need to call it in your Notification which I believe you have written it on your Catalog Task Table:

Syntax for calling Notification Script in Notification is as below:

${mail_script:Mail Script Name}

This will be in the body of the notification in 3rd tab i.e. What will it Contain of Notification form

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke