Email notification to CC current logged in user

Abhinab Achary1
Tera Guru

Hi All,

I am a bit stucked in mail notifcation.

I have a notification that send email to people when someone initiates transaction from UI action.

>I was solving using the 'event creator ' checkbox , strangely it dont work.. (Event triggered notification)

So lets say User A initiated and click button and now mail needs to go to User B and C 

with this check box on : it should trigger to B ,C and also to A(event creator).

 

>Another approach is i was the id of user to the mail script and use

(Event triggered notification)

call mail script for the mail notification 

So recipients are in Event.param2 and cc needs to be there from mail script as below

email.addAddress('cc', userEmai);

 

I cannot use last param of event as the CC or the fixed logged in user and content needs to be passed via that dynamically..

 

I don't know what I am doing wrong. similar situation worked well in past.

Thanks in Advance..

Abhinab

 

 

1 ACCEPTED SOLUTION

yes. even the hardcoded didnot work either.

 

The problem is may be it donot apear in email logs but mentioned in copied may be that is how it works and not come as a separate in email logs.

In my instance outgoing emails are blocked. 

find_real_file.png

View solution in original post

15 REPLIES 15

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Abhinab,

So send to event creator checkbox is true but it didn't send to A?

Possibly try including user A as well in the recipients when you are setting the recipients using gs.eventQueue()

Can you share the script which triggers gs.eventQueue()

Regards
Ankur

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

This is the SI..

event creator ,, doesnot work.

var ProcessEmailFOT = Class.create();
ProcessEmailFOT.prototype = Object.extendsObject(AbstractAjaxProcessor, {
triggerEmail: function() {

var selectedFots = this.getParameter("sysparam_fots");
var emailNotes = this.getParameter("sysparam_emailBody");
var currentUserID = this.getParameter("sysparam_userfrom");
gs.log(currentUserID,'AAtest');
var au = new ArrayUtil();
var userList = [];
var messageElement = {};
var msgArr = [];
var fotGr = new GlideRecord("cert_follow_on_task");


fotGr.addQuery('sys_id', 'IN', selectedFots);
fotGr.query();
while (fotGr.next()) {

userList.push(this.getUserID(fotGr.u_pdd_tech_debt_manager) + '');
messageElement.sid = fotGr.sys_id + '';
messageElement.tdmId = this.getUserID(fotGr.u_pdd_tech_debt_manager) + '';
msgArr.push(JSON.stringify(messageElement));

if (JSUtil.notNil(fotGr.u_pdd_tech_debt_manager)) {
var activityNotes = "From: " + gs.getUserDisplayName() + '\n';
activityNotes += "To: [ PDD Tech Debt Manager ] - " + fotGr.u_pdd_tech_debt_manager + '\n';
activityNotes += "Sent: " + gs.nowDateTime() + '\n';
activityNotes += "Message:\n---------------------------------------------------------------------\n\n " + emailNotes + '\n';
fotGr.work_notes = activityNotes;
fotGr.update();
}

}
var st = '';

// userList.push(currentUserID);
userList = au.unique(userList);

for (var i = 0; i < userList.length; i++) {
for (var j = 0; j < msgArr.length; j++) {
var pd = JSON.parse(msgArr[j]);
if (userList[i] == pd.tdmId) {
st += pd.sid + ',';
}
}
st = st.replace(/,\s*$/, "");

var jsob = {};
jsob.note = emailNotes;
jsob.ids = st;
jsob.loggedId = currentUserID;
var parser = new JSON();
var formattedDetails = parser.encode(jsob);
// userList.push(currentUserID);
gs.eventQueue('fots.list.email.tdd.mgr', fotGr, userList[i], formattedDetails);
st = '';
}
var listMissing = this.ifAnyPddTdmMissing(selectedFots);
if (listMissing) {
return 'Email for following FOT are ignored as PDD Tech Debt Manager is empty \n' + listMissing;
}
},


ifAnyPddTdmMissing: function(fotsId) {
var missingPdd = '';
var fotGrp = new GlideRecord("cert_follow_on_task");
fotGrp.addEncodedQuery('u_pdd_tech_debt_managerISEMPTY^sys_idIN' + fotsId);
fotGrp.query();
while (fotGrp.next()) {
missingPdd += fotGrp.number + ',';
}
missingPdd = missingPdd.replace(/,\s*$/, "");
if (JSUtil.notNil(missingPdd)) {
return missingPdd;
} else {
return false;
}

},


getUserID: function(userName) {

var userGr = new GlideRecord('sys_user');
userGr.addEncodedQuery('name=' + userName + '^active=true');
userGr.query();
if (userGr.next()) {
return userGr.sys_id;
}
},

type: 'ProcessEmailFOT'
});

 

 

////////////////////////Mail script

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

var jsonObject = event.parm2;
var obj = JSON.parse(jsonObject);
var sIds = obj.ids;
var loggedUser = obj.loggedId;
var url = gs.getProperty('glide.servlet.uri') + 'cert_follow_on_task_list.do?sysparm_query=sys_idIN' + sIds + '&sysparm_view=';

template.print('Dear ' + getDetails(sIds,'u_pdd_tech_debt_manager') + ',<br><br>');
template.print('The Follow on task(s) is requested for an update by: ' + event.user_name + '<br><br>');
template.print(getDetails(sIds,'number')+'<br><br>');

template.print('Message: ' + obj.note + "<br>");
template.print('Click here to view record(s): <a href="' + url + '">' + 'Link' + '</a><br>');

var user = new GlideRecord('sys_user');
user.addQuery('sys_id',event.user_id);
user.query();
if(user.next()){
gs.log(user.email.toString()+user.name.toString(),'abhi6567');
email.addAddress("cc",user.email.toString(),user.name.toString());
}

function getDetails(fotId, fieldName) {

var fotGr = new GlideRecord('cert_follow_on_task');
fotGr.addQuery('sys_id', 'IN', fotId);
fotGr.query();
if (fieldName == 'u_pdd_tech_debt_manager') {
if (fotGr.next()) {
return fotGr.u_pdd_tech_debt_manager + '';
}
}
if(fieldName == 'number'){
var str ='';
while(fotGr.next()){
str += fotGr.number+', ';
}
str = str.replace(/,\s*$/, "");
return str;
}

}

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

Hi,

Can you include logged in user while including in recipients?

Regards
Ankur

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

for all the recipient the message format is dynamic.. so logged in user its different.. cannot include in same list