I need to trigger survey on clicking of button in service portal widget

sirisha17
Tera Contributor

I need to trigger survey from a portal widget, Let us know if anyone has worked on similar requirement.

Tried using below code, but receiving error.

new SNC.AssessmentCreation()).createAssessments('62d95a812f06011028f12f2ef699b611',"",usr)

6 REPLIES 6

dmathur09
Kilo Sage
Kilo Sage

Hi Sirisha,

Can you provide more details on the error that you are receiving?

Regards,

Deepankar Mathur

Hi Deepankar,

 

I am receiving below error.

find_real_file.png

Community Alums
Not applicable

Hi Sirisha,

I hope you have created your survey and the state of the survey is "Ready to take".

Just follow this link to setup the survey widget:

https://docs.servicenow.com/bundle/rome-servicenow-platform/page/administer/survey-administration/concept/c_SurveyServicePortal.html

Mark my answer correct & Helpful, if Applicable.

Thanks,

Sandeep

Community Alums
Not applicable

Also, 

you can add code like this to your UI Action:

var typeSysID = ''; //The sys_id of the metric type or survey definition to generate assessments or surveys for.

var sourceRecordID = current.getValue('sys_id'); //One or more comma-separated sys_ids of records to include in the assessments generated. There must be an assessable record associated with the specified metric type for each source record. If this parameter is left blank, the assessments generated include all assessable records for the specified type. This parameter is for use with assessments only.
var userID = current.getValue('some_user_field'); //One or more comma-separated sys_ids of users to send assessment or survey instances to. If this parameter is left blank, the assessment stakeholders or survey users receive instances. This parameter is required for on-demand assessments.
new SNC.AssessmentCreation().createAssessments(typeSysID , sourceRecordID , userID );

There is another aaproach:

https://community.servicenow.com/community?id=community_question&sys_id=0d980b21db5cdbc01dcaf3231f9619d5