In some scenarios, we want to be able to generate on-demand assessments, that can be Service Portal or UI Action or Business rule
ServiceNow AssessmentCreation API provides a way to generate assessments via script. In the article, I am using createAssessments method to generate assessments via Service Portal Widget
first here is a quick explanation of the method parameter
AssessmentCreation.createAssessments (String typeID, // Assessment Metric Type Sys ID
String sourceRecordID, // Assessable Record which will be the source of assessment
String userID // users ID to which to send assessment instances to
)
Let’s put AssessmentCreation to action
- I create ServiceNow Portal service in cmdb_ci_service table which will be my source ID.Service Sys_ID is 4baec2fe07d3f0101263f19d7c1ed0a6
- I create Assessment type named ServiceNow Portal Assessment which trigger on Demand. Assessment Metric type Sys_ID is d902e09a075730101263f19d7c1ed03a

Now we have the Assessment Metric type and Source Record ready let’s think about how and when we are going to trigger the assessment?
I would like to trigger the assessment randomly for whoever visits my service portal home page on day 23 so I decide to create a widget and add it to my portal home page. the widget contains the server script below which create assessment instance.
(function() {
var gdtSurvey = new GlideDateTime();
if (gdtSurvey.getDayOfMonthUTC() == 23) {
(new SNC.AssessmentCreation()).createAssessments('d902e09a075730101263f19d7c1ed03a', '4baec2fe07d3f0101263f19d7c1ed0a6', gs.getUserID());
data.uSelected = 'You have been selected to take Service Poral Assessment';
}
})();