thanks for your help. I am running into an unexpe...
# suitescript
p
thanks for your help. I am running into an unexpected error when trying to save the item. What am I doing wrong? var firstcomitem = record.create({ type: record.Type.NON_INVENTORY_ITEM, isDynamic: true }); log.debug({details:"firstcomitem = " + firstcomitem}); firstcomitem.setValue({ fieldId: 'subtype', value: 'Sale' }); firstcomitem.setValue({ fieldId: 'itemid', value: nameforkit }); firstcomitem.setValue({ fieldId: 'taxschedule', value: '3' }); log.debug({details:"gothere"}); var id = firstcomitem.save(); log.debug({details:"intidcomp = " + intidcomp});
r
if you remove the setting of the subtype, does the error go away?
p
I now get the error java.lang.IllegalAccessError: class nlobjError (in unnamed module @0x15405bd6) cannot access class com.oracle.truffle.api.TruffleException (in module org.graalvm.truffle) because module org.graalvm.truffle does not export com.oracle.truffle.api to unnamed module @0x15405bd6
b
thats very weird looking
id make sure you are using suitescript 2.0
p
I have /** * @NApiVersion 2.x * @NScriptType UserEventScript */
b
there may or not be a difference between 2.0 and 2.x
p
I did. I still get the error. I have attached a copy of the script.
it looks like it is the save that is causing an issue. the purpose of the script is to autogenerate our kit items based upon data from a custom record
b
id toss the parameters to save, you occasionally get better errors
p
what do you mean?
b
Copy code
var idnew = InvItem.save({enableSourcing: true,
            ignoreMandatoryFields: true
            });
remove the parameters to the save function
p
got it
I still get java.lang.IllegalAccessError: class nlobjError (in unnamed module @0x15405bd6) cannot access class com.oracle.truffle.api.TruffleException (in module org.graalvm.truffle) because module org.graalvm.truffle does not export com.oracle.truffle.api to unnamed module @0x15405bd6
b
thats honestly a weird error that i would only expect from a 2.1 script
s
I like truffles
😂 1
e
I suspect there is smth related to some value which is not acceptable, or some field which might be required and is not set...(properly). There is this SuiteAswers article and you have a code example there - try to just put that piece in your script, just to see if it saves the record: https://netsuite.custhelp.com/app/answers/detail/a_id/90525/kw/non%20inventory%20item
Copy code
var rec = record.create({
		type: record.Type.NON_INVENTORY_ITEM,
		isDynamic: true
	})
		rec.setValue({
			fieldId: 'subtype',
			value: 'Resale'
		})
		rec.setValue({
			fieldId: 'itemid',
			value: 'Script - Non Inventory Item for Resale'
		})
		rec.setValue({
			fieldId: 'cost',
			value: '1.0'
		})
		rec.selectLine({
			sublistId: 'price1',
			line: 0
		})
		rec.setCurrentSublistValue({
			sublistId: 'price1',
			fieldId: 'currency',
			value: 1
		})
		rec.setCurrentSublistValue({
			sublistId: 'price1',
			fieldId: 'price_1_',
			value: '1.0'
		})
		rec.commitLine({
			sublistId:'price1'
		})
	var id = rec.save()
p
I still get an unexpected error
b
probably should get started on the netsuite support case
p
ok. I will do that
b
be sure to give them a simplified version of the script to work with
similar to the code you first shared
p
thanks.
b
while you are waiting for a response, you can try general debugging steps like not using dynamic mode
i would remove any code that tried setting the pricing matrix like in the suiteanswer article that was shared
that code is feature specific
e
...only 1 more idea: • you said you get the error when you save; • did you check if don't have some other customization, done on Saving the record...somewhere(on some entry point), deployed on the item-record, which kicks in and throws the error...for some reason?(could be script, could be wf...)
if such customization throws an error, then your record cannot be created/saved...and the error is not explicitly passed to your script context...
b
id be surprised if that happened for a user event script
e
well, you may be surprised, but I saw this kind of behavior before 🙂
p
I am checking to see if there are any other scripts
e
"unexpected error" is usually thrown, when there is some other error...which is not handled properly(take for example the cases when there is an error in rendering a record to a pdf/template - the error in the rendering process is thrown in the script as "unexpected error")
p
I don't see any scripts or workflows that are custom made.
e
so, in scriptedrecords, for the "Non-Inventory Part"-record, there is no UE-script nor WF...right?
p
correct
its all avalara
b
undeploy everything Scripted Record, custom or not
e
ohh...Avalara is not native... 😉
yeah, undeploy evrything and then try to save
p
ok
I undeployed everything and I still get the same error
it looks like its a defect
e
I took the code from the SuiteAnswers and put it in a short UE-script, on afterSubmit, and I deployed it on Employee-record(can be any record), to create the new NON-INV-ITEM, when the Employee is Updated/Saved. It worked without any error.
p
NetSuite support confirmed the error is a defect
e
I still believe there is smth that kicks in, when that runs and throws an error - that error. This error you get, is not generated by your script...but it thrown by your script, eventually...
ok
p
did you try running it against a custom record after submit?
e
but then I'm wondering why it worked...like when I just tried 🤔
ok, I'll do that, also
p
does it usually throw an invalid field value error with a script? I have gotten those before
e
yup. I deployed it on a different record, a custom record - the script creates the NON-INV-ITEM, on afterSubmit of the custom record, when the custom record is edited and saved
so again, the NON-INV-ITEM gets created w/o any issue/error
p
argh
e
mmm...one more question, in the deployment...do you run it as "Administrator"? (or "current user")?
...try with "Administrator"(cause if current user is...different than Admin, might be a matter of permissions, on the Item~ records...)
also, try to save like this:
intNewRecId = rec.save({enableSourcing: false, ignoreMandatoryFields: true});
p
its running as admin
e
anyway, so this is my script (sorry for the mess...I took it from somewhere else and modified it a bit 😉 ) - save it in your account as UE-script, then deploy it on some record, as admin, then update that record and on save, the new NON-INV-ITEM shall be created:
message has been deleted
Copy code
/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 * @NModuleScope SameAccount
 */


