Use this script to warn a user when a specific field on a document is blank. In many workflows, the required attribute of a field may not be practical to implement, but users still need to be aware when the field is left blank. The document in its original state may not have the required data, but at some point in the workflow it should be added, and users should be notified of such a condition.
The following script will inspect an invoice number field on a PO document. If invoice number is left blank, when the document is opened the Live Field will trigger a browser alert window, notifying the user of this condition.
GlobalSearch Go
if ($$inject.fields['Invoice Number'] == '') {
alert('Warning: Invoice Number is blank on this record. Please verify no invoice has been received.');
}
return "Invoice Verification Checked";
GlobalSearch Legacy
var viewHash = 'viewed-'+$$inject.properties.document.fileId;
if(!sessionStorage.getItem(viewHash)) {
sessionStorage.setItem(viewHash, true)
if($$inject.fields['Invoice Number']=='')
alert('Warning: Invoice Number is blank on this record. Please verify no invoice has been received.');
}
return "Invoice Verification Checked";
When applied to a Live Field and that field is applied to an archive with an Invoice Number that is blank, opening the document throws the following browser alert:
Troubleshooting
Issue: The popup message doesn’t always appear when I open the document in GlobalSearch Go but appears to work fine in the legacy browser.
Reason: There is logic in your javascript that check the browser cache to see if the document has been previously opened. In the session storage, there is a key viewed-NO_CACHE that gets written when you open a doc. As long as that key is there, the live field triggers but the if(!sessionStorage.getItem(viewHash)) {statement evaluates as false, the popup is skipped.
Solution: To make the popup appear every time when using GlobalSearch Go and the page is opened, remove all of the sessionStorage logic (viewHash, getItem, and setItem). See the GlobalSearch Go example above.