- 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 05:40 AM
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! */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2025 05:44 AM
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");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2025 06:06 AM
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! */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2025 02:51 AM
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.
(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');