function onLoad() { var scriptHasUncommentedLines; var isAdvanced = (g_form.getValue('advanced') === 'true'); var origScriptVal = (g_form.getValue('script').trim()); var doesScriptExist = (!!origScriptVal); if (!isAdvanced && doesScriptExist) { scriptHasUncommentedLines = (getUncommentedLines(origScriptVal).length > 0); if (scriptHasUncommentedLines) { showExpandingFormMessage( 'ACL Script Contains uncommented Code, but the "Advanced" ' + 'Checkbox is set to false.
' + 'This code will still execute, which can cause performance issues and ' + 'unexpected behavior!', '

As per KB0728012, Business Rules and ACLs ' + 'with the "Advanced" checkbox set to false will still execute any ' + 'code in the "Script" field.
' + 'This can cause performance issues and unexpected behavior that can be very ' + 'difficult to troubleshoot, so it\'s recommended to remove any code in the "Script" ' + 'field if the "Advanced" checkbox is set to false.

', 'More info', 'Hide info' ); } } function getUncommentedLines(codeToCheck) { var uncommentedLines = []; var isMultilineComment = false; const lines = codeToCheck.split('\n'); lines.forEach(line => { if (isMultilineComment) { if (line.includes('*/')) { isMultilineComment = false; const remaining = line.split('*/')[1]; if (remaining.trim() !== '') { uncommentedLines.push(remaining); } } } else { if (!line.trim() || line.trim().startsWith('//')) { return; } if (line.trim().startsWith('/*')) { isMultilineComment = true; const remaining = line.split('/*')[0]; if (remaining.trim() !== '') { uncommentedLines.push(remaining); } return; } uncommentedLines.push(line); } }); return uncommentedLines; } /** * Display an expandable form message. This message will be shown at the top of whatever form * this code is executed on. The text in firstLine will be shown, but the text in flyoutText * will be hidden until the user clicks the 'expand' link. * * @param {String} firstLine - The first line of text in the message, which will be shown * immediately when this code executes. Unlike the text in flyoutText, this text will not * be hidden. * @param {String|HTML_TEXT} flyoutText - This text will be hidden by default, but will be shown * once the user clicks the 'expand' link (which you can customize by setting expandLinkText). * @param {String} [expandLinkText="Show more"] - Optionally specify the text to be shown as * a clickable link, which will cause the form message to expand and display the text * specified in flyoutText. * @param {String} [collapseLinkText="Hide details"] - Optionally specify the text to be shown * after the user clicks the 'expand' link text (specified in expandLinkText). * This text will be shown when the message is expanded and the text specified in flyoutText * is shown. Upon clicking this text, the message will be collapsed, flyoutText will be hidden, * and the link text will revert back to that specified in expandLinkText. * * @example * showExpandingFormMessage( * 'This message expands', * flyoutListHTML, * 'Show more', * 'Hide details' * ); */ function showExpandingFormMessage(firstLine, flyoutText, expandLinkText, collapseLinkText) { var formMsg = firstLine; expandLinkText = (typeof expandLinkText !== 'string') ? 'Show more' : expandLinkText; collapseLinkText = (typeof collapseLinkText !== 'string') ? 'Hide details' : collapseLinkText; formMsg += '
'; formMsg += '

' + expandLinkText + '

'; formMsg += '
'; formMsg += flyoutText; formMsg += '
'; formMsg += '
'; g_form.addErrorMessage(formMsg); } }