Script mentioned is for creating the assessment record but it is only updating the existing record.

Community Alums
Not applicable
Previously  it was creating the new assessment instance record and users were able to give the survey , now when we trigger this actions it is updating the old assessment instance record based on users (metric type, userID) matches and updates it.
 
Need some help on this
 
(function execute(inputs) {
var typeSysID = "Sys_id" ;//The sys_id of the metric type or survey definition to generate assessments or surveys for.
var sourceRecordID = '';
var userID = 'sys_id'; //The sys_id of the survey respondent.
var result = new SNC.AssessmentCreation().createAssessments(typeSysID, sourceRecordID, userID);
var asmtGR = new GlideRecord("asmt_assessment_instance");
asmtGR.get(result.split(",")[0]);
asmtGR.setValue('trigger_table','sc_req_item');  //table_name RITM)
asmtGR.update();
 

//outputs.survey_assessment_instance = asmtGR.getUniqueValue();
})(inputs, outputs);
1 ACCEPTED SOLUTION

YaswanthKurre
Giga Guru

Hi @Community Alums ,

 

This script call : new SNC.AssessmentCreation().createAssessments(typeSysID, sourceRecordID, userID);

will reuse an existing assessment instance and match an existing record if:

  • The metric type (typeSysID)
  • The user (userID)
  • And the source record (sourceRecordID, if provided or empty)

If sourceRecordID is empty or reused, the system assumes it's the same context and updates the existing instance.

 

To ensure a new instance is created, you must:

  1. Provide a unique sourceRecordID (e.g., the sys_id of the RITM or task).
  2. Ensure the metric type is published and has valid metric categories and assessable records.

Links to documentation and community:

  1. AssessmentCreation - Global
  2. Solved: AssessmentCreation - Global - Using Business Rule - ServiceNow Community

 

Please mark this as helpful and correct if this resolved your issue.

 

Thanks,

Yaswanth

 

 

 

View solution in original post

2 REPLIES 2

YaswanthKurre
Giga Guru

Hi @Community Alums ,

 

This script call : new SNC.AssessmentCreation().createAssessments(typeSysID, sourceRecordID, userID);

will reuse an existing assessment instance and match an existing record if:

  • The metric type (typeSysID)
  • The user (userID)
  • And the source record (sourceRecordID, if provided or empty)

If sourceRecordID is empty or reused, the system assumes it's the same context and updates the existing instance.

 

To ensure a new instance is created, you must:

  1. Provide a unique sourceRecordID (e.g., the sys_id of the RITM or task).
  2. Ensure the metric type is published and has valid metric categories and assessable records.

Links to documentation and community:

  1. AssessmentCreation - Global
  2. Solved: AssessmentCreation - Global - Using Business Rule - ServiceNow Community

 

Please mark this as helpful and correct if this resolved your issue.

 

Thanks,

Yaswanth

 

 

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Community Alums 

Can you share your complete business requirement here and where are you using that script?

New assessment will be created because of this line

var result = new SNC.AssessmentCreation().createAssessments(typeSysID, sourceRecordID, userID);

Why are you updating it later?

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