"Create User Survey" UI Action

Fabian10
Tera Guru

Hi

We like to create a UI Action on the Incident Form, which is displayed, when the Incident is resolved. This UI Action is called "Create User Survey". By clicking this UI Action we like to create a Assessment for this Incident.

I already tried to use "SNC.AssessmentCreation().createAssessments", but when I run the following code in Background Scripter I get the following result:

Script

var metric = '502a2c44d7211100158ba6859e6103a3';

var incident = '4f88910c4f5276006af8c0501310c750';

var user = 'f34c7c6b4f79f2408c8908111310c774'

gs.print(new SNC.AssessmentCreation().createAssessments(metric, incident, user));

Result:

*** Script: ,1,

No assessment instance has been created 😞

I also tried to use the following code:

var asmt_condition_trigger = 'ec8dce994fb5ba008c8908111310c762';

(new sn_assessment_core.AssessmentCreation()).conditionTrigger(current, asmt_condition_trigger); //current is the incident

But the problem with this is, that my condition trigger has a Repeat Interval of 30 Days configured. So this doesn't work, when there already was a assessment in the last 30 days.

Can anybody help me to get this UI Action working?

Best regards,

Fabian

4 REPLIES 4

snehabinani26
Tera Guru

Hi Fabian,



Check this link Add survey button to the Incident Form



Hope this helps


Hi Sneha



Thank's a lot!



Unfortunately, they also start a survey by triggering the Trigger Condition:


new SNC.AssessmentCreation()).conditionTrigger(current, 'aac09e696f772100809df941be3ee4e8');



I already tried this, it's similar to my second approach.


var asmt_condition_trigger = 'ec8dce994fb5ba008c8908111310c762';


(new sn_assessment_core.AssessmentCreation()).conditionTrigger(current, asmt_condition_trigger); //current is the incident



For my first approach (SNC.AssessmentCreation().createAssessments) I followed this link: Re: Trigger survey form UI action button?



Best regards,



Fabian


johnny27
Tera Contributor

I believe we are experiencing the same issue. The output for the createASsessments call also returns the annoying ,1,



I'm on Geneva.


johnny27
Tera Contributor

Hey Fab,



Someone from servicenow just resolved this issue for me on hi. The trick was to have a blank string for sourceRecordID in the createAssessments call



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


var sourceRecordID = ''; //Actually just leave this as an empty string


var userID = current.caller_id.sys_id; //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.


var result = new SNC.AssessmentCreation().createAssessments(typeSysID, sourceRecordID, userID);



But it does look like it doesn't properly set the trigger_id and related record fields so you'll need to update them accordingly.



var asmtGR = new GlideRecord("asmt_assessment_instance");


asmtGR.get(result.split(",")[0]);


asmtGR.setValue('trigger_id',current.getValue('sys_id'));


asmtGR.setValue('trigger_table','incident');


asmtGR.update();




Hope this helps others.