RUNNING CLIENT SCRIPT IN VIEW MODE

In order to run clientscript in view mode you need to modify the form on BeforeLoad using a UserEvent script and attach a Clientscript file to the form using the clientScriptFieldId function.

Suitescript 2.0 InlineHTML Hack:

If you need to run your code without having to click a button you can try the the following code. This code injects a script into the form to hack the DOM. In other words, it’s a hack.

/**
 *@NApiVersion 2.x
 *@NModuleScope Public
 *@NScriptType UserEventScript
 */
define([], runUserEvent);
 
function runUserEvent() {
	var returnObj = {};
	returnObj.beforeLoad = beforeLoad;
	return returnObj;
}
 
function beforeLoad(scriptContext) {
    if (scriptContext.type == scriptContext.UserEventType.VIEW) {
		var field = scriptContext.form.addField({
			id: 'custpageinjectcode',
			type: 'INLINEHTML',
			label: 'Inject Code'
		});
		
		field.defaultValue = "<script>alert('Hello')</script>"; //This is where you would type your script
    }
}

Leave a comment

Your email address will not be published. Required fields are marked *