Saturday, March 30, 2019

How to Source Handling Cost and Subtotal from Transfer Order in Transaction Body Field of an Invoice

A custom Transaction Body Field of type Transaction List (sourced from Transfer Orders) has been created on Invoice. The user would like to have the fields Shipping Cost, Handling Cost and Order Subtotal populated on the invoice form upon selection of a Transfer Order.
Define the three Transaction Body Fields on the Sales Order:

  1. Navigate to Customization > Lists, Records & Fields > Transaction Body Fields > New
    Enter a Label
    Select Type = Currency
    Applies To tab: Mark the Sale check box to apply the custom field to it
    Un-check the Store Value check box.
    Display tab: Select a subtab or Main to display the field on the preferred location and Display Type = Inline
    Sourcing & Filtering tab: Select Source List = Transfer Order List
    Select Source From = Shipping Cost
  2. Transaction Body Fields Handling Cost and Order Subtotal are defined similarly.
    They cannot be sourced from Source List = Transfer Order List as the fields are not available for selection (in Sourcing & Filtering tab) nor accessible through Default Value using Formula (in Validation & Defaulting tab).

    Wanted result be achieved using a Client Script with Field Changed Function that will populate the fields Handling Cost and Subtotal upon every change of the selected Transfer Order.

    The function will have to:
    • Retrieve the selected order details
    • Retrieve the subtotal and handling cost of it
    • Set the values retrieved in the custom Transaction Fields defined above (Handling Cost and Order Subtotal)

    The script code can look like bellow:
    function FieldChanged_TransferOrder(type, name){    if (name == 'custbody_transfer_order_list')    {        //retrieve the ID of the selected Transfer Order        var getTOId =   nlapiGetFieldValue('custbody_transfer_order_list');         //load the transfer order record         var transferOrder = nlapiLoadRecord('transferorder', getTOId);	              //retrieve subtotal and handling cost        var subtotal = transferOrder.getFieldValue('subtotal');        var handlingCost = transferOrder.getFieldValue('handlingcost');		          //set the values in the transaction body field        nlapiSetFieldValue('custbody_to_subtotal',subtotal);        nlapiSetFieldValue('custbody_to_handling_cost',handlingCost);	                   }}

Once the client script is created, it will have to be deployed on Invoice. For script creation and deployment please refer to Create Script Records and Define Script Deployment.

No comments:

Post a Comment