在插入新客户记录时,我有一段时间要设置perform_now
和defaultshipping
检查。我已经在下面添加了我的代码并尝试了几种不同的东西,但由于某种原因,插入的第一个地址设置了defaultbilling
和defaultshipping
,但第二个地址没有检查。
defaultbilling
在我尝试使用的地址对象的地址数组中:
define([ 'N/record', 'N/runtime' ],
function(record, runtime) {
function doPost(requestBody) {
var custRec = record.create({
type : record.Type.CUSTOMER,
isDynamic : true
});
var addresses = [
custBillAddr = {
addr1 : '2100 S. Blah St.',
addr2 : '',
addressee : 'Test Person',
city : 'Test Ville',
defaultbilling : true,
defaultshipping : false,
state : 'IA',
zip : '12345'
}, custShipAddr = {
addr1 : '5144 S. Test St.',
addr2 : '',
addressee : 'Tester Test',
city : 'Test City',
defaultbilling : false,
defaultshipping : true,
state : 'TX',
zip : '54321'
}];
var curScript = runtime.getCurrentScript();
var defEntity = curScript.getParameter({
name : 'custscript_default_entity_status'
});
var defSub = curScript.getParameter({
name : 'custscript_default_subsidary'
});
var custData = {
accountnumber : '112233',
companyname : 'Testing Company',
email : 'Testing@example.com',
entityid : '112233',
entitystatus : defEntity,
externalid : '123',
subsidiary : defSub,
};
for ( var key in custData) {
if (custData.hasOwnProperty(key)) {
custRec.setValue({
fieldId : key,
value : custData[key]
});
}
}
/* create address sub lists here */
custRec = upsertAddresses(custRec, addresses);
var recordId = custRec.save({
enableSourcing : false,
ignoreMandatoryFields : false
});
return JSON.stringify(recordId);
}
function upsertAddresses(custRec, addresses) {
for ( var address in addresses) {
custRec.selectNewLine({ sublistId : 'addressbook' });
var addList = custRec.getCurrentSublistSubrecord({ sublistId : 'addressbook', fieldId : 'addressbookaddress' });
for ( var key in addresses[address]) {
addList.setValue({ fieldId : key, value : addresses[address][key] });
}
custRec.commitLine({ sublistId : 'addressbook' });
}
return custRec;
}
return {
post : doPost,
};
});
但他们都没有设置该字段,我没有收到错误。希望有人在这里可以告诉我在设置这些字段时我做错了什么。
答案 0 :(得分:3)
我有一个非常类似的问题。事实证明,2.0中的地址簿需要子列表的子记录。下面的代码并不完全符合您的要求,但它可以帮助您完成所需的操作。在我的我得到的价值,你只需要设置它们。希望这会有所帮助。
define(['N/record','N/https','N/search'],function(record,https,search){
function sendContactData(context){
var contactNewRecord=context.newRecord;
if(context.type=='create' || contactNewRecord.getValue('nluser')=='1234'){return;}
var contactID=contactNewRecord.getValue('id');
var contactObjectRecord=record.load({type:record.Type.CONTACT,id:contactID,isDynamic:true,});
var shippingAddr1='';
var shippingCity='';
var shippingState='';
var shippingZip='';
var shippingCountry='';
var numLines=contactNewRecord.getLineCount({sublistId:'addressbook'});
if(numLines>0){
for(var addressCount=0;addressCount<numLines;addressCount++){
var addressShipping=contactNewRecord.getSublistValue({
sublistId:'addressbook',
fieldId:'defaultshipping',
line:addressCount
});
if(addressShipping==true){break;}
}
}
if(addressShipping==true){
//Select the line set as the default shipping:
contactObjectRecord.selectLine({sublistId:"addressbook",line:addressCount});
var shippingAddressSubrecord=contactObjectRecord.getCurrentSublistSubrecord({sublistId:"addressbook",fieldId:"addressbookaddress"}); //Access the addressbookaddress subrecord:
if(shippingAddressSubrecord){
shippingAddr1=shippingAddressSubrecord.getValue({fieldId:'addr1'});
shippingCity=shippingAddressSubrecord.getValue({fieldId:'city'});
shippingState=shippingAddressSubrecord.getValue({fieldId:'state'});
shippingZip=shippingAddressSubrecord.getValue({fieldId:'zip'});
shippingCountry=shippingAddressSubrecord.getValue({fieldId:'country'});
}
}
}; /* END sendContactData() */
return{
afterSubmit:sendContactData
} /* END return block */
}); /* END define(['N/record'],function(record) */