Tutorial | PHP ‘Contact Us’ external form to Netsuite custom record
- Create a custom record. Setup > Customization > Record Types > New
- Create three custom fields for the created “Contact Us” custom record.
- For the webservice application we are going to use PHP and PHPToolkit from Netsuite. PHP Toolkit can be download here
- Create the php form
Name: Contact Us
ID: customrecord_contact_us
Internal ID: xx
Name: Title
ID: custrecord_contact_us_title
Type: Free-Form Text
Store Value = true
Name: Email
ID: custrecord_contact_us_email
Type: Email Address
Store Value = true
Name: Message
ID: custrecord_contact_us_message
Type: Text Area
Store Value = true
Include the libraries necessary library in your PHP file, make sure that your directory is set correctly. The login_info.php should contain your Netsuite credentials.
require_once 'PHPtoolkit.php'; require_once 'login_info.php'; global $myNSclient;
Receive post data from the form and store in variables.
$title = $_POST['title']; $email = $_POST['email']; $message = $_POST['message'];
For custom record objects on PHP Toolkit the internal id is the integer id and not the string id.
$customRecord = new nsComplexObject('CustomRecord');
$recordTypeRef = new nsRecordRef(array(
'type'=>'customRecord',
'internalId'=>'67'));
Free-form text, Email address and Text Area are all string objects.
$field_title = new nsComplexObject('StringCustomFieldRef');
$field_title->setFields(array(
'internalId' => 'custrecord_contact_us_title',
'value' => $title));
$field_email = new nsComplexObject('StringCustomFieldRef');
$field_email->setFields(array(
'internalId' => 'custrecord_contact_us_email',
'value' => $email));
$field_message = new nsComplexObject('StringCustomFieldRef');
$field_message->setFields(array(
'internalId' => 'custrecord_contact_us_message',
'value' => $message));
Set the custom field list to the custom record object.
$customFieldList = array($field_title, $field_email, $field_message); $customRecord->setFields(array( 'recType' => $recordTypeRef, 'customFieldList' => $customFieldList ));
Add the custom record.
try
{
$addResponse = $myNSclient->add($customRecord);
// handle add response
if(isset($addResponse))
{
if ($addResponse->isSuccess)
{
echo "SUCCESS";
}
else
{
echo "" . $addResponse->statusDetail[0]->message . "";
echo "";
}
}
}
catch(Exception $e)
{
echo $e;
}
You can download the source code here.
Related posts:
- Netsuite | How to use External website to send data to Netsuite Online Forms
- Netsuite | How to get the value of custom fields using webservices in .NET application
- Netsuite | How to put dynamic values on Email Templates in Send Email Action in Workflow Manager
- Netsuite | How to know if a form has a client-side suitescript
Connect!
Enter your WordPress.com blog URL
http://.wordpress.com
Proceed