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

Mohammad Danis1
Giga Guru

Hi @tomaslindev ,
Please try to print instanceId. see if you are actualy geting the right sys_id of assessment instance.

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

Hi @Ankur Bawiskar, 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.

 

(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');

 

tomaslindev_0-1751968174446.png

 

@tomaslindev 

Glad to know that my comment helped.

I believe I answered your original question about redirection.

The discussion can continue on an answered thread.

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