Validation of Workflow Rule based on Date field value

By | February 20, 2012

For one of our clients we had a requirement where 3 days after closing opportunity a welcome letter needed to be sent out. The closure action was tracked using two fields Status (Closed) and Closed Date (Date when opportunity was closed). There was an action in workflow to send out the Welcome Letter to clients; however large number of users using it was clicking it before 3 days after closure. Hence we had decided to implement the workaround so that the Rule will be visible only when 3 days are passed after closure. We followed below steps to put the below script on workflow rule to perform the validation.

  1. Go to the Administration | Advanced Customization | Workflow.
  2. Click on the your “OpportunityWorkflow
  3. Click on the “Edit Workflow” button.
  4. Then click on the rule name that you want to apply the condition
  5. Then put the below script in the  rule name of the Javascript Condition:
    var dOppoClosed=””;
    dOppoClosed = new String(Values(“oppo_closed”));
    if(dOppoClosed==”null” || dOppoClosed==”Undefined”)dOppoClosed=””;
    //’If date is blank then rule appeared else not appear
    if(dOppoClosed == “”)
    {
               Valid=true;
    }
    else
    {
               Valid=false;
    }
  6. Click on the “Save” button.
  7. Click on the “Activate Workflow” button.

This content explains how you can validate date fields to apply some conditions on workflow actions.