- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2020 01:16 AM
Hi,
I have created an event to send a notification when the incident is resolved. I see records to be created by i don't see a notification to be sent. Can anyone help me out?
Business rule:
function onAfter(current, previous){
var num = 0;
var currentMatch = false;
var previousMatch = false;
var sc = new GlideRecord('asmt_condition');
sc.addQuery('table', current.sys_class_name);
sc.addActiveQuery();
sc.orderBy('order');
sc.query();
gs.log('Inside business rule');
//check for send all property to determine if we should fire all matching surveys or only first one
var sendAll = gs.getProperty('glide.task.survey_send_all');
while (sc.next()) {
var filter = Packages.com.glide.script.Filter;
// check to see if current and previous match condition
currentMatch = filter.checkRecord(current, sc.condition);
previousMatch = filter.checkRecord(previous, sc.condition);
//get the recipient and check to see if it's valid
var user = current.getElement(sc.user_field.toString());
if (user == null)
return;
if (user.isNil())
return;
//don't repeat surveys for x days
var daysWait = sc.duration;
if (daysWait.nil()) {
//get global default
daysWait = gs.getProperty('glide.task.survey_days_wait',30);
}
// make sure current matches and previous doesn't so this only runs once
if (currentMatch && !previousMatch) {
//see if we recently sent this survey to this user
var lastSurvey = new GlideRecord('asmt_assessment_instance');
lastSurvey.addQuery('user',user);
lastSurvey.addQuery('assessment',sc.metric_type.sys_id);
lastSurvey.addQuery('sys_created_on','>',gs.daysAgo(daysWait));
lastSurvey.query();
if (lastSurvey.next()) {
gs.log('Survey "' + sc.metric_type.getDisplayValue() + '" was not sent to ' + user.getDisplayValue() + ' since they were already sent one within the last ' + daysWait + ' days');
return;
}
//check for random survey option
if (sc.trigger_random) {
num = (100 / sc.percent_random);
if (Math.floor(Math.random() * num) == 0) {
sendSurvey(current, sc, user);
}
} else {
sendSurvey(current, sc, user);
//(new sn_assessment_core.AssessmentCreation()).conditionTrigger(current, '3515ec89dba90090bda4d602ca9619a7');
}
if (sendAll != 'true')
return;
}
}
}
//(new sn_assessment_core.AssessmentCreation()).conditionTrigger(current, '3515ec89dba90090bda4d602ca9619a7');
function sendSurvey(task, sc, recipient) {
//(new sn_assessment_core.AssessmentCreation()).conditionTrigger(current, '3515ec89dba90090bda4d602ca9619a7');
var ts = new GlideRecord('asmt_assessment_instance');
ts.initialize();
ts.task_id = task.sys_id;
ts.metric_type = sc.assessment;
ts.user = recipient;
ts.state = "ready";
ts.sys_created_on = gs.nowDateTime();
var taskSurvey = ts.insert();
var surveyURL = getSurveyURL(taskSurvey, sc.assessment.name);
gs.log("survey : " + surveyURL);
//pass survey url from here so we don't have to build it in every notification
gs.eventQueue('task.send_survey', task, recipient, getSurveyURL);
}
function getSurveyURL(taskSurvey, surveyName) {
var instanceURL = gs.getProperty("glide.servlet.uri");
var overrideURL = gs.getProperty("glide.email.override.url");
if (overrideURL)
instanceURL = overrideURL;
else
instanceURL = instanceURL + "nav_to.do";
gs.log("instanceURL is: " + instanceURL);
surveyName = surveyName.replace(/ /g,'%20');
gs.log("surveyName is: " + surveyName);
var url = instanceURL + '?uri=survey_take.do?sysparm_survey=' + surveyName + '%26sysparm_task_survey=' + taskSurvey;
gs.log("survey url: " + url);
return url;
}
Event :
Notification:
Trigger condition:
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2020 02:15 AM
Remove the fourth parameter its seems it is a function.
And do tick Sent to event creator under who will receive.
Thanks,
Dhananjay.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2020 01:25 AM
Hi,
Your second parameter should be object of gliderecord.
gs.eventQueue("incident.commented", current, gs.getUserID(), gs.getUserName());
Thanks,
Dhananjay.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2020 01:51 AM
Tried changing it but no luck.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2020 02:15 AM
Remove the fourth parameter its seems it is a function.
And do tick Sent to event creator under who will receive.
Thanks,
Dhananjay.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2020 09:18 PM
We don't have to remove the function which is the fourth parameter. Function call is necessary in this case.
I just had missed to tick the "send to event creator" check box. That solved the issue.
Thanks.