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

Yes, you can add this functionality to your assessment submission process. Here are the general steps:

  1. Add a UI action to the assessment table that triggers a script when clicked.

  2. In the script, check if the user has already submitted an assessment for the record by checking if a related assessment result record exists with their user ID.

  3. If a related assessment result record exists, prompt the user with a yes/no pop-up question asking if they want to edit their existing assessment.

  4. If the user selects "yes," redirect them to the assessment form for editing. If they select "no," do nothing or display a message confirming their decision.

Here is an example of what the UI action script might look like:

 

(function() {
    var assessmentID = g_form.getUniqueValue();
    var currentUserID = g_user.userID;

    var assessmentResult = new GlideRecord('asmt_assessment_result');
    assessmentResult.addQuery('assessment', assessmentID);
    assessmentResult.addQuery('user', currentUserID);
    assessmentResult.query();

    if (assessmentResult.next()) {
        if (confirm('You have already completed the assessment. Would you like to edit your existing assessment?')) {
            var resultID = assessmentResult.getUniqueValue();
            var editURL = '/assessments.do?action=edit_result&sys_id=' + resultID;
            window.location.href = editURL;
        }
    } else {
        alert('You have not yet completed the assessment.');
    }
})();

 

This script checks for an assessment result record that matches the current assessment and user ID. If a match is found, it displays the pop-up question and redirects the user to the assessment edit form if they select "yes." If no match is found, it displays a message indicating that the user has not yet completed the assessment.

 

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

 

Hi Punit,

Thank you for the reply, could you please suggest me how can we so the same thing for story table.

 

Cindy, yes it's very much possible , however may not align well with the process as closed stories would not supposed to be re-opened. 

 

To add a popup message on the  rm_story table in ServiceNow, you can create a Client Script that triggers on a specific event, such as when the user clicks on the story link. Here are the general steps to do this:

  1. Go to the Client Scripts module in ServiceNow (you may need to search for it in the navigation bar).
  2. Click on the  New button to create a new client script.
  3. Give the script a name and select the appropriate table (in this case, rm_story).
  4. Choose the event that triggers the script. For example, you can select onLoad to trigger the script when the record loads.
  5. In the  Script field, enter the code to display the popup message. Here's an example code snippet:

 

if (g_form.getValue('state') == 'complete') {
  if (confirm('You have already completed this story. Would you like to edit your existing story?')) {
    // User clicked "OK", do something
  } else {
    // User clicked "Cancel", do something else
  }
}

 

 

This code checks if the story is already completed (based on the value of the state field) and displays a popup message using the confirm  function. If the user clicks "OK", you can add code to edit the existing story. If the user clicks "Cancel", you can add code to do something else, such as redirecting to a different page.

  1. Save the client script.

Note that this is just a basic example, and you may need to customize the code depending on your specific requirements. Also, make sure to test the script thoroughly before deploying it to production.

 

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

 

 

Hi Punit,

Thank you for reply. I am creating custom ranking assessment for story table. I need script for invoke assessment: Clicking the assessment that has been submitted  prompts submitter with yes/no pop up question dialog box: 'You have already completed assessment. Would you like to edit your existing assessment?'. If the user selects 'yes' User would be able to modify assessment just like in risk assessment. 

Right now I am not able to achieve this. Could you suggest any script for this?

Thanks,