customization - Custom department-like structure in NetSuite -
there need create custom construction in netsuite. construction must closer possible existing section record type. standard classifications occupied, need more classifications.
i created custom record type 2 fields: name , parent. parent points record of same type. question how create nicely formatted name like: "parent_of_the_parent : the_parent : child". need specify parent names in record name. best way accomplish netsuite customization capabilities?
i previous solution suite resources if there 3 levels classifications.
if absolutely need many levels classifications (like departments or class), can create custom record (with inline editing disabled) , utilize script update of sub-classifications alter if edit classification.
for example, if create custom record id = 'customrecord_classification' , have fields (custrecord_classificationname [type=freeformtext], custrecord_classificationparent [type=listrecord] referring new custom record type, , custrecord_classificationfullname [type=freeformtext]), can use/modify next script wrote below. tested , works great, if want utilize error handling, logging, etc. should added.
function beforesubmit(type) { // create sure turn off inline editing on custom record type don't have handle xedit events // context record changed , run when alter made in ui var context = nlapigetcontext(); if (context.getexecutioncontext() == 'userinterface') { // if creating new classification record if (type == 'create' ) { // current record fields: internal id, custrecord_classificationname, custrecord_classificationparent var classificationid = nlapigetrecordid(); var classificationname = nlapigetfieldvalue('custrecord_classificationname'); var parentid = nlapigetfieldvalue('custrecord_classificationparent'); // check if classification has parent specified var hasparent = parentid.length == 0 ? false : true; var classificationfullname; // if classification has parent specified lookup parent's total name , append new classification name if (hasparent == true) { var parentfullname = nlapilookupfield('customrecord_classification', parentid, 'custrecord_classificationfullname'); classificationfullname = parentfullname + ' : ' + classificationname; } // if classification not have parent total name equal name else { classificationfullname = classificationname; } // set classification total name on current record nlapisetfieldvalue('custrecord_classificationfullname', classificationfullname); } // if editing existing classification record else if (type = 'edit') { var classificationid = nlapigetrecordid(); // recored before record edited grab old value total classification name var previousclassificationrecord = nlapigetoldrecord(); var oldclassificationfullname = previousclassificationrecord.getfieldvalue('custrecord_classificationfullname'); var classificationname = nlapigetfieldvalue('custrecord_classificationname'); var parentid = nlapigetfieldvalue('custrecord_classificationparent'); var hasparent = parentid.length == 0 ? false : true; var classificationfullname; if (hasparent == true) { var parentfullname = nlapilookupfield('customrecord_classification', parentid, 'custrecord_classificationfullname'); classificationfullname = parentfullname + ' : ' + classificationname; } else { classificationfullname = classificationname; } nlapisetfieldvalue('custrecord_classificationfullname', classificationfullname); var filters = new array(); var columns = new array(); // filter saved search classifications have total classification name origin old classification name filters[0] = new nlobjsearchfilter( 'custrecord_classificationfullname', null, 'startswith', oldclassificationfullname ); // create sure current record not 1 of records returned filters[1] = new nlobjsearchfilter( 'internalid', null, 'noneof', classificationid ); columns[0] = new nlobjsearchcolumn( 'custrecord_classificationfullname' ); var affectedclassifications = nlapisearchrecord( 'customrecord_classification', null, filters, columns ); // loop through of classifications need updated ( var = 0; affectedclassifications != null && < affectedclassifications.length; i++ ) { var subclassificationtofix = affectedclassifications[i]; var subclassificationtofixid = subclassificationtofix.getid(); // load sub-classification record fix, right it's value re-submit var subclassificationtofixrecord = nlapiloadrecord('customrecord_classification', subclassificationtofixid); var subclassificationtofixoldfullname = subclassificationtofixrecord.getfieldvalue('custrecord_classificationfullname'); var subclassificationtofixnewfullname = subclassificationtofixoldfullname.replace(oldclassificationfullname, classificationfullname); subclassificationtofixrecord.setfieldvalue('custrecord_classificationfullname', subclassificationtofixnewfullname); var id = nlapisubmitrecord(subclassificationtofixrecord, false); } } } }
customization netsuite
No comments:
Post a Comment