Hi Everyone,
I've used this forum so far mainly to learn from others so I figured it was time I gave back a little. Our previous ERP software had a field on the Customer record that held the Last Sale Date of a customer. It made a lot of things in reporting very easy and convenient. I missed it in NetSuite so I came up with this method to add that functionality. Hopefully someone will find it as useful as I do. Hopefully, NetSuite will just add this functionality so my code isn't even necessary.
Create a custom entity field with the id of custentity_lastsaledate.
Create a script for Sales Orders that has an afterSubmit function.
Place this code in the afterSubmit function.
var d = new Date();
var m = (d.getMonth())+1
var dd = d.getDate();
var y = d.getFullYear();
var now = m+'/'+dd+'/'+y;
var newId = nlapiGetRecordId();
var newType = nlapiGetRecordType();
var record = nlapiLoadRecord(newType,newId);
var customerid = record.getFieldValue('entity');
var record = nlapiLoadRecord('customer',customerid);
record.setFieldValue('custentity_lastsaledate', now);
var id = nlapiSubmitRecord(record, true);
I'm not an expert programmer so there may be a more elegant way of doing this. Please feel free to post any ideas or improvements to my humble code.
And, as always, your mileage may vary.