Setting a Custom Date Format for Sales Order Transaction Body Fields in SuiteCommerce Advanced

Overview

When working with SuiteCommerce Advanced (SCA) and NetSuite, you may encounter an issue where setting a date field in a Sales Order using a transaction body field does not support the normal date format (e.g., ‘MM/DD/YYYY’). To resolve this, you can convert the date to a supported format (e.g., ‘DD-Month-YYYY’) before setting it.

Solution

Here’s how you can format a date string from ‘MM/DD/YYYY’ to ‘DD-Month-YYYY’ and set it to a Sales Order transaction body field in your SCA implementation.

Step-by-Step Implementation

1.Create a Function to Format the Date

Define a function formatDeliveryDate to convert the date from ‘MM/DD/YYYY’ format to ‘DD-Month-YYYY’ format.

formatDeliveryDate: function formatDeliveryDate(dateStr) {

  const months = [

    “January”, “February”, “March”, “April”, “May”, “June”,

    “July”, “August”, “September”, “October”, “November”, “December”

  ];

  // Assuming the dateStr is in the format ‘MM/DD/YYYY’

  const [month, day, year] = dateStr.split(‘/’);

  const monthName = months[parseInt(month, 10) – 1];

  return `${day}-${monthName}-${year}`;

}

2.Update the setDeliveryDate Function

Modify the setDeliveryDate function to use the formatDeliveryDate function and set the formatted date to the Sales Order transaction body field.

setDeliveryDate: function setDeliveryDate() {

  try {

    const dateInput = document.getElementById(‘selected-date’);

    const selectedDate = dateInput.value;

    var formattedDate = this.formatDeliveryDate(selectedDate);

    console.log(“select”, selectedDate);

    this.model.attributes.options.custbody_exp_del_date = formattedDate;

    console.log(“this==”, this);

    this.wizard.selectedExpDate = selectedDate;

  } catch (error) {

    console.log(‘error@error’, error);

  }

}

Leave a comment

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