问题
Getting this error Invalid custrecord_lt_partner reference key 225399. While trying to insert into
The first two fields are lists/records & the third field is free form text.
Netsuite with Admin rights
Here is the code
global $nsClient;
$recordTypeRef = array("internalId" => 91);
$partnerName = "225399";
$companyName = "20562";
$labAcctNum = "7182794";
$partnerNameFields = new nsComplexObject('SelectCustomFieldRef');
$partnerNameFields->setFields(
array(
'value' => new nsListOrRecordRef(array('internalId' => $partnerName)),
'internalId' => 'custrecord_lt_partner'
)
);
$companyNameFields = new nsComplexObject('SelectCustomFieldRef');
$companyNameFields->setFields(
array(
'value' => new nsListOrRecordRef(array('internalId' => $companyName)),
'internalId' => 'custrecord_lt_company'
)
);
$labAcctNumFields = new nsComplexObject('StringCustomFieldRef');
$labAcctNumFields->setFields(
array(
'internalId' => 'custrecord_lt_user_lab_acct_number',
'value' => $labAcctNum,
)
);
$customRecordFields = array(
"recType" => $recordTypeRef,
"customFieldList" => array($partnerNameFields, $companyNameFields, $labAcctNumFields),
);
$customRecord = new nsComplexObject('CustomRecord');
$customRecord->setFields($customRecordFields);
//echo "<pre>"; print_r($customRecord); echo "</pre>"; exit;
$addResponse = $nsClient->add($customRecord);
if($addResponse->isSuccess) {
echo "<pre>"; print_r("Success"); echo "</pre>"; exit;
}
else {
echo "<pre>"; print_r($addResponse->statusDetail[0]->message); echo "</pre>"; exit;
}
回答1:
I get this error when the internalID specified does not exist. So I assume that the value of $partnerId is "225399". Did you double check in Netsuite that an entry with that ID exists? (The URL or the System Tab usually tells you more. Alongside SelectFields there's usually also a Javascript array where you can find the IDs).
回答2:
Is $partnerName the entityId field from the partner record, or the internalId field?
You need to supply either an internalId or externalId. Your use of the word "name" within your variable makes me think you are not using internal or external Id.
来源:https://stackoverflow.com/questions/13256994/netsuite-error-invalid-key-or-ref