This topic contains 1 reply, has 0 voices, and was last updated by pcutler 6 years, 10 months ago.

  • Author
    Posts
  • #18176

    billyboyo

    Anybody got a script kicking around that sets fields on a Sales Order by looking up predefined values in a custom record?

    Anyone willing to share it with sufficient info for a “non-scripter” (but wanna be) to implement?

    As incentive, there’s a free pair of golf shoes in it for the best (judge’s opinion is final) entry.

    Back story is I want to assign default values on a Sales Order based on the Shipping Method (Shipping Item) chosen.

    Thought I could add custom fields to the Shipping Item but apparently that’s not supported by Netsuite.

    Was told script was the way to go.

    My “relational database” / SQL analogy would be to create a table (let’s call it ShipViaPlus) with Shipping Methods as it’s key.

    Examples of Fields in that custom table would be Freight Code (value = “PP”, “TP”, “CC”, etc.) and SCAC Code (value = “UPSN”, “FDXG”, etc).

    I would have matching custom body fields on my Sales Order table.

    When creating (or editing) a Sales Order and setting {shipmethod} the script would trigger and:

    Look up the Sales Order {shipmethod} in the custom table ShipViaPlus (essentially Join the tables by Shipping Method).

    Set Sales Order {freightcode} = ShipViaPlus {freightcode}

    Set Sales Order {SCAC} = ShipViaPlus {SCAC}, etc.

    In terms of error trapping:

    If shipmethod missing from ShipViaPlus set the SO fields to NA or ERR etc., maybe send an email?

    Trigger considerations –

    Sales Order can be created via UI, CSV Import and most importantly via WebServices (EDI).

    Seems like relatively simple logic but (alas) I have no suitescript skills (yet).

    Given the basic script, I can create the custom record, play with the fields, etc.

    If it winds up being a Workflow Action Script, I do have minimal Workflow understanding (define the parameters, I can at least create it).
    This is a cached copy. Click here to see the original post.

  • #18177

    pcutler

    Here’s a quick script I threw together. You may need to adjust for your needs. I haven’t tested it, so there could be some typos/bugs. Good luck!

    Code:
    require([‘N/search’, ‘N/currentRecord’, ‘N/email’], function(search, currentRecord, email) {

    //get the shipping method from the appropriate field
    var SHIPPING_METHOD = currentRecord.get().getValue({fieldId: ‘shipmethod’});

    // run a search for mapping custom records that match the shipping record
    var mySearch = search.create({
    type: ‘customrecord_mapping’,
    columns: [‘custrecord_freight_code’],
    filters: [
    [‘custrecord_shipping_method’, ‘is’, SHIPPING_METHOD]
    ]
    });

    // get a list of results
    var searchResults = mySearch.runPaged({number: 5}).fetch({number: 0}).data;

    if(searchResults && searchResults.length == 1) {
    // if theres a single result, use it to update a sales order
    currentRecord.get().setValue({fieldId: ‘shipmethod’, value: searchResults[0].getValue({name: ‘custrecord_freight_code’})});
    }
    else {
    // if there are either multiple results or no results, send an error email
    email.send({ author: -5, recipients: [‘abc@domain.com’], subjust: ‘Script Error’, body: ‘Could not map shipping method to freight code.’});
    }
    });

You must be logged in to reply to this topic.