SuiteScript – Shipping Carriers and Methods Unraveled

Like almost all my posts, this is a simple concept that quickly turned into brain surgery. So let’s dumb this down.

I needed a way to select and set the shipping method on an estimate from a Suitelet. Before I even started coding, I noticed that I had different shipping methods based on my selection of shipping carriers. What I mean by this is that when editing an estimate, when you change the shipping carrier, it blanks the shipping methods dropdown and the choices change. So how does NetSuite know which methods (also known as shipitem) are associated with each of the two carriers? Great question!

Setup >> Accounting >> Shipping — Shows carriers

List >> Accounting >> Shipping Items — Shows shipping methods

I’ll share some code written in SuiteScript 2.1 that can be dropped into debugger. When you run it, you’ll see the list of all shipping methods. It is not limited by carrier and in fact the carrier field is blank. Why? Who knows?

However, what I learned was that any custom shipping methods (shipitem) gets associated with the FedEx/USPS/more carrier. AND… when you change the shipping method, it automatically changes the carrier. So set to one of the UPS methods and the carrier magically becomes UPS. Set to any method not prefixed with UPS, and the carrier becomes FedEx/USPS/more.

In an estimate, after changing the method to any method other than one of the UPS methods, and inspect it using SuiteScript Field Explorer (a Chrome plugin), you’ll see the carrier is set to “nonups”.

So it would appear that the two carriers (under the hood) are UPS and “Other”!

Here is my code. The commented section at the bottom was my great revelation. Changing the method automatically changes the carrier. Be sure to select script type of 2.1 when you run this in debugger.

require(['N/search', 'N/record'],
    (search, record) => {
        log.debug('Start');

        let mySearch = search.create({
            type: 'shipitem',
            columns: [
                search.createColumn({ name: 'internalid'}),
                search.createColumn({ name: 'carrier', sort: 'ASC'}),
                search.createColumn({ name: 'itemid', sort: 'ASC'})
            ],
            filters: [
                ['isinactive', 'is', false]
            ]
        })

        let myPages = mySearch.runPaged({ pageSize: 1000 });
        for (let i = 0; i < myPages.pageRanges.length; i++) {
            let myPage = myPages.fetch({ index: i });
            myPage.data.forEach(
                function (result) {
                    let internalid = result.getValue('internalid');
                    let carrier = result.getValue('carrier');
                    let itemid = result.getValue('itemid');
                    log.debug(`${carrier}: ${itemid}: ${internalid}`)
                }
            )
        }


        // var rec = record.load({
        //     type: record.Type.ESTIMATE,
        //     id: xxxxxxxx,
        //     isDynamic: false
        // });

        // rec.setValue('shipmethod', xxx);

        // rec.save();

        log.debug('Done');
    }
)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s