I am attaching client script to Nestuite iframe suitelet to hide div element.
Here's the strange part:
1.If I inspect the element in the browser's developer tools and then execute document.getElementById('abc') in the console, it returns null.
2. But, if I copy the JSON path of the element in the developer tools and then execute document.getElementById('abc') in the console, it correctly returns the element.
Below in Netsuite client script:
//Client Script
function pageInit(scriptContext) {
document.getElementById("uif37");
}
//i_frame suitelet
if (context.request.method === 'GET') {
var form = serverWidget.createForm({title: 'Monitoring System', hideNavBar: true});
// Construct URLs for child Suitelets
var fisrtiframeUrl = buildIframeUrl('scriptid', 'deployid');
var secondiframeUrl = buildIframeUrl('scriptid', 'deployid);
var fisrtiFrameHtml = "<iframe src='" + fisrtiframeUrl + "' id='view' width='50%' height='700px' scrolling='auto' name='firstframeView' marginheight='0' marginwidth='0' frameborder='0'></iframe>";
var secondiFrameHtml = "<iframe src='" + secondiframeUrl + "' id='view' width='50%' height='700px' scrolling='auto' name='secondframeView' marginheight='0' marginwidth='0' frameborder='0'></iframe>";
var combinedHtml = fisrtiFrameHtml + secondiFrameHtml;
var htmlField = form.addField({
id: 'custpage_my_iframe',
type: serverWidget.FieldType.INLINEHTML,
label: 'Performance iFrame'
});
htmlField.defaultValue = combinedHtml;
form.clientScriptModulePath = 'SuiteScripts/cs_hide_div.js';
form.addResetButton({label: 'Cancel'});
context.response.writePage(form);
}
}
.getElementById()function will only find the element if it is actually part of the page when your script runs.