Genesys Cloud - Main

 View Only
Discussion Thread View
  • 1.  Count in Reverse Order

    Posted 01-25-2022 06:00
    Hello,

    Is there a way in Architect to COUNT in reverse? For example, if I have an array of {Apple, Pear, Banana, Banana} and I want to use the COUNT function but start from the right, excluding anything Banana, how would I go about that? I considered using the REVERSE function but do not want to reverse the actual words, just the order I'm counting them in.

    Regards,
    Mo
    #ArchitectureandDesign
    #Routing(ACD/IVR)

    ------------------------------
    Mo Ford
    Upgrade
    ------------------------------


  • 2.  RE: Count in Reverse Order

    GENESYS
    Posted 01-25-2022 09:47
    Use a loop to go through each item in your collection.  In this example Task.fruit is the string collection.  Name the index variable anything you like.  The maximum loop count tells the loop when to stop, in your case you want the number of items in your list, so use the expression Count(Task.fruit) which will be 4.  Normally people want to go through the list from the start, so inside the loop you would use Task.fruit[Task.index].  You know collection indices start at 0 right?  So
    0=Apple
    1=Pear
    2=Banana
    3=Banana
    In your case you want to go through it backwards, so instead of Task.fruit[Task.index] you want to look at Task.fruit[Count(Task.fruit)-1-Task.index]. 
    When Task.index=0, you will look at the item with index 4-1-0 = 3 and get Banana
    When Task.index=1, you will look at the item with index 4-1-1 = 2 and get Banana
    When Task.index=2, you will look at the item with index 4-1-2 = 1 and get Pear
    When Task.index=3, you will look at the item with index 4-1-3 = 0 and get Apple

    FYI there's a much simpler way of counting how many items are not Banana in your collection.  You could just evaluate this expression, no looping necessary.
    Count(Task.fruit)-Count(Find(Task.fruit, "Banana"))
    Find returns a collection of indices for which the item exists in the given collection (in your case you would get a collection with the values 2 & 3).  The count of that is 2, and subtracting it from the total count for the collection gets 2.

    ------------------------------
    Melissa Bailey
    Genesys - Employees
    ------------------------------



  • 3.  RE: Count in Reverse Order

    Posted 01-27-2022 10:37
    Thank you, Melissa. The second suggestion is much cleaner and worked for finding the count.

    If I wanted to instead find the location of the items in the string below that are not EXPIRED, CLOSED or REJECTED with the intent to save the location to be used later in a GetAt function, how would I go about doing that?

    EXPIRED, ISSUED, CLOSED, OPENED, REJECTED

    ------------------------------
    Mo Ford
    Upgrade
    ------------------------------



  • 4.  RE: Count in Reverse Order

    GENESYS
    Posted 01-31-2022 13:11
    First create a string collection Task.statuses from your string using the Split function.  Create an integer collection Task.GoodStatusIndices to hold the indices (locations) of the items that don't match.  Create another string collection Task.BadStatuses with EXPIRED, CLOSED, & REJECTED as the items.  Then use a loop to go through each item in Task.statuses and determine if it is not in Task.BadStatuses.  If so, add the index to Task.GoodStatusIndices.

    The full expression in the decision action is 
    FindFirst(Task.BadStatuses, Trim(Task.statuses[Task.index])) == -1
    Trim is getting rid of any leading or trailing whitespace.  FindFirst returns -1 if the item is not found anywhere in the collection.
    The full expression for the update data action inside the loop is
    AddItem(Task.GoodStatusIndices, Task.index)




    ------------------------------
    Melissa Bailey
    Genesys - Employees
    ------------------------------



  • 5.  RE: Count in Reverse Order

    Posted 02-15-2022 04:55
    Thanks, Melissa. That suggestion worked to gather the locations of the good statuses. If I wanted to reference the highest number in the good status indices, how would I go about doing that in a GetAt() function?

    ------------------------------
    Mo Ford
    Upgrade
    ------------------------------



  • 6.  RE: Count in Reverse Order

    GENESYS
    Posted 02-17-2022 10:42
    You mean get the last item?  
    GetAt(Task.GoodStatusIndices, Count(Task.GoodStatusIndices)-1)​


    ------------------------------
    Melissa Bailey
    Genesys - Employees
    ------------------------------



  • 7.  RE: Count in Reverse Order

    Posted 02-22-2022 15:18
    Thanks for all of your help @Melissa Bailey! Last question (for now), if the collection is a collection of dates, is there a way to identify the most recent date? I assume some form of the date that's closest to today.​

    ------------------------------
    Mo Ford
    Upgrade
    ------------------------------



  • 8.  RE: Count in Reverse Order

    Posted 02-22-2022 15:44
    I would think you would want to create another collection of "dateTimeDiffs" between the current time and the dates in your existing collection. The output of DateTimeDiff isn't always friendly (sometimes you get something like this: PT-4337H-59M), so you would need to convert it to a standard time unit, such as seconds.  The most recent date would be the lowest seconds value of course. Then, you would need to run through all of the dateTimeDiffs and use a decision step to see if the current step is less than the previous step (you'd want to start out with a comparator of a really high number so that the you properly loop through all of the items in the array. You then replace the <most recent date placeholder > value if it is lower.

    ------------------------------
    Peter Stoltenberg
    Avtex Solutions, LLC
    ------------------------------



Need Help finding something?

Check out the Genesys Knowledge Network - your all-in-one access point for Genesys resources