需要在NetSuite中创建自定义结构。结构必须尽可能接近现有的Department记录类型。所有标准分类都被占用,我们需要更多的分类。
我创建了一个包含两个字段的自定义记录类型:name和parent。父指向相同类型的记录。问题是如何创建格式良好的名称,如: “Parent_of_the_parent:the_parent:child”。我们需要在记录名中指定所有父名称。使用NetSuite自定义功能实现此目标的最佳方法是什么?
答案 0 :(得分:1)
如果分类只有3个级别,我喜欢套件资源的先前解决方案。
如果绝对需要您的分类的多个级别(,如部门或类),您可以创建自定义记录(禁用内联编辑)并使用脚本更新编辑分类时更改的所有子分类。
例如,如果您使用ID =' customrecord_classification'创建自定义记录?并且您有字段(custrecord_classificationname [type = FreeFormText],custrecord_classificationparent [type = ListRecord]引用新的自定义记录类型,以及custrecord_classificationfullname [type = FreeFormText]),然后您可以使用/修改我在下面为您编写的以下脚本。我测试了它并且效果很好,但是如果你想使用它,应该添加一些错误处理,日志记录等。
function beforeSubmit(type) {
// Make sure you turn off inline editing on the custom record type so we don't have to handle xedit events
// Get the context the record was changed and only run when the change was made in the UI
var context = nlapiGetContext();
if (context.getExecutionContext() == 'userinterface') {
// If creating a new classification record
if (type == 'create' ) {
// Get the current record fields: internal ID, custrecord_classificationname, custrecord_classificationparent
var classificationID = nlapiGetRecordId();
var classificationName = nlapiGetFieldValue('custrecord_classificationname');
var parentID = nlapiGetFieldValue('custrecord_classificationparent');
// Check if the classification has a parent specified
var hasParent = parentID.length == 0 ? false : true;
var classificationFullName;
// If the classification has a parent specified lookup the parent's full name and append the new classification name to it
if (hasParent == true) {
var parentFullName = nlapiLookupField('customrecord_classification', parentID, 'custrecord_classificationfullname');
classificationFullName = parentFullName + ' : ' + classificationName;
}
// If the classification does not have a parent then the full name is equal to the name
else {
classificationFullName = classificationName;
}
// set the classification full name on the current record
nlapiSetFieldValue('custrecord_classificationfullname', classificationFullName);
}
// If editing an existing classification record
else if (type = 'edit') {
var classificationID = nlapiGetRecordId();
// get the recored before the record was edited to grab the old value for the full 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 for a saved search for all classifications that have a full classification name beginning with the old classification name
filters[0] = new nlobjSearchFilter( 'custrecord_classificationfullname', null, 'startswith', oldClassificationFullName );
// Make sure the current record is not one of the 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 all of the classifications that need to be updated
for ( var i = 0; affectedClassifications != null && i < affectedClassifications.length; i++ ) {
var subClassificationToFix = affectedClassifications[i];
var subClassificationToFixID = subClassificationToFix.getId();
// load the sub-classification record to fix, correct it's value then re-submit it
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);
}
}
}
}
答案 1 :(得分:0)
您可能需要一个名称(带有父级的全名),父级和名称(无层次结构)。
然后您可以填写姓名(无层次结构)值(例如袜子),指定父级(例如服装)。
然后,您可以通过加载父记录并连接名称(无层次结构)值来填充全名字段。
我不确定这是否有意义,但如果您在Netsuite中注意到,他们也会使用该名称和名称(无层次结构)的结构,如果您创建项目保存搜索作为示例,则可以看到你应该看到这两个结果都可用。
答案 2 :(得分:0)
只有3级深度?还是更多?
如果为3,则在引用祖父母的父级上创建一个字段(取消选中存储值,使用“源和过滤”选项卡)。
在孩子身上,你可以做同样的事情 - 引用父母和祖父母的引用。