Creating surveys from a script

Tim34
Tera Contributor

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

 

 

 

1 ACCEPTED SOLUTION

Hayo Lubbers
Kilo Sage

Hi,

 

The createAssessments returns a sysId of the assessment/survey and/or the groupId.

See for details how the result looks like at:

https://developer.servicenow.com/dev.do#!/reference/api/washingtondc/server_legacy/c_AssessmentCreat...

 

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

View solution in original post

8 REPLIES 8

Hayo Lubbers
Kilo Sage

Hi,

 

The createAssessments returns a sysId of the assessment/survey and/or the groupId.

See for details how the result looks like at:

https://developer.servicenow.com/dev.do#!/reference/api/washingtondc/server_legacy/c_AssessmentCreat...

 

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

I was able to get it to work. Thanks so much for your help on this. I was able to set a result variable to capture the instanceId to use to update the task, trigger, table information. That was exactly what I needed.

Thanks again!

Gpope
Tera Contributor

Hi @Tim34 , 

 

How are you sending the survey notification link ? Can you please share me all the steps you did to make it work ? 

 

Thanks a lot 🙂

Tim34
Tera Contributor

Hi Gpope, the survey notification link is sent out by a Notification that I setup based on certain conditions. You can define who to send it to and under what conditions. The email sent contains the survey link.

 

Is there anything specific you wanted to know?