How to Convert ship method into abbreviated form for displaying in the SCA website.

In the NetSuite the ship method values contains 2 or three words in it for example: “3rd party FedEX” so if any client wants to display on the the abbreviation or a single word we can use the following javascript for converting the ship method.

Example: “3rd party FedEX” can be converted into FEDEX and also : “3rd party USPS” can be converted into USPS

For getting the ship method value we need a suite-script module and to pass the value from back-end.

here I’m mentioning only the front end converting method after getting the ship method value.

Code Snippet:

//here 'data' is getting from back-end and it contains the ship method name, we are checking the words: "FedEx", "USPS", "UPS" present in it or not.
here we are also adding the delivery method page link to the website
if (data) {
    //Shipped Via:Getting value of ship method and converting into Short form
    var shipLink = "";
    var shipAbbriv = "";
    var shipMethodSearchResultData = data.searchResultData
    var shipmethodValue = shipMethodSearchResultData[0].columns.shipmethod.name;
    const WORDSTOCHECK = ["FedEx", "USPS", "UPS"];
    for (let i = 0; i < WORDSTOCHECK.length; i++) {
        if (shipmethodValue.includes(WORDSTOCHECK[i])) {
            var shipViaValue = WORDSTOCHECK[i];
            if (shipViaValue === "FedEx") {
                shipAbbriv = "FEDEX";
                shipLink = data.trackingLinks.FEDEX;
            }
            if (shipViaValue === "USPS") {
                shipAbbriv = "USPS";
                shipLink = data.trackingLinks.USPS;
            }
        }
    }

Leave a comment

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