How to set the default shipping address country in SuitScript

We can set a default shipping address using suitescript.

define(‘ContactUs.Model’, [

  ‘SC.Model’,

  ‘Configuration’,

  ‘Application’,

  ‘Models.Init’,

  ‘Utils’

], function ContactUs(

  SCModel,

  Configuration,

  Application,

  CommerceAPI

) {

  ‘use strict’;

 

  return SCModel.extend({

    name: ‘ContactUs’,

 

    configuration: Configuration.get(‘contactUs’),

 

    create: function create(data) {

      nlapiLogExecution(‘ERROR’, ‘Create fn’);

      nlapiLogExecution(‘ERROR’, ‘Create fn data’, JSON.stringify(data));

      data.country =”US”;

      var response;

      var responseCode;

      var currentDomainMatch = CommerceAPI.session.getSiteSettings([‘touchpoints’]).touchpoints.home;

      var currentDomain = currentDomainMatch;

      var url = currentDomain + ‘/app/site/crm/externalcasepage.nl?compid=’ +

        nlapiGetContext().getCompany() + ‘&formid=’ + this.configuration.formId + ‘&h=’ +

        this.configuration.hash + ‘&globalsubscriptionstatus=1’;

      var formUrl = this.configuration.formURL

      nlapiLogExecution(‘ERROR’, ‘Create fn formUrl’, formUrl);

      nlapiLogExecution(‘ERROR’, ‘Create fn url’, url);

      if (CommerceAPI.context.getFeature(‘SUBSIDIARIES’)) {

        data.subsidiary = CommerceAPI.session.getShopperSubsidiary();

      }

      try {

        nlapiLogExecution(‘ERROR’, ‘Create fn data.subsidiary’, JSON.stringify(data));

        response = nlapiRequestURL(formUrl, data);

        responseCode = parseInt(response.getCode(), 10);

        // Just in case someday it accepts the redirect. 206 is netsuite error (‘partial content’)

        nlapiLogExecution(‘ERROR’, ‘Create fn response’, JSON.stringify(response));

        nlapiLogExecution(‘ERROR’, ‘Create fn response’, responseCode);

        if (responseCode === 200 || responseCode === 302 || responseCode === 201 || responseCode === 404) {

          return {

            successMessage: this.configuration.successTitle

          };

        }

      } catch (e) {

        nlapiLogExecution(‘ERROR’, ‘Create fn url submit error’, e);

        // If the form submit SUCCEEDS!!! it will throw an exception

        // Because of the url redirect

        if (e instanceof nlobjError && e.getCode().toString() === (‘ILLEGAL_URL_REDIRECT’)||(‘SSS_UNKNOWN_HOST’)) {

          return {

            successMessage: this.configuration.successTitle

          };

        }

      }

 

      return {

        status: 500,

        code: ‘ERR_FORM’,

        message: ‘Something went wrong processing your form, please try again later.’

      };

    }

  });

});

In the above example it is a form in which all the necessary modules are extended for that form and we are setting the data.country =”US” to make the shipping address default as “US”.

Leave a comment

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