Need to add field name dynamically in Subject of notification

Priyanka77
Tera Guru

Hi,
My requirement is to trigger email for multiple people for below conditions:
There are 4 fields in a table and that 4 refers to sys_user table. Through catalog item if I change any one field then it should send notification to all those people. In subject line I need to give label of that four fields after changes.

For example: Four fields: A,B,C,D
if "A" field changes then in subject line it should show: A(label not the name) has been changed for "x"record.

Please give me some solutions.

Thanks,
Priyanka

8 REPLIES 8

Mr_m1
Tera Expert

HI Priyanka,

 

1) You can update your Trigger condition, on when your required field changes.

2) Adding that field in the subject 
3) This above will helps

 

Please mark it as helpful if it works

 

Thanks

Mr.M

Filipe Cruz
Kilo Sage
Kilo Sage

Hi Priyanka,

I can provide a solution.

1) Trigger your notification by triggering an event: Set a business rule in your table (catalog item table) that if any of the fields A,B,C or D change, then the event will be triggered. you need to pass the current record and as param1 you can put a comma-separated list of fields that changed (ex: A, B, D).
You can create your event like this:

gs.eventQueue('name_of_event',current,"A,B,D");



2) Set your notification to be triggered by the event

3) Create a mail script, associated with your notification, that will query your catalog item (based on the that is in event.instance that contains the sys_id of your catalog item and event.table that contains the name of the table you want to query) and will get the current value of fields that are in param1.
Then you can use the statement template.print to print data in your notification.


Can this solution suits your needs?

Please mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Best Regards,

Filipe Cruz

Hi @Filipe Cruz ,

Thanks for the response.

I already created a BR in which I have added the filter condition and in script also gs.eventQueue added. But once if out of four fields one got change that one how can I dynamically add label of that field in subject of notification.

Can you please suggest me here

Hello Priyanka,

If you follow the solution I provided, in the mail script you can have something like this:

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

	var gr = new GlideRecord(event.table);
	gr.getValue(event.instance);
	var fields = event.parm1.split(",");
	var field_labels = [];
	
	for(var field in fields){
		fields.push(gr.getLabel(field));
	}

	email.setSubject("Fields " + field_labels.join(", ") + " changed!");

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

 

Please let me know if this is clear for you!

Please mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Best Regards,

Filipe Cruz