[Add Button] [UserEvent call clientscript] Aim: A...
# suitescript
d
[Add Button] [UserEvent call clientscript] Aim: Add button on existing form Opportunity (view mode) and button call a function. UserEventScript:
Copy code
/**
 *@NApiVersion 2.x
 *@NScriptType UserEventScript
 */
define([],

    function() {
		
		function _beforeLoad(context){			
			if(context.type === context.UserEventType.VIEW){			
				var form = context.form;				
				form.clientScriptFileId = 2514;	//line responsible for error		
				form.addButton({				
					id: 'custpage_modifyStatus',
					label: 'Identify',
					functionName: 'customFunc'					
				});			
			}		
		}

		return {			
			beforeLoad :_beforeLoad		
		};		
});
ClientScript:
Copy code
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
*/
define([],

	function() {

		function pageInit(context) {}	
		function customFunc(){			
			alert("hey hey");	
		}
		
	return {
		pageInit: pageInit,
		customFunc: customFunc
	};
});
Error: _,"cause":{"message":"missing ; before statement","fileName":"","lineNumber":1,"name":"InternalError","stack":"\tat /SuiteScripts/BW_userEvent_AddStatusButton.js:15 (_beforeLoad)\n\tat INVOCATION_WRAPPER$sys:26\n\tat INVOCATION_WRAPPER$sys:17\n\tat INVOCATION_WRAPPER$sys:34\n\tat INVOCATION_WRAPPER$sys:1\n","rhinoException":"org.mozilla.javascript.EvaluatorException: missing ; before statement"},"notifyOff":false,"userFacing":true}_ What am i doing wrong ? help please !
a
The JS error suggests your syntax is wrong somewhere, though I’m not seeing it at a cursory glance. Regarding your problem though: You can try using
form.clientScriptModulePath = "RELATIVE_PATH_TO_CLIENT_SCRIPT";
instead of client script file id.
d
@Alex Hirota seems to work. woww... Its weird that it doesnt work with the internalId. Thanks again. 😊
a
@Damree Ilyaad cheers mate. Glad to help.