Custom 'Take Assessment' UI action

SNowPatroller
Tera Contributor

Hello,

 

We are trying to improve our GRC assessment process by allowing users to take the assessment directly from the Risk.

 

The issue is there can be multiple respondants to the Risk and therefore multiple assessment instances.  We have the code to determine the take assessment instance url based on the current user.  We then want to redirect the user to that page. 

 

We have tried the following 2 options.

 

1. Only using Server Side code

Outcome: Able to get the correct URL but does not redirect to the page

var sysID = current.sys_id.toString();
var userID = gs.getUserID().toString();
gs.addInfoMessage('Risk sysID: ' + sysID);
gs.addInfoMessage('Risk userID: ' + userID);

var gr = new GlideRecord('asmt_assessment_instance');
gr.addEncodedQuery('state=ready^user=' + userID + '^sn_grc_item=' + sysID);
gr.query();


if (gr.next()) {

    var attSysID = gr.sys_id;

    var link = new global.AssessmentUtils().getAssessmentInstanceURL(gr.sys_id);
    var url = '' + link + '';
    url += '&sysparm_view=default_view';

    var urlLink = url.toString();
    current.u_assessment_instance_link = urlLink;
    current.update();
    gs.addInfoMessage('Risk Link: ' + link);
    gs.addInfoMessage('Risk URL: ' + url);
    action.setRedirectURL(urlLink);

}

 

 

2. Server Side and Client Side

Outcome: The URL gets updated after the redirection, therefore the second time the user clicks the button, they are sent to the correct URL. 

 

 

function getAssessment() {

    var sysID = current.sys_id.toString();
    var userID = gs.getUserID().toString();
    gs.addInfoMessage('Risk sysID: ' + sysID);
    gs.addInfoMessage('Risk userID: ' + userID);

    var gr = new GlideRecord('asmt_assessment_instance');
    gr.addEncodedQuery('state=ready^user=' + userID + '^sn_grc_item=' + sysID);
    gr.query();


    if (gr.next()) {

        var attSysID = gr.sys_id;

        var link = new global.AssessmentUtils().getAssessmentInstanceURL(gr.sys_id);
        var url = '' + link + '';
        url += '&sysparm_view=default_view';

        var urlLink = url.toString();
        current.u_assessment_instance_link = urlLink;
        current.update();
        gs.addInfoMessage('Risk Link: ' + link);
        gs.addInfoMessage('Risk URL: ' + url);
        action.setRedirectURL(atLink);

    }

}

if (typeof window == 'undefined')
    getAssessment();


function openAssessment() {

    var atLink = g_form.getValue('u_assessment_instance_link');
    g_navigation.openPopup(atLink);
    gsftSubmit(null, g_form.getFormElement(), 'take_assessment');
}

 

5 REPLIES 5

If the URL link field is not being updated after the server-side script runs, it's possible that the script is not executing due to access controls or user permissions. Here are some things you can try:

  1. Make sure that the UI action is visible and available to the user. Check the "UI Action" related list on the "sys_ui_action" table and make sure that the action is marked as "Active" and is visible to the user's role.

  2. Check if the user has the necessary permissions to access the "asmt_assessment_instance" table and related records. Make sure that the user's role has the necessary read and write permissions to the table and that there are no access controls that restrict access to the records.

  3. Check the system logs for any errors or messages related to the UI action or the server-side script. The logs can provide useful information on why the script is not executing.

If none of the above steps work, you may want to consider reaching out to ServiceNow support for further assistance.