Monday, October 22, 2018

Use CASE WHEN Expression in Workflow Manager Formula

This solution demonstrates how to use CASE WHEN expression and how to add days to a date field in the Workflow Manager formula. In the sample below, the workflow adds five days to the transaction date and sets it as the default value of the shipping date when creating a sales order. It also excludes Saturday and Sunday.

  

Create a Workflow

 

1. Navigate to Customization > Workflow > Workflows > New
2. Set the following:
------- Name: (Any name)
------- Record Type: Transaction
------- Sub Types: Sales Order
------- Release Status: Released or Testing
------- Initiation: On Create
------- Trigger Type: Before Record Load

2. Set the following:
------- Name: (Any name)
------- Record Type: Transaction
------- Sub Types: Sales Order
------- Release Status: Released or Testing
------- Initiation: On Create
------- Trigger Type: Before Record Load
------- In the Field subtab, click New Field.
------------ Label: Temp_date (or any label)
------------ ID: custworkflow26 (or any ID )
------------ Type: Date
------------ Store Value: Un-checked
------- Save.

3. Add a new state with two 'Set Field Value' actions
------- (First Set Field Value action)
------- Trigger: Before Record Load
------- Parameters:
------------- Field: Temp_date (or the label you specified in Step 2)
------------- Value: Date= Five Days from Now
------- (Second Set Field Value action)
------- Trigger: Before Record Load
------- Parameters:
------------- Field: Ship Date
------------- Value: Formula 

CASE

  WHEN (TO_CHAR({custworkflow26}, 'D')) = '1'

    THEN (TO_DATE(TO_CHAR(({custworkflow26} + 1),'MM/DD/YYYY')))

  WHEN (TO_CHAR({custworkflow26}, 'D')) = '7'

    THEN (TO_DATE(TO_CHAR(({custworkflow26} + 2),'MM/DD/YYYY')))

  ELSE (TO_DATE(TO_CHAR({custworkflow26},'MM/DD/YYYY')))

END

 

4. Save.

No comments:

Post a Comment