UI Action on form to create and assign a survey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2025 08:56 AM
Hello. I have the following UI Action button - Task Assessment, that when clicked on the [idea] form table should create and assign a new survey. Within the UI Action I added the following triggerAssessment() function:
function triggerAssessment() {
// Call a GlideAjax Script Include to start the assessment
var ga = new GlideAjax('TriggerAssessment');
ga.addParam('sysparm_name', 'startAssessment');
ga.addParam('sysparm_idea_sys_id', g_form.getUniqueValue());
ga.getXMLAnswer(function(response) {
if (response) {
// Show a confirmation or open modal
g_form.showFieldMsg('short_description', 'Assessment has been assigned. Please check the portal.', 'info');
} else {
g_form.showFieldMsg('short_description', 'Error assigning assessment.', 'error');
}
});
and the following Script Include:
var TriggerAssessment = Class.create();
TriggerAssessment.prototype = Object.extendsObject(AbstractAjaxProcessor, {
startAssessment: function() {
var ideaId = this.getParameter('sysparm_idea_sys_id');
if (!ideaId) return false;
var ideaGR = new GlideRecord('idea');
if (!ideaGR.get(ideaId)) return false;
// Create assessment instance
var asmtUtils = new AssessmentUtils();
var instanceId = asmtUtils.createAssessmentInstance('23f2df3ffb46ee10a70ef7937befdcaa', ideaGR.sys_id);
return !!instanceId;
}
});
I tried using the AssessmentUtils to create a new instance of the survey and yet for some reason it still doesn't work. Any ideas as to why this is happening?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2025 07:48 PM
Hello @mmarinov007,
AssessmentCreation
API to create the survey and then assign it to a user.
- Table:
idea
- Action name: A unique name for the UI Action (e.g.,
create_assessment_on_idea
) - Form button: Check this box to display the action as a button on the form.
- Client: Uncheck this box, as the core logic will be server-side.
- On click: You can optionally add a client-side function here to provide a confirmation message or handle other client-side logic before submitting the server-side script.
- Script: This is where the server-side logic will reside.
(function executeUACode(current, g_scratchpad, baseElement) {
try {
// 1. Define the assessment type (replace with your actual assessment type sys_id)
var assessmentTypeSysId = 'your_assessment_type_sys_id'; // Replace with the actual sys_id of the assessment type
// 2. Get the user to assign the assessment to (e.g., current user, a specific user, etc.)
var assignee = gs.getUserID(); // Or gs.getUser().getID() or any other user's sys_id
// 3. Create the assessment using the AssessmentCreation API
var assessmentCreation = new sn_assessment_core.AssessmentCreation();
assessmentCreation.setUser(assignee);
assessmentCreation.conditionTrigger(current, assessmentTypeSysId);
// 4. Optionally, handle success or failure
gs.addInfoMessage('Assessment created and assigned to: ' + gs.getUserDisplayName());
} catch (err) {
gs.addErrorMessage('Error creating assessment: ' + err);
}
})(current, g_scratchpad, baseElement);
If this is helpful, please mark it as helpful and accept the correct solution by referring to this solution in future, it will be helpful to them.
Thanks & Regards,
Abbas Shaik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2025 02:38 AM
If we had to make it client callable how would it work? Here is the UI Action implementation:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2025 08:06 PM
is glideajax working?
what debugging did you do?
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