Friday, January 4, 2019

Sample HTML Code to Invoke Extenally Available Suitelet and Pass Parameters

Below is a sample of a Suitelet invoked from an external HTML file which receives an internal ID of a customer record and returns the company name of the customer record.

Sample Suitelet Code:

function demoHTML(request, response)
{
 if ( request.getMethod() == 'GET' )
 {
  var html =  '<html><body><h1>This is the GET method. Please use POST to see the intended result</h1></body></html>';
  response.write( html );
  response.setHeader('Custom-Header-Demo', 'Demo'); 
 }else{
  var subject = request.getParameter('useracct');
  var rec = nlapiLoadRecord('customer',subject);
  var compname = rec.getFieldValue('companyname');
  var html =  '<html><body><h1>Customer Name is ' + compname + '</h1></body></html>';
  response.write( html );
  response.setHeader('Custom-Header-Demo', 'Demo'); 
 }
}

Note: on the Script Deployment, set Available without Login to checked/true.

Sample HTML Code:

<form  id="form" name="form" action="https://forms.na1.netsuite.com/app/site/hosting/scriptlet.nl?script=704&deploy=1&compid=TSTDRV817301&h=8d2989447f2aa23f7baa" method="post">
 Customer Internal ID &nbsp;:<input type="text" id="useracct" name="useracct" /><br/>
 <input type="submit" id="getname" name="getname" value="Get Customer Name" />
</form>

DISCLAIMER: The sample code described herein is provided on an "as is" basis, without warranty of any kind, to the fullest extent permitted by law. Netsuite Inc. does not warrant or guarantee the individual success developers may have in implementing the sample code on their development platforms or in using their own Web server configurations.

Netsuite Inc. does not warrant, guarantee or make any representations regarding the use, results of use, accuracy, timeliness or completeness of any data or information relating to the sample code. Netsuite Inc. disclaims all warranties, express or implied, and in particular, disclaims all warranties of merchantability, fitness for a particular purpose, and warranties related to the code, or any service or software related thereto.

Netsuite Inc. shall not be liable for any direct, indirect or consequential damages or costs of any type arising out of any action taken by you or others related to the sample code

 

No comments:

Post a Comment