Survey Instance behavior
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2014 10:22 PM
Hi everyone,
Is anyone here familiar with the survey management module? I created an active survey in the survey module. The triggered condition would be that, for every incident that has been resolved, a new survey instance will be created and the link will be emailed to the end user. So far, this is fine. What I noticed is that, when the end user has 2 resolved tickets in the system and both survey has not been completed, the system only shows one survey instance to the end user at the My Assessment and Surveys menu. Even if end user completed the 1st survey instance, the 2nd survey instance is never shown.
In my client scenario, I need one survey for each incident resolved. In this case, it seems that, the system does not show this "duplicate" survey even though I have 2 resolved incidents. Does anyone have any resolution to this or is it just me messing up my settings?
Your comments and helps are appreciated. Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2015 09:53 PM
Hi Alex Ng, Preety Arora, Lucas Guerino, Mehul Patel, Christian Mehring,
A couple of months back I had to work on this problem and I was able to put together a workaround. Indeed the restriction of only having 1 survey of one survey type per user in enforced by ServiceNow logic and the logic that enforces this restriction is quite kept unreachable. The only way I was able to workaround it was by fooling the system. .
In a nutshell, the concept is that as soon as the survey condition is triggered I will make the system think that there are no other survey instances of the same survey type assigned to that user. For this, the approach was to use the OOB onBefore business rule of each trigger condition where we do the following:
a) captured the sys_id of all surveys of the same survey type which was triggered and that are also assigned for the same person as the survey condition which was triggered. I will then have a list of sys_id of these existing surveys for that given user for which the survey was triggered for.
b) I will proceed to blank out the assigned_to field of these survey instance records and that will make the trick since the system would not be able to validate that there's already a survey assigned to that person and will create the respective new survey for that user (using the same code line which is in the OOB business rule in the trigger condition)
c) once the new survey instance is created then I will proceed to reassign each of the surveys captured previously and assigning back the assigned_to to these.
In order to accomplish this I modified the OOB Business Rule Generate assessment trigger condition which is responsible to automatically create the business rules through the ones the trigger conditions do the work. On that business rule i included two functions that respectively take care of the steps a, b and c explained above.
i hope that it is helpful or at least insightful in how a problem like this could be tackled
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2015 06:38 PM
Brilliant!! Thanks for sharing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2015 08:40 PM
In case it helps, here goes the code:
The following lines should go in the OOB Generate assessment trigger condition (around line 20 where the script field is assigned)
gr.script = "var assessments = unassignAssessmentInstance('" + current.sys_id + "');"; | |
gr.script += "(new SNC.AssessmentCreation()).conditionTrigger(current, '" + current.sys_id + "');"; | |
gr.script += "assignAssessmentInstance(assessments, '" + current.sys_id + "');"; |
The functions unassignAssessmentInstance and assignAssessmentInstance (stored in classless script includes) are something like the following:
function unassignAssessmentInstance(condition){
var asmtCondition = new GlideRecord('asmt_condition');
if (asmtCondition.get(condition)){
var sysIDs = [];
var assessmentInstance = new GlideRecord('asmt_assessment_instance');
assessmentInstance.addQuery('metric_type',asmtCondition.assessment);
assessmentInstance.addQuery('user',current[asmtCondition.user_field]);
assessmentInstance.query();
while(assessmentInstance.next()){
if (assessmentInstance.trigger_id.toString() != current.sys_id.toString()){
sysIDs.push(assessmentInstance.sys_id.toString());
assessmentInstance.user = '';
assessmentInstance.update();
}
}
return sysIDs.join(',');
}
}
function assignAssessmentInstance(assessmentInstances, condition){
var asmtCondition = new GlideRecord('asmt_condition');
if (asmtCondition.get(condition)){
var sysIDs = assessmentInstances.split(',');
for (var sysID in sysIDs){
var assessmentInstance = new GlideRecord('asmt_assessment_instance');
if (assessmentInstance.get(sysIDs[sysID])){
assessmentInstance.user = current[asmtCondition.user_field];
assessmentInstance.update();
}
}
}
}
I hope it's helpful and all feedback is appreciated!
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2015 03:33 AM
Many Thanks Berny for sharing the solution and code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2015 03:14 AM
You're welcome!