How to get a previous assignment group value in email notification?

bbf35621
Kilo Sage

How can I get a value of the previous assignment group, not the current one in an email notification? Do I need an email script to receive it?

1 ACCEPTED SOLUTION

Ian Mildon
Tera Guru

This business rule script is doing similar to what you are wanting:

(function executeRule(current, previous /*null when async*/ ) {
	
    if ('u_remote_user_device', true) {
	    gs.eventQueue("cmdb.ownedby.receipt", current, current.owned_by, current.owned_by.manager); //send email for receiving device
    }

    if ('u_remote_user_device', false) {
        gs.eventQueue("cmdb.returned.receipt", previous, previous.owned_by, previous.owned_by.manager); //send email for surrendering device
    }

})(current, previous);

In this these two events, I am sending the email to Parm1 and Parm2, but you can use them directly in the email script for other purposes via "event.parm1" or "event.parm2"

View solution in original post

4 REPLIES 4

sachin_namjoshi
Kilo Patron
Kilo Patron

You can configure a business rule to send previous and current object as event parameter.

After this , you will have to write email script to parse this event parameters and retrieve previous values in email script.

 

Regards,

Sachin

Ian Mildon
Tera Guru

This business rule script is doing similar to what you are wanting:

(function executeRule(current, previous /*null when async*/ ) {
	
    if ('u_remote_user_device', true) {
	    gs.eventQueue("cmdb.ownedby.receipt", current, current.owned_by, current.owned_by.manager); //send email for receiving device
    }

    if ('u_remote_user_device', false) {
        gs.eventQueue("cmdb.returned.receipt", previous, previous.owned_by, previous.owned_by.manager); //send email for surrendering device
    }

})(current, previous);

In this these two events, I am sending the email to Parm1 and Parm2, but you can use them directly in the email script for other purposes via "event.parm1" or "event.parm2"

in the email script, do I need to use JSONParse or JSONObject to get event.parm2?

In the business rule script, I use this,

gs.eventQueue("x_mtbr_ebs_shareit.notification.group", previous, previous.assignment_group.getDisplayValue(), parm2);

Drop the "parm2" part as you don't need it in your example. You have the assignment_group set as parm1.

Also you may not need to use the .getDisplayValue() but it would be best to test it out to confirm.

Here is another example that will show the passing of a parm1 value and how it was used in the email script:

var errorCount = new GlideAggregate("syslog");
errorCount.addEncodedQuery("sys_created_onONToday@javascript:gs.daysAgoStart(0)@javascript:gs.daysAgoEnd(0)^level=2");
errorCount.addAggregate('COUNT');
errorCount.query();
var finalCount = 0;
while (errorCount.next()) {
    finalCount = errorCount.getAggregate('COUNT');
    //fix time zone
    var isNow = gs.nowGlideDateTime();
    isNow.addSeconds(-18000); //subtract 5 hrs to give EST
    var nowLocal = isNow.getValue();
    //provide email message
    var errMsg = 'As of ' + nowLocal + ' there have been a total of ' + finalCount + ' system errors reported today.';
    gs.eventQueue('sys.error.count', current, errMsg); //pass message as event.parm1
}



//event name: sys.error.count


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

   //get daily count of system errors
template.print(event.parm1);

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

As you can see in the email script I'm just printing the parm1 value, which in this case is a message string