- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I have a survey I want to trigger every quarter for members of a particular group.
On the related list of my Survey Definition [asmt_metric_type], I can add trigger conditions, however these seem to require specific events to trigger.
On the Survey Definition record itself, there is the Schedule Period field, but this does not allow anything between monthly and yearly.
What is the solution here?
Regards,
Kim
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago - last edited 2 weeks ago
The problem is, I did not read the docs carefully enough and I did not realize there is a difference between assessments and surveys.
It says that the second parameter is ONLY for use with assessments. My "assessment" is actually a survey, so the second parameter should be left blank. Thus in my scheduled script:
triggerSurvey();
function triggerSurvey() {
try {
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery("group", "2ccabcccaf3d6a10e8f667caa6274980"); //Group SysID
gr.query();
while (gr.next()) {
new SNC.AssessmentCreation().createAssessments('37b85f99af99ba1056b7a2c651274978' */My survey definition*/, '', gr.user);
}
} catch (ex) {
gs.info(ex);
}
}
Works like a charm.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
are you able to trigger the survey using that?
it's getting assigned to which user?
how will the system know survey has to trigger to which user?
it would be nice if you could share the details so that it helps.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@Ankur Bawiskar This was a bit more complex than I thought. I assumed that it worked now because of the Recipient List I had added before in the Related Lists, but this does not appear to do anything. The reason why the survey went out correctly was because I already had Survey Users since before (which had been added during testing via my Trigger condition I think? But I'm not sure). Sending all my work to the next instance which did not have any Survey Users did not allow the scheduled job to create any new Survey Instances even when clicking "Execute now".
However, I cannot get it to work with your solution either. In my case I want to send out the survey to members of a particular group, thus I modified your script like so:
triggerSurvey();
function triggerSurvey() {
try {
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery("group", "2ccabcccaf3d6a10e8f667caa6274980"); //My group
gr.query();
while (gr.next()) {
new SNC.AssessmentCreation().createAssessments('37b85f99af99ba1056b7a2c651274978' /*My survey definition*/, gr.getUniqueValue(), gr.user);
}
} catch (ex) {
gs.info(ex);
}
}
But this creates an error message for each user that was going to get the assessment:
[AssessmentCreation - createInstances_Parameters]: For assessment 37b85f99af99ba1056b7a2c651274978, for user 9962a6fccdb116d0d14423e37806d921, instance is not created. Possible reasons are:
1. Please make sure that at least one metric category has at least one assessable record associated.
2. Please make sure that at least one metric category has at least one metric.
3. Please make sure that if domain plugin is installed, at least one assessable record is visible to this user.
4. Please make sure that at least one metric category is accessable to this user - check the roles on category.
5. Please make sure that this user has required roles to access the assessable record.: no thrown error
[AssessmentCreation - createInstances_Parameters]: For assessment 37b85f99af99ba1056b7a2c651274978, for following users [9962a6fccdb116d0d14423e37806d921], no instance is created. Please find previous error messages for details.: no thrown error
My Survey Definition has a Metric Category which in turn has a list of Assessment Metrics, and clearly the users have access because otherwise previous Assessment Instances could not have been generated. So now I'm at a loss... but I also don't understand why the second parameter should point to the GR record I use to find the user (core_company in your example), maybe the problem lies there?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Please keep the thread unanswered so that members can help you.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
the link I shared which has working solution is just for your reference.
You should enhance the script to cater to your requirement and not just pick it as it is.
Survey is always on some table record.
Example: If incident is resolved, you send survey to user to share his/her response on that INC resolution
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
I did not simply copy the code but adapted it for my use case.
What I don't understand is what to put in the second parameter. The docs are also very obscure at this point, because it says the first parameter is "The sys_id of the metric type or survey definition" while the second is "One or more comma-separated survey definition sys_ids to include in the assessments generated" - so it sounds like both parameters should be survey definition sysID's which doesn't make any sense.
