- 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,
I suspect that the eventQueue call might not be correct as the arguments for this function call needs to be string .
gs.eventQueue('task.send_survey', task, recipient, getSurveyURL);
In above line, getSurveyURL is a function call and function calls are defined as getSurveyURL().
Make sure that you arguments are String.
Please try and update if it works for you.
Please mark correct or helpful in case it helps.
Thanks!
Vikas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2020 01:28 AM
Hi,
Also as mentioned by Dhananjay above, second parameter needs to be a gliderecord object and I dont see there is any GlideRecord initialized with variable task.
Thanks!
Vikas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2020 02:22 AM
check this out:
gs.eventQueue('task.send_survey', task, recipient, getSurveyURL);
task is undefined here. replace it with current or gliderecord object as below.
gs.eventQueue('task.send_survey', current, recipient, getSurveyURL);
Please mark as Correct Answer and Helpful, if applicable.
Thank You!
Abhishek Gardade
Abhishek Gardade