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.

var viewHash = 'reasons-'+$$;
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 == '')

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

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