Skip to main content
Skip table of contents

Reason Code On Open

In scenarios where security is paramount, customer may want to force users to provide details on why they are accessing a document. Use this script to force users to provide a reason for accessing a document when opening.

CODE
var viewHash = 'reasons-'+$$inject.properties.document.fileId;
if(!sessionStorage.getItem(viewHash)) {
    let reason = window.prompt('Accessing this document requires a reason code to proceed. Provide a reason, or click Cancel to exit.');
    if(reason == null || reason == '')
        window.close();

    sessionStorage.setItem(viewHash, true)
    let reasonsArray = $$inject.fields['Reason Codes'];
    reasonsArray.push(reason);

    $$inject.fields['Reason Codes'] = reasonsArray;
    $$inject.save();
    $$inject.notify.info("Document auto-saved.");
    return "Reason code collected."
}
return "Reason already set."

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.