5 Replies · Latest reply on Dec 7, 2017 4:34 AM by Michael Ritchie

    Routing in a workflow using a list collector

      We are new to ServiceNow / Scripting and were hoping someone could help us.  We have a list collector variable within our catalog item.  In our workflow we are attempting to add an if statement where if one item is selected within the list collector route one way else if multiple items are selected within the list collector route the other way.

      It does not matter what values are selected, only that there is more than 1 selection.

       

      This is what we've tried in the If script within the workflow.

       

      answer = ifScript();

      function ifScript()

      {

      var office = current.variable_pool.office_affected.toSring();

      if(office.length>1)

      {

          

        {

          return 'yes';

        }

      }

      else

      {

        return 'no'; }

      }

        • Re: Routing in a workflow using a list collector
          prasad Kodumuri

          answer = ifScript();

          function ifScript()

          {

          var office = current.variables.office_affected.toString();

          if(office.length>1 )

          {

            

           

              return 'yes';

           

          }

          else

          {

            return 'no'; }

          }

           

           

           

          Simple condition

           

          answer = ifScript();

          function ifScript()

          {

          var office = current.variables.office_affected;

          if(office)

          {

                    return 'yes';

           

          }

          else

          {

            return 'no'; }

          }

          • Re: Routing in a workflow using a list collector
            Michael Ritchie

            First you need to split the list into in array to get the proper length.  Then you had extra {} so I removed those.

             

            answer = ifScript();
            
            function ifScript() {
                var officeArray = current.variables.office_affected.toString().split(",");
            
                if (officeArray.length > 1) {
                    return 'yes';
                } else {
                  return 'no';
                }
            }
            
            1 of 1 people found this helpful


            Please mark this post or any post helpful or the correct answer so others viewing can benefit.

              • Re: Routing in a workflow using a list collector
                Eric Cheung

                Michael,

                 

                I tried your script and it worked perfectly!

                 

                Thank you!

                 

                Prasad, I did not get a chance to try yours unfortunately. Thank you for the reply though!

                • Re: Routing in a workflow using a list collector
                  Rody Bjerke

                  Hi Michael,

                   

                  I'm trying something similiar, but instead of checking if there is 1 or more in the List Collector, i want to check if anyone in the list has "u_approval_required = Yes" and then route one way or the other based on that:

                   

                  answer = ifScript(); 

                   

                  function ifScript() { 

                      var officeArray = current.variables.office_affected.toString().split(","); 

                   

                      if (officeArray.length > 1) { 

                          return 'yes'

                      } else { 

                        return 'no'

                      } 

                   

                  I think it should be something like this, but not sure where to put it in the above script to make it work:

                  var sftwre = new GlideRecord('cmdb_ci_spkg');

                    sftwre.addQuery('sys_id', 'IN', officeArray);

                    sftwre.addQuery('u_approval_required', 'yes');

                    sftwre.query();

                   

                  Could you help?

                   

                  Best regards,

                    • Re: Routing in a workflow using a list collector
                      Michael Ritchie

                      answer = ifScript(); 

                       

                      function ifScript() { 

                          var softwareList = current.variables.NAME-OF-SOFTWARE-VARIABLE.toString();

                          var sftwre = new GlideRecord('cmdb_ci_spkg');

                          sftwre.addQuery('sys_id', 'IN', softwareList);

                          sftwre.addQuery('u_approval_required', 'yes');

                          sftwre.query();

                       

                          if (sftwre.hasNext()) { 

                              return 'yes'

                          } else { 

                            return 'no'

                          } 

                      }

                      1 of 1 people found this helpful


                      Please mark this post or any post helpful or the correct answer so others viewing can benefit.