passing 3 parameters to event ( To, CC, Comment )

juan casas
Mega Expert

Hello experts,

 I want to pass 3 parameters to an event, so that I can send an email.

The functionality is driven by a custom UI page where the user can change the TO, CC, and email body.

 

The issue that I am having is, how to I route all three parameters to the notification?

 

I can only route two parameters at a time.

If I try to pass an object,  how can I select a key-value pair out of it to be included in the cc or to of the email?

 

this is what I am passing to the notification::

// param0: name of event
// param1: obj
// param2: cc
// param3: comment to be in email being send added
gs.eventQueue("x_banun_creops.ReplyEvent", gCO, {
            "to": to,
            "cc": cc
}, comment); 

1 ACCEPTED SOLUTION

Kartik Sethi
Tera Guru
Tera Guru

Hi @juan casas 

When you are passing key-values (JSON object) among different scripts then you need to convert it to string in the source script and then parse it to object again in the target script.

So you need to modify your code as provided below:

// param0: name of event
// param1: obj
// param2: cc
// param3: comment to be in email being send added

//This should be in the source script from where you are triggering the event
var obj = {};
obj.to = to;
obj.cc = cc;

gs.eventQueue("x_banun_creops.ReplyEvent", gCO, JSON.stringify(obj), comment);



//------------------------------------------------------------------------------------

//Mail script

var addressObj;

if(event.param1) {
	addressObj = JSON.parse(event.param1);
}

email.setReplyTo(addressObj.to.toString());
//NOTE: If you want to set CC as well then you need to pass display value also
//e.g. email.addAddress("cc",test@example.com,"Test User");

 

Please do the above changes.

 


Please mark my answer as correct if this solves your issues!

If it helped you in any way then please mark helpful!

 

Thanks and regards,

Kartik

View solution in original post

6 REPLIES 6

Yousaf
Giga Sage

Hi Juan,

Refer to this please

How to pass 3 parameters in gs.eventqueue()

 

Mark Correct or Helpful if it helps.


***Mark Correct or Helpful if it helps.***

what email script is that?

its the one you need to create.


***Mark Correct or Helpful if it helps.***

i made a new question that is pretty much what I was looking for from this question::

 

https://community.servicenow.com/community?id=community_question&sys_id=e9a38bd8db91115021b59b3c8a961928

 

 

so you get 2 questions since I didn't write the first one good if you know the answer