NetSuite中如何使用脚本查看某个客户的历史信息?
How can check history information for a certain customer by using scripting in NetSuite?
我想在 NetSuite 中创建一个脚本,它需要来自客户的一些历史信息。事实上,我需要的信息是了解用户是否购买了商品。
为此,我需要以某种方式访问该客户的历史记录。
巴勃罗.
您可以对 invoices
使用已保存的搜索 nlapiLoadSearch
或 nlapiCreateSearch
,按客户筛选,还可以报告发票项目(或仅报告特定项目)。使用 nlapiCreateSearch
可能很难使用,所以我建议使用 UI 构建保存的搜索,然后使用 nlapiLoadSeach(type, id)
加载它
这将为您提供一组 invoices/customers 购买了您的商品。
尝试包含此函数并传递客户的内部 ID 和项目内部 ID
function hasPurchasedBefore(customerInternalID, itemInternalID){
var results = [];
var filters = [];
var columns = [];
filters.push(new nlobjSearchFilter('internalidnumber', 'customermain', 'equalto', [customerInternalID]))
filters.push(new nlobjSearchFilter('anylineitem', null, 'anyof', [itemInternalID]));
filters.push(new nlobjSearchFilter('type', null, 'anyof', ['CustInvc']));
columns.push(new nlobjSearchColumn('internalid', null, 'GROUP'));
results = nlapiSearchRecord('transaction', null, filters, columns);
if (results && results.length){
return true;
}
return false;
}
示例:
var record = nlapiLoadRecord(nlapiGetRecordType(),nlapiGetRecordId());
var customerInternalID = record.getFieldValue('entity');
var itemInternalID = record.getLineItemValue('item', 'item', 1); //Gets line 1 item Internal ID
if( hasPurchasedBefore(customerInternalID, itemInternalID) ) {
//Has bought something before
}
我想在 NetSuite 中创建一个脚本,它需要来自客户的一些历史信息。事实上,我需要的信息是了解用户是否购买了商品。 为此,我需要以某种方式访问该客户的历史记录。
巴勃罗.
您可以对 invoices
使用已保存的搜索 nlapiLoadSearch
或 nlapiCreateSearch
,按客户筛选,还可以报告发票项目(或仅报告特定项目)。使用 nlapiCreateSearch
可能很难使用,所以我建议使用 UI 构建保存的搜索,然后使用 nlapiLoadSeach(type, id)
这将为您提供一组 invoices/customers 购买了您的商品。
尝试包含此函数并传递客户的内部 ID 和项目内部 ID
function hasPurchasedBefore(customerInternalID, itemInternalID){
var results = [];
var filters = [];
var columns = [];
filters.push(new nlobjSearchFilter('internalidnumber', 'customermain', 'equalto', [customerInternalID]))
filters.push(new nlobjSearchFilter('anylineitem', null, 'anyof', [itemInternalID]));
filters.push(new nlobjSearchFilter('type', null, 'anyof', ['CustInvc']));
columns.push(new nlobjSearchColumn('internalid', null, 'GROUP'));
results = nlapiSearchRecord('transaction', null, filters, columns);
if (results && results.length){
return true;
}
return false;
}
示例:
var record = nlapiLoadRecord(nlapiGetRecordType(),nlapiGetRecordId());
var customerInternalID = record.getFieldValue('entity');
var itemInternalID = record.getLineItemValue('item', 'item', 1); //Gets line 1 item Internal ID
if( hasPurchasedBefore(customerInternalID, itemInternalID) ) {
//Has bought something before
}