A sample code to Add a record of a Custom record type via WS using PHP
Note: This article requires existing knowledge of Web Services and PHP.
Sample code snippet in PHP:
require_once '../PHPtoolkit.php';
require_once 'login_info.php';
global $myNSclient;
# ADD A Record of a Custom Record type
# ===============
//create an array for the custom record type which will set the custom record ID, etc.
$recordTypeRef = array(
"internalId" => "6" // Record type's internal ID
);
$otherName = " Test - Name"; // Free-Form text
$location = "71"; // List/Record
// StringCustomFieldRef : Free-Form text field type
$customStringField = new nsComplexObject('StringCustomFieldRef');
$customStringField->setFields(array('internalId' => 'custrecord_other_name',
'value' => $otherName));
// SelectCustomFieldRef : List/Record field type
$customSelectField = new nsComplexObject('SelectCustomFieldRef');
$customSelectField->setFields(array('value' => new nsListOrRecordRef(array('internalId' => $location)), 'internalId' => 'custrecord_wlf_prod_pref_item'));
$customRecordFields = array(
"recType" => $recordTypeRef,
'customFieldList' => array($customStringField, $customSelectField)
);
// create Custom Record
$customRecord = new nsComplexObject('CustomRecord');
// set fields
$customRecord->setFields($customRecordFields);
// perform add operation and store nsWriteResponse object in $addResponse variable
$addResponse = $myNSclient->add($customRecord);
// handle add response
if ($addResponse->isSuccess) {
echo "<font color='green'><b>SUCCESSFULLY Added Custom Record!</b></font>";
} else {
echo "<font color='red'>" . $addResponse->statusDetail[0]->message . "</font>";
echo "</b></font>";
}
require_once 'login_info.php';
global $myNSclient;
# ADD A Record of a Custom Record type
# ===============
//create an array for the custom record type which will set the custom record ID, etc.
$recordTypeRef = array(
"internalId" => "6" // Record type's internal ID
);
$otherName = " Test - Name"; // Free-Form text
$location = "71"; // List/Record
// StringCustomFieldRef : Free-Form text field type
$customStringField = new nsComplexObject('StringCustomFieldRef');
$customStringField->setFields(array('internalId' => 'custrecord_other_name',
'value' => $otherName));
// SelectCustomFieldRef : List/Record field type
$customSelectField = new nsComplexObject('SelectCustomFieldRef');
$customSelectField->setFields(array('value' => new nsListOrRecordRef(array('internalId' => $location)), 'internalId' => 'custrecord_wlf_prod_pref_item'));
$customRecordFields = array(
"recType" => $recordTypeRef,
'customFieldList' => array($customStringField, $customSelectField)
);
// create Custom Record
$customRecord = new nsComplexObject('CustomRecord');
// set fields
$customRecord->setFields($customRecordFields);
// perform add operation and store nsWriteResponse object in $addResponse variable
$addResponse = $myNSclient->add($customRecord);
// handle add response
if ($addResponse->isSuccess) {
echo "<font color='green'><b>SUCCESSFULLY Added Custom Record!</b></font>";
} else {
echo "<font color='red'>" . $addResponse->statusDetail[0]->message . "</font>";
echo "</b></font>";
}
Equivalent SOAP request:
No comments:
Post a Comment