define([
        'N/record', 
        'N/error',
        'N/log',
		'N/runtime',
		'N/email'
        ],
/**
 * @param {record} record
 * @param {error} error
 * @param {log} log
 * @param {runtime} runtime
 * @param {email} email
 */

function(record, error, log, runtime, email) {
	
	// GLOBAL variables
	var DEBUG = true;
	var currentScript = runtime.getCurrentScript();
	var stExecutionContext = runtime.executionContext; // runtime.ContextType.USER_INTERFACE = 'USERINTERFACE'
	var objCurrentUser = runtime.getCurrentUser();
	var stAuthor = objCurrentUser.id;//currentScript.getParameter('custscript_email_author_ue');
	
	
	/**
     * <code>afterSubmit</code> event handler. See
     * [NetSuite Help: afterSubmit(scriptContext)]{@link <https://system.na1.netsuite.com/app/help/helpcenter.nl?fid=section_4407992281.html>}
     * for details.
     *
     * @governance XXX
     *
     * @param context
     *        {Object}
     *
     * @param context.newRecord
     *        {record} The new record being submitted. See
     *            [NetSuite Help: record.Record]{@link <https://system.na1.netsuite.com/app/help/helpcenter.nl?fid=section_4205869719.html>}
     * @param context.oldRecord
     *        {record} The old record before it was modified. See
     *            [NetSuite Help: record.Record]{@link <https://system.na1.netsuite.com/app/help/helpcenter.nl?fid=section_4205869719.html>}
     * @param context.type
     *        {UserEventType} The action type that triggered this event. See
     *            [NetSuite Help: context.UserEventType]{@link <https://system.na1.netsuite.com/app/help/helpcenter.nl?fid=section_4407992596.html>}
     *
     * @return {void}
     *
     * @static
     * @function afterSubmit
     *
     * @see [NetSuite Help: afterSubmit(scriptContext)]{@link <https://system.na1.netsuite.com/app/help/helpcenter.nl?fid=section_4407992281.html>}
     * @see [NetSuite Help: context.UserEventType]{@link <https://system.na1.netsuite.com/app/help/helpcenter.nl?fid=section_4407992596.html>}
     * @see [NetSuite Help: record.Record]{@link <https://system.na1.netsuite.com/app/help/helpcenter.nl?fid=section_4205869719.html>}
     */
	function afterSubmit(scriptContext) /// !!! DOES NOT EXECUTE WHEN SYSTEM GENERATES DROP-SHIP ORDERS !!!
    {
		var TITLE = 'afterSubmit_transaction'; // function name
		try
		{
			logMessage('DEBUG', TITLE+' #0', '--> Script START <--');
			
			var stExecutionType = scriptContext.type; // scriptContext.UserEventType.CREATE = 'create'
			logMessage('DEBUG', TITLE+' #GLOBAL', ' --> stExecutionContext='+stExecutionContext+' | stExecutionType='+stExecutionType
			+' | objCurrentUser='+objCurrentUser);
			
			// Script 
			if ((stExecutionType != scriptContext.UserEventType.DELETE)) // script will not execute on DELETE 
			{
				var objCurrRecord_context = scriptContext.newRecord;
				var objOldRecord_context = (stExecutionType != scriptContext.UserEventType.CREATE)?scriptContext.oldRecord:undefined;
				var intNewRecId = -1;
				
				var rec = record.create({
					type: record.Type.NON_INVENTORY_ITEM,
					isDynamic: true
				})
					rec.setValue({
						fieldId: 'subtype',
						value: 'Resale'
					})
					rec.setValue({
						fieldId: 'itemid',
						value: 'Script - Non Inventory Item for Resale'
					})
					rec.setValue({
						fieldId: 'cost',
						value: '1.0'
					})
					rec.selectLine({
						sublistId: 'price1',
						line: 0
					})
					rec.setCurrentSublistValue({
						sublistId: 'price1',
						fieldId: 'currency',
						value: 1
					})
					rec.setCurrentSublistValue({
						sublistId: 'price1',
						fieldId: 'price_1_',
						value: '1.0'
					})
					rec.commitLine({
						sublistId:'price1'
					})
				intNewRecId = rec.save({enableSourcing: false, ignoreMandatoryFields: true});
				
				logMessage('DEBUG', TITLE, ' --> intNewRecId='+intNewRecId);
				
							
			} // script will not execute on DELETE -> scriptContext.UserEventType.DELETE
			
        }
        catch (error) 
        {
            logMessage('ERROR', 'Script Error', error.toString());
			sendEmailOnError(error.toString(), TITLE, stAuthor);
            throw error;
        } 
    }
	// END afterSubmit
	
	
	/******* UTIL - functions ****
	******************************
	*****************************/
	function logMessage(logType, title, details)
	{
		if(DEBUG)
		{
			log.debug({
				title: logType+' | '+title, 
				details: details
				});
		}
		if ((logType == 'AUDIT') && (!DEBUG)) {
			log.audit({
				title: logType+' | '+title, 
				details: details
				});
		}
		if ((logType == 'ERROR') && (!DEBUG)) {
			log.error({
				title: logType+' | '+title, 
				details: details
				});
		}
	}
	
	function sendEmailOnError(errorMsg, TITLE, stAuthor){
		if ( errorMsg.length > 0 )
		{
			var e = error.create(
			{
				name: TITLE+'_FAILED',
				message: JSON.stringify( errorMsg )
			} );
				
			//var recipients = '<mailto:eraceanu@netsuite.com|eraceanu@netsuite.com>';
			var subject = 'UserEvent script ' + runtime.getCurrentScript().id + ' failed during execution. ';
			var body = 'An error occurred with the following information:\n' + 'Error code: ' + e.name + '\n' + 'Error msg: ' + e.message;
			email.send(
			{
				author: stAuthor,
				recipients: stAuthor,
				subject: subject,
				body: body
			} );
		}
	}

    return {
		afterSubmit: afterSubmit
    };
    
});
p
thanks
👍 1
I get an unexpected error with your script too. must be something additional in our environment
b
there is some spooky stuff going on with user event scripts on non inventory items
not only was it being triggered by other user event scripts, it was using an old version of the script while doing so
e
...so you mean, the issue/error was thrown by some other UE-script(deployed on the non inventory item record)?
b
same user event script
i have a testing user event script that i usually keep deployed to sales orders, and deployed it to non inventory items to test the issue
made the user event script create a non inventory item
triggering the sales order created the non inventory item successfully, and somehow also triggered the script deployed to non inventory items
e
...not sure I follow: the issue was with a UE-script...deployed on some record(not the "non inventory item"-record), which was supposed to create a non inventory item
b
thats the user event script deployed to sales orders that creates non inventory items
e
...mmm, there is smth else, on the non inventory item, which is triggered and runs "not as UE-script", every time a non inventory item is created(or edited?), which does smth to that non inventory item record...and the execution context is not "UE-script". what I mean here, is that any serverside script, other than UE, can trigger a UE-script...
what you say, actually proves there is smth ...which triggers when you create the non inventory item record and does smth...
b
for me, that was the same user event script deployed to non inventory items
e
aaa, ok, now I got it...I see your case...yeah, that is...strange, but then again, such particular scenario(as what you described) is not a real life scenario... I don't think Phillip had this case(just happened to you, cause...you were testing...)
b
the extra spooky part was that i changed the script to create a custom record (which also has the same user event deployed to it) instead of the non inventory item
the user event script deployed to the custom record did the normal thing and didnt trigger off the sales order deployment
but the non inventory deployment decided to be scary and triggered using the old version of the script. I could tell from the names of the item being created
e
btw, sometimes, the UI gets cached in the browser...and pages, including the ones where you update the script...deploy and so on...don't show or submit correct...
b
the sales order deployment is doing normal stuff and uses the current version of the file
e
so sometimes, it might be that...what really happens(what you do in the browser)...might not really be what gets submitted. when I notice smth like this, I try to do things from a different browser
anyway, like if you try to get the same weird behavior now...is it reproducible?
b
it was weird enough that i deleted all my deployments
and tried reproducing it
still cant change the old code that is running
which is very unfortunate since it was beforeLoad