I'm editing this function on a scheduled script. T...
# suitescript
j
I'm editing this function on a scheduled script. This was written by a previous developer and it worked in a sandbox environment but when deploying to production the
custentity93
is not setting the value for Sales 2021. Any ideas? I've checked the Field Ids, Saved search that this is dependent on and nothing
Copy code
function processNextCustomer(customer) {
	try{
		var context = nlapiGetContext();

		var usage = context.getRemainingUsage();

		var customerId = customer.getValue('internalid','customer','GROUP');

		var allColumns = customer.getAllColumns();

		var currentTotal = customer.getValue(allColumns[2]);

		var salesTotal = customer.getValue(allColumns[3]);

		if (currentTotal != salesTotal) {

			// Current total is different - Update all of the customer sales order fields
			var customerUpdate = nlapiLoadRecord('customer',customerId);

			var sales2021 = customer.getValue(allColumns[4])
			var sales2020 = customer.getValue(allColumns[5]);
			var sales2019 = customer.getValue(allColumns[6]);
			var sales2018 = customer.getValue(allColumns[7]);
			var sales2017 = customer.getValue(allColumns[8]);
			var salesPre2017 = customer.getValue(allColumns[9]);

			customerUpdate.setFieldValue('custentity_tdg_totalsales', salesTotal);
			customerUpdate.setFieldValue('custentity28', sales2017);
			customerUpdate.setFieldValue('custentity29', sales2018);
			customerUpdate.setFieldValue('custentity30', sales2019);
			customerUpdate.setFieldValue('custentity32', sales2020);
			customerUpdate.setFieldValue('custentity93', sales2021);
			customerUpdate.setFieldValue('custentity33', salesPre2017);
			nlapiSubmitRecord(customerUpdate, true);
		}




		return true;

	}
	catch(e) {
		var errorMessage = e;
		nlapiLogExecution('ERROR', 'e', e);
	}

}
s
How did you get it to production, manually or bundle/copy/etc?
j
@Sandii pushed from webstorm
also tried to copy and paste directly into NetSuite
s
Ah I was wondering if it was one of those where the id already existed in prod and NS appended a 2 on the end and changed the file without letting you know
j
yeah that sounds like something Netsuite would do
I've checked again and again and compared everything between SB and Prod and still not setting values. As mentioned, it worked fine in sandbox and even the Field id is exactly the same in both envs
s
I mean theres a chance
getAllColumns()
has different columns/order in sandbox vs prod?
j
yeah I checked that as well and changed it when I added my 2021 column
Initially this was `
Copy code
var sales2020 = customer.getValue(allColumns[4]);
			var sales2019 = customer.getValue(allColumns[5]);
			var sales2018 = customer.getValue(allColumns[6]);
			var sales2017 = customer.getValue(allColumns[7]);
			var salesPre2017 = customer.getValue(allColumns[8]);
`
s
1. did you try catch to see if the script stopped executing? 2) and or did you log sales2021? 3) does cusentity93 have field sourcing or defaults? 4) is the value from the variable sales2021 available on the UI when you update the customer record via the ui? just giving ideas to things to look ^_^
j
@Sciuridae54696d thanks! checked 2, 3 and 4. Haven't checked on 1
s
ends up custentity93 is a list/record and you should have done set text for it to work or some randomer like the search was text and you needed to set text
I kid but once you check the field i'm sure you would have picked that up too hahahaha
b
probably want to check how you can set the field in your production account
that will probably consist of a simple test script that loads the customer, sets the custentity93 field, and then saves the record
once you get that working, compare the value you get from sales2021 to the value in your test script
j
Thank you!