Show previous assignmnet group, state values from fields into notification

thirumala2
Tera Guru

Hi ,

We have a requirement to send the below details in  a notification :

The Assignment Group has been changed from << Old Assignment Group >> to << New Assignment Group >>

                           The State has changed from << Old State >> to << New State >>

 

How to show the previous values of assignmnt grps,states ?

 

@Ankur Bawiskar ,

@shloke04 

 

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@thirumala2 

you can use eventQueue based approach to trigger email and send the current and previous group value in event parm2

I hope you are aware on how to create event on your table, how to link email notification with event, how to include email script in email body

You can find examples in docs.

Example

After update BR

var obj = {};
obj["old_group"] = previous.assignment_group.toString();
obj["new_group"] = current.assignment_group.toString();
obj["old_state"] = previous.state.getDisplayValue().toString();
obj["new_state"] = current.state.getDisplayValue().toString();

gs.eventQueue('event_name', current, 'recipient', JSON.stringify(obj));

Then you can use email script in email body

(function runMailScript(current, template, email, email_action, event) {

	// Add your code here
	var jsonObj = JSON.parse(event.parm2);
	template.print("The Assignment Group has been changed from " + jsonObj.old_group + " to " + jsonObj.new_group);
	template.print("The state has been changed from " + jsonObj.old_state + " to " + jsonObj.new_state);

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

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

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

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@thirumala2 

you can use eventQueue based approach to trigger email and send the current and previous group value in event parm2

I hope you are aware on how to create event on your table, how to link email notification with event, how to include email script in email body

You can find examples in docs.

Example

After update BR

var obj = {};
obj["old_group"] = previous.assignment_group.toString();
obj["new_group"] = current.assignment_group.toString();
obj["old_state"] = previous.state.getDisplayValue().toString();
obj["new_state"] = current.state.getDisplayValue().toString();

gs.eventQueue('event_name', current, 'recipient', JSON.stringify(obj));

Then you can use email script in email body

(function runMailScript(current, template, email, email_action, event) {

	// Add your code here
	var jsonObj = JSON.parse(event.parm2);
	template.print("The Assignment Group has been changed from " + jsonObj.old_group + " to " + jsonObj.new_group);
	template.print("The state has been changed from " + jsonObj.old_state + " to " + jsonObj.new_state);

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

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

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

Mad3
Tera Expert

Hi @Ankur Bawiskar 

 

Need your assistance here!

 

Tried to get trigger notification with  after business rule when state is changed, I am able to trigger. 

--> Here when used mail script to show in email body is 

BR:- 

(function executeRule(current, previous /*null when async*/ ) {


gs.addInfoMessage("BR running");
var obj={};

obj["new_state"] = current.state.getDisplayValue().toString();
obj["new_state"] = previous.state.getDisplayValue().toString();

gs.addInfoMessage("Old State: "+obj["new_state"] +" "+ "and" +" "+ "New State: "+obj["new_state"]);

gs.eventQueue('x_sink.state.previous.current', current, 'recipient', JSON.stringify(obj));


})(current, previous);

Mail script:

var jsonObj = JSON.parse(event.parm2);

template.print("The status of the ticket has changed from " + jsonObj.old_state + " to " + jsonObj.new_state);

 

I not getting the new. You cane see in below image it looks.

Mad3_0-1682662731971.png here in image can only getting old value.

Here I want to get,   The status of the ticket has changed from Old Value  to New Value.

Mad3
Tera Expert

HI @Ankur Bawiskar 

 

I found my Mistake, Was in BR. 

 

Thanks for the code It's working....!