How to access event parameter in email script

_navin9898
Tera Expert

Dear Community members,

Good Day!

Could someone please let me know, how can I access event parameter in email script?

var Details = {"status" : status_code, "error_message" : errorMessage};

Ex.   gs.eventQueue('Ticket Created', gr, Details), here Details (parm1) has 2 values as above which I want to pass to my mail script. Could someone please let me know how can I accomplish this?

 

Best Regards,

Navin 

1 ACCEPTED SOLUTION

AbhishekGardade
Giga Sage

Hello Naveen,

Please check out the below Code :

1. First you need to create Json Formatted object as given below:

var Details ={

"status": 'STATUS code you want to pass',
"error_message": 'ErrorMessage you want to pass'
};

var parser = new JSON(); // Creates an instance of the JSON class.
var formattedDetails = parser.encode(Details); // json formatted object

gs.log('JSON object: '+ formattedDetails);
gs.eventQueue('TicketCreated',current,formattedDetails);

 

2. EMAIL SCRIPT:

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

// Add your code here
var jsonObject=event.parm1;
template.print("Complete Json Object: "+jsonObject+"<br>");

// Parsing JSON object:
var obj = JSON.parse(jsonObject);

template.print('status is: '+ obj.status+"<br>");
template.print("Error message is "+obj.error_message+"<br>");


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

3. You can call mail script from notification as :

        ${mail_script:demoscript}  // Replace mail script name demoscript with your mail script name

Please mark answer correct if you find it as helpful.

Thanks,

Abhishek Gardade

Thank you,
Abhishek Gardade

View solution in original post

7 REPLIES 7

AbhishekGardade
Giga Sage

Hello Naveen,

Please check out the below Code :

1. First you need to create Json Formatted object as given below:

var Details ={

"status": 'STATUS code you want to pass',
"error_message": 'ErrorMessage you want to pass'
};

var parser = new JSON(); // Creates an instance of the JSON class.
var formattedDetails = parser.encode(Details); // json formatted object

gs.log('JSON object: '+ formattedDetails);
gs.eventQueue('TicketCreated',current,formattedDetails);

 

2. EMAIL SCRIPT:

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

// Add your code here
var jsonObject=event.parm1;
template.print("Complete Json Object: "+jsonObject+"<br>");

// Parsing JSON object:
var obj = JSON.parse(jsonObject);

template.print('status is: '+ obj.status+"<br>");
template.print("Error message is "+obj.error_message+"<br>");


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

3. You can call mail script from notification as :

        ${mail_script:demoscript}  // Replace mail script name demoscript with your mail script name

Please mark answer correct if you find it as helpful.

Thanks,

Abhishek Gardade

Thank you,
Abhishek Gardade

Hi Abhishek, 

Thanks for this.

This also helped me.

 

Shiraz.

Thank you very much, this solved my problem.