Tutorial | PHP ‘Contact Us’ external form to Netsuite custom record

In this tutorial we are going to create a php external form that would serve as a “Contact Us” page to a website. Every submitted record will be saved to a custom record in Netsuite.

  1. Create a custom record. Setup > Customization > Record Types > New
  2. Name: Contact Us
    ID: customrecord_contact_us
    Internal ID: xx

  3. Create three custom fields for the created “Contact Us” custom record.
  4. 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

  5. For the webservice application we are going to use PHP and PHPToolkit from Netsuite. PHP Toolkit can be download here
  6. Create the php form
  7. Title
    Email
    Message
  8. Here is the code for PHP Netsuite webservice
  9. 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:

  1. Netsuite | How to use External website to send data to Netsuite Online Forms
  2. Netsuite | How to get the value of custom fields using webservices in .NET application
  3. Netsuite | How to put dynamic values on Email Templates in Send Email Action in Workflow Manager
  4. Netsuite | How to know if a form has a client-side suitescript

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>