Hi Guys, I have custom netsuite external form and ...
# suitescript
m
Hi Guys, I have custom netsuite external form and I have uniprice and quantity field on that when I add custom code into this form some how field change event is not triggering. Please have a look at below image
b
share the code
make sure your script falls under the restrictions on Working with Online Forms
m
Copy code
/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 */
// In SuiteScript 2.0   
define(['N/search', 'N/currentRecord'], function(search, currentRecord) {
    return {
        pageInit: function(context) {			
            var currentRecord = context.currentRecord;            
        },
		fieldChanged: function(context){
			
			try
			{
				var currentrecord = context.currentrecord;				
				if(context.fieldid == 'custrecordunitprice1' | context.fieldid == 'custrecordquantity1'){						
					var unitprice = currentrecord.getvalue({
						fieldid: 'custrecordunitprice1'
					});	
					var quantity = currentrecord.getvalue({
						fieldid: 'custrecordquantity1'
					});	
					var amount = (unitprice || 0 ) * ( quantity || 0 );
					currentrecord.setvalue({
						fieldid: 'custrecordpola1',
						value: amount
					});
				}
			}
			catch(err)
			{
				console.log('');
			}
		}		
    };		
});
b
you probably want to use better tooling
Copy code
context.currentrecord;
Copy code
if(context.fieldid == 'custrecordunitprice1' | context.fieldid == 'custrecordquantity1'){
Copy code
var unitprice = currentrecord.getvalue({
Copy code
var quantity = currentrecord.getvalue({
Copy code
currentrecord.setvalue({
almost every line you have has a typo
get very used to using camel case or snake case
its the standard, and code that doesnt use it looks bad
m
actually, notepad get this messed but actual code has the camelcase
Do you think i can catch field change event externally?
b
you are going to need to get better at copy and paste if you want your code review to be useful
m
Copy code
var currentRecord = context.currentRecord;				
				if(context.fieldId == 'custrecordunitprice1' | context.fieldId == 'custrecordquantity1'){						
					var unitprice = currentRecord.getValue({
						fieldId: 'custrecordunitprice1'
					});	
					var quantity = currentRecord.getValue({
						fieldId: 'custrecordquantity1'
					});	
					var amount = (unitprice || 0 ) * ( quantity || 0 );
					currentRecord.setValue({
						fieldId: 'custrecordpola1',
						value: amount
					});
b
| vs ||
m
ok i will use visual studio
b
something that eslint would warn you about
m
do you think this code should work on external forms/online forms?
b
fieldChanged works on external forms
m
saveRecord event is working too?
b
you should be worried if netsuite allows it as an option and it doesnt work
m
external form is accessible without login do you think I need to change something ?
b
you can probably just make an empty script that logs when the entry point is entered
if it logs something, the entry point is fine and your code is wrong
m
OK, That's good idea @battk, Once again thanks for your help.
@battk It's working fine, there were issue i resoved. Thanks for your time