How to create Survey Button on incident form

Chaitanya Redd1
Tera Guru

Hello Team,

Please help me on this issue creating Survey button incident form.

  1. I have created Survey Button on incident form but it's not triggering the survey. I have written script and condition but not working.
  2.  I wanted this button should visible only when state is closed and visible only for ITIL users.

Condition : current.active && (gs.hasRole("itil") || gs.hasRole("admin"))

Script :

var typeSysID = '99471f319f0312006371f84bc42e70f1';  //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);
asmtGR.get(result.split(",")[0]);

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

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

asmtGR.update();

 

Thanks.

1 ACCEPTED SOLUTION

Chaitanya Redd1
Tera Guru

Hello team,

I have tried below script it worked for me.

var gr = new GlideRecord('asmt_assessment_instance');
gr.addEncodedQuery('metric_type=99471f319f0312006371f84bc42e70f1^user='+current.caller_id+'^trigger_id='+current.sys_id); //Here in the metric_type add the sys_id of your Survey from 'asmt_metric_type' table
gr.query();
if(gr.hasNext()){
gs.addErrorMessage("Surevy already sent to user!");
//current.setAbortAction(true);
action.setRedirectURL(current);
}else{
var Link =(new sn_assessment_core.AssessmentCreation()).conditionTrigger(current,'249e70b0875013005d90bba826cb0bbf');
gs.addInfoMessage(" successfully assigned survey to caller");
action.setRedirectURL(current);
}

 

Thanks all for your help.

 

Thanks,

JRY

View solution in original post

7 REPLIES 7

Kunal Varkhede
Tera Guru

Hi,

 

In UI action condition

try this,

current.state=='7' && (gs.hasRole("itil") || gs.hasRole("admin"))

 //here 7 is value of close state

Thanks,

Kunal

your script worked to hide and visible only for itil users but survey is not getting triggered after click on survey button. Can you help how to set that issue.

Ankush Jangle1
Kilo Guru

hi,

Click on the "View Survey URL" Link

After you have this, you can use the action.setRedirectURL call in ServiceNow.

Example (Takes you to the OOB Service Desk Satisfaction Survey):

action.setRedirectURL('/nav_to.do?uri=assessment_take2.do%3Fsysparm_assessable_type=502a2c44d7211100158ba6859e6103a3');

 

Please Mark it Correct/Helpful if it helps you

Hi Ankush,

I have tried but it's still not triggering survey once I click on " Survey" button.

Can you please look into below script and help if any changes required.

var typeSysID = '99471f319f0312006371f84bc42e70f1';//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);
asmtGR.get(result.split(",")[0]);

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

asmtGR.setValue('trigger_table','incident');
action.setRedirectURL('https://dev79551.service-now.com/nav_to.do?uri=assessment_take2.do%3Fsysparm_assessable_type=99471f319f0312006371f84bc42e70f1');

asmtGR.update();