4 Replies Latest reply on Mar 17, 2016 8:43 AM by Jeremy Donaldson

    Simple Rule JavaScript

    Jeremy Donaldson Journeyman

      I'll begin this by saying I've never done an update like this before myself.  Looking for assistance on how to add a simple rule java script to an existing rule set for a custom eform.  Need to be able to add a watcher group in parallel to the approval flow when a particular department ID is specified within a vector field.  Not entirely sure how to capture the value from the vector field and loop through it to see if the value matches.  Below is what I've created so far in an attempt to build this, thanks in advance for any assistance and or direction.

       

      Condition:

       

      function AddProcurementGroup_Condition (eform)

      {

           // Add Procurement group to the flow based on certain cost centers

           // Some kind of loop goes here to step through the values of the vector field and sends it below to the isCostCenterSelected function

            // Eform have been checked -- no particular Cost Centers are present, so return false

      }

       

      function isCostCenterSelected(cc)

      {  

           var checkCCs= new Array("44801","44802","44803","44804","44805","44806","44807","44808","44809","44810","44811","44812","44813","44814","44815","44816","44817","44818","44819","44820","44821");   

       

           // loop through and check cost centers  

           for (var i=0; i < checkCCs.length; i++)

           {    

                Log.javascript.debug("Compare " + checkCCs[i] + " & " + cc);     

                if (checkCCs[i].equals(cc))

                {return true;}  

           }  

           // match not found, return false

            return false;

           }

      AddProcurementGroup_Condition; 

       

      Action:

       

      function AddProcurementGroup_action (eform)

      {  

           // Add Procurement Group to Flow    

           var ProcurementGroup = Group.getGroup("Procurement");    

           return ApprovalRequest.create(eform, ProcurementGroup,true,"ruleReasons","ProcurementGroup");                                                 

      }

      AddProcurementGroup_action;

        • Re: Simple Rule JavaScript
          Amit Gupta Master

          Hi Jeremy,

           

          Probably you could try something as below:

           

          function AddProcurementGroup_Condition (eform)

          {

                    var list = eform.getFieldValue("TestVectorField");

                    if (list != null)

                    {

                              for(i=0; i < list.size(); i++)

                              {

                                        var testObject = list.get(i);

                                        var cc = testObject.getFieldValue("CostCenter");

                                        var checkCCs= new Array("44801","44802","44803","44804","44805","44806","44807","44808","44809","44810","44811","44812","44813","44814","44815","44816","44817","44818","44819","44820","44821");  

                                        // loop through and check cost centers 

                                        for (var i=0; i < checkCCs.length; i++)

                                        {   

                                          Log.javascript.debug("Compare " + checkCCs[i] + " & " + cc);    

                                          if (cc !=null && checkCCs[i].equals(cc))

                                                  {return true;} 

                                        } 

                                        // match not found, return false

                                        return false;

                              }

                    }

          }

           

           

          In action, you will need to set third parameter in return statement to false. true defines that the approver will be added as an actual approver i.e. his approval will be required, whereas false means, it will be added as a watcher.

           

          function AddProcurementGroup_action (eform)

               // Add Procurement Group to Flow   

               var ProcurementGroup = Group.getGroup("Procurement");   

               return ApprovalRequest.create(eform, ProcurementGroup,true,"ruleReasons","ProcurementGroup");                                                

          }

          AddProcurementGroup_action;

           

          Best Regards,

          Amit

          1 of 1 people found this helpful