Pop up question in assessment

Cindy Sim
Tera Expert

Could anyone also may be suggest to add  functionality :

Clicking the assessment that has been submitted  prompts submitter with yes/no pop up question: 'You have already completed assessment. Would you like to edit your existing assessment?'

 

1 ACCEPTED SOLUTION

Thank you Punit. I tried this script is not getting anything after 'if'. It is exact same script except the table name is asmt_assessment_instance. Any thing I am missing, Please give me suggestion. I appreciate any input

 

View solution in original post

6 REPLIES 6

Punit S
Giga Guru

Cindy, 

 

Here is a sample script that you find useful . 

 

function onClickAssessment() {
  var assessmentGr = new GlideRecord('ranking_assessment');
  assessmentGr.addQuery('story', current.sys_id); // Replace "story" with the field name of the story reference field on your assessment table
  assessmentGr.addQuery('submitter', gs.getUserID());
  assessmentGr.query();
  if (assessmentGr.next()) {
    var answer = confirm('You have already completed assessment. Would you like to edit your existing assessment?');
    if (answer == true) {
      gs.getSession().setAttribute('assessment_id', assessmentGr.sys_id);
      action.setRedirectURL('/assessment.do?sys_id=' + assessmentGr.sys_id);
    }
  } else {
    action.setRedirectURL('/assessment.do?sysparm_query=story=' + current.sys_id); // Replace "story" with the field name of the story reference field on your assessment table
  }
}

 

This script assumes that you have a table named "ranking_assessment" with a reference field to the "story" table, and that the "submitter" field is used to track who submitted the assessment. You'll need to adjust the script to match the field names and table names in your specific implementation.

To use the script, create a UI action on the form for your "story" table, and set the "Client" field to "true". In the "Script" field, paste the above script. This will create a button on the story form that, when clicked, will check if the user has already submitted an assessment for the current story. If they have, it will display a confirmation dialog asking if they want to edit their existing assessment. If they choose "yes", it will redirect them to the existing assessment record. If they choose "no" or they haven't submitted an assessment yet, it will redirect them to the assessment form to create a new assessment.

I hope this helps! Let me know if you have any questions or need further assistance.

 

Please mark my answer as a solution/helpful in case it adds value and moves you a step closer to your desired ServiceNow solution goal.

Thanks,
Punit

Thank you Punit. I tried this script is not getting anything after 'if'. It is exact same script except the table name is asmt_assessment_instance. Any thing I am missing, Please give me suggestion. I appreciate any input