Survey Designer

tomaslindev
Mega Guru

Hi everyone,
I've created a button to validate that I need to leave a comment on the work notes and redirect me to a questionnaire. The UI Action code is as follows.

 

var templateId = '74b1332c872eae50b44aeb909bbb35db';
var assessmentUtils = new AssessmentUtils();

var instanceId = assessmentUtils.createAssessment(templateId, gs.getUserID(), current.sys_id);


if (current.isValidField('work_notes')) {
    current.work_notes = 'Encuesta técnica lanzada desde Validar';
    current.update();
}

action.setRedirectURL('/asmt_assessment_instance.do?sys_id=' + instanceId);

tomaslindev_0-1751454744167.png


I created a Survey from the Survey Designer module and tried to associate it with the button. The problem is that it leaves the comment, but the survey doesn't appear.
Any ideas?

Thank you very much, and best regards.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@tomaslindev 

you are using wrong syntax

this is correct, also the value it returns is a string and you can split it and 1st element will be assessment instance sysId

AssessmentCreation - Global 

AnkurBawiskar_0-1751462099663.png

 

var templateId = '74b1332c872eae50b44aeb909bbb35db';

var returnValue = new SNC.AssessmentCreation()).createAssessments(templateId, current.sys_id, gs.getUserID());

if (current.isValidField('work_notes')) {
    current.work_notes = 'Encuesta técnica lanzada desde Validar';
    current.update();
}

var instanceId = returnValue.split(',')[0];
action.setRedirectURL('/asmt_assessment_instance.do?sys_id=' + instanceId);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

8 REPLIES 8

GlideFather
Tera Patron

Hola @tomaslindev
you mean that it is not redirected to the survey or it is not visible?

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


Hello  @GlideFather 

I've corrected the code, and the backend redirects me to the survey, but the portal, which in this case is the FSM module, still doesn't show it.

var templateId = '1950fb64872eae50b44aeb909bbb35d1';
var assessmentUtils = new AssessmentUtils();

var instanceId = assessmentUtils.createAssessments(templateId, "" , gs.getUserID());

if (current.isValidField('work_notes')) {
    current.work_notes = 'Encuesta técnica lanzada desde Validar';
    current.update();
}

// action.setRedirectURL('/asmt_assessment_instance.do?sys_id=' + instanceId);
action.setRedirectURL('/fsmcp?id=fsmcp_take_survey&sys_id=' + instanceId);
// action.setRedirectURL("https://search.brave.com/search?q=google");

can you please review/share the query to the survey from the FSM perspective on the Portal?

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


Hi @GlideFather  thanks so much for your help, I have corrected the code and it redirects me to the correct survey, it correctly creates the survey instances but I cannot find where to associate the questionnaires.

 

tomaslindev_1-1751968251615.png

(new sn_assessment_core.AssessmentCreation()).conditionTrigger(current, '1950fb64872eae50b44aeb909bbb35d1');

var grAsses = new GlideRecord("asmt_assessment_instance");
grAsses.addQuery("trigger_id", current.getUniqueValue());  
grAsses.orderByDesc("sys_created_on");
grAsses.query();
if (grAsses.next()) {
    grAsses.setValue("user", gs.getUserID());
    grAsses.update();
}

if (current.isValidField('work_notes')) {
    current.work_notes = 'Encuesta técnica lanzada desde Validar';
    current.update();
}

action.setReturnURL(current);
action.setRedirectURL('fsm_questionnaire_list.do?sysparm_show=' + current.sys_id + '&sysparm_tablename=wm_task');