How to create a notification in a worklfow with the variables from the catalog item?

velvet
Mega Guru

I have created a workflow that has a notification being sent.  But it seems to not be in the right format because it is not copying the variables over.  Here are some of the variables.  Can someone help with the script part?

find_real_file.png

Here some of the variables, if someone help me get started i can finish it.

find_real_file.png

1 ACCEPTED SOLUTION

This is a preview of a notification in the notifications section of ServiceNow.  Also it looks like it is pointing to the sc_task table when it need to be on the sc_req_item table.  In the email logs did you try clicking Preview HTML Body related link.

View solution in original post

39 REPLIES 39

Scott Jordheim
Giga Guru

In this case, you would need to use ${current.variables.yourVariableName} whenever you wanted to call them in the notification. If that workflow currently is tied to the catalog item in question, you can use that Fields dot-walking box to get to them as well. (Click the +, then go down to variables and find the one you need, assuming that workflow is ran from the Requested Item or such table.)

Ok I will try this Thanks

Brian Lancaster
Tera Sage

Here is a mail script I use to send out all the filled out variables on a Requested item.  So if a variable is not mandatory and was not filled out it will not be sent.  Hope this helps.

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
	
	// Add your code here
	template.print("Summary of Requested item:\n");
	var task = new GlideRecord("sc_task");
	var sc_number = '';
	task.addQuery('request_item', current.sys_id);
	task.query();
	if (task.next()){
		sc_number = task.number;
	}
	var item = new GlideRecord("sc_req_item");
	item.addQuery("sys_id", current.sys_id);
	item.query();
	while(item.next()) {
		template.print(item.number + ":  " + item.cat_item.getDisplayValue() + "\n");
		template.print("Task Number: " + sc_number + "\n");
		template.print("    Item Options:\n");
		
		
		//var keys = new Array();
		var set = new GlideappVariablePoolQuestionSet();
		set.setRequestID(item.sys_id);
		set.load();
		var vs = set.getFlatQuestions();
		for (var i=0; i < vs.size(); i++) {
			if(vs.get(i).getDisplayValue() != '') {
				template.space(4);
				template.print('     ' +  vs.get(i).getLabel() + ": " + vs.get(i).getDisplayValue() +"\n");
			}
		}
	}
	
})(current, template, email, email_action, event);

 

Should this be added to the workflow notification or should I create an event and a separate notification?