Monday, July 15, 2019

Limit Shipping Method list

There are instances when an account have a long list of available shipping method, though there are only several methods that are usually used.

In this type of scenario, the user may wish to limit the shipping methods that they see in the list.

Since the list set on the Shipping Method field could not be directly limited, one can make use of the alternate solution below:

1) Create a custom list

     Name: <desired name>

     Values > Value: <Name of the desired shipping method>

2) Create a custom transaction field:

      Label: <desired name>

      Type: List/Record

      List/Record: <list in step 1>

      Applies To: Sales


           Subtab: Shipping

           Display Type: Normal

    Store Value: checked

3) Create a Client side script triggered on field change

// set the actual shipping method based on the selected value from the custom list

function clientFieldChanged(type, name, linenum){
    nlapiLogExecution('debug','name', name);
    if(name == 'custbody24') // custbody24 is the internal ID of the field in step 2

        var custMethod = nlapiGetFieldValue('custbody24');
        nlapiLogExecution('debug','custMethod', custMethod);
        var shipMethod;


        if (custMethod == '1') // if - else was used since switch is not working

            shipMethod = '1465'; // internal ID of the shipping method
        } else if (custMethod == '2'){
            shipMethod = '248';
        nlapiLogExecution('debug','shipMethod', shipMethod);
        nlapiSetFieldValue('shipmethod', shipMethod,false);

4) Set the Ship Method display type to Inline Text

    Custom Transaction Form > Screen Fields subtab > Shipping sub subtab > Shipping Method

     Display Type = Inline Text

    // set the Ship Method field's display type to Inline text for data consistency

No comments:

Post a Comment