- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2025 04:12 AM
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);
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2025 06:15 AM
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
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2025 06:00 AM
Hi @tomaslindev ,
Please try to print instanceId. see if you are actualy geting the right sys_id of assessment instance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2025 06:15 AM
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
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2025 02:49 AM
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');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2025 02:56 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader