- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2024 06:15 AM
When using new SNC.AssessmentCreation()).createAssessments, how do you associate the newly created survey with a task record? For example, an incident, change request, etc, like happens when you use the trigger.
I can associate it with a record if you use sn_assessment_core.AssessmentCreation()).conditionTrigger, but then you have to use the "opened by" or "assigned to" user field that is configured in the trigger.
SNC.AssessmentCreation()).createAssessments
For above function, I can create surveys and assign them to a user of my choosing in the script. However, there is no option to tie it to a task record like change request.
sn_assessment_core.AssessmentCreation()).conditionTrigger
For this above function, I can create surveys that are tied to a task record like change request, but I have to assign the survey to the user record that is in the trigger.
I was hoping I could do something like SNC.AssessmentCreation()).createAssessments but tie it to a task record like incident or change.
I hope that makes sense.
Thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2024 06:59 AM
Hi,
The createAssessments returns a sysId of the assessment/survey and/or the groupId.
See for details how the result looks like at:
When you have the assessment instanceId, you can link the record(task) via script. Something like:
function getInstanceId(userId) {
//generate the instance for this instance and return the sys_id
var assessmentId = 'YouAssessmentId'; //sys_id of the survey/assessment
var result = new global.AssessmentUtils().createAssessments(assessmentId, '', userId);
result = result.split(',');
var instanceId = result[0];
grInstance = new GlideRecord('asmt_assessment_instance');
if (grInstance.get(instanceId)){
grInstance.setValue('task_id', current.getUniqueValue());
grInstance.setValue('trigger_id', current.getUniqueValue());
grInstance.setValue('trigger_table', current.getTableName());
grInstance.update();
}
return instanceId;
}
Regards,
Hayo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2024 11:56 AM
Hi @Tim34 ! Thanks for your reply.
I need to create a survey to external users that we only have the email on a string field on a case record. When the case is resolved, I need to trigger this survey to that contact email added on the form.
I was breaking my head on different scripts but I see you solve it here.
Can you please show me what is the script to create the survey and add the questions on it ?
I need to set the users in the assessment record because as they are externals, they always shows as GUEST.
Thanks!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2024 12:29 PM
Hi Gpope, I accepted the solution that was given by Hayo Lubbers. The solution he provided worked for me. You just need to fill in the specific sys_id's that you have (assessmentId, userId, task_id, trigger_id, trigger_table). Is there something specific that isn't working? One thing I did, was I only ever wanted to trigger the survey from the script. Therefore, I created a trigger with conditions that would never be true, but I could still reference the trigger_id in the script for when I wanted to create the survey. Let me know if you have any questions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2024 11:59 AM
Hi again @Tim34 .
I was able to trigger the survey from that script. But when i send the notification with the link there is another assessment instance created also for GUEST user. I can see the one created from the script but stays as Ready to Take. How are you doing that part?
Thanks a lot!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2024 01:06 PM
Hi Gpope,
In that script you assign the survey to the user here where userId is listed. That's the sys_id of the user:
var result = new global.AssessmentUtils().createAssessments(assessmentId, '', userId);
In your notification that you send out, there is a "Who will receive" section where you specify who you want the survey sent to. I'm not sure why another assessment instance is being created for GUEST user. I would check your trigger conditions to make sure you're not accidentally creating another survey. It's hard for me to troubleshoot this without more details. If all else fails and you can't find anything in the community about a similar issue, maybe you could try raising a support case.