Can you find the highest integer value using a flow?

Moedeb
Tera Guru

I have an integer field on the sys_user table called "u_queue_number".

What I want to do if possible via a flow is to seek out all records where u_queue_number is not blank and find what the current highest value of that field is and also how many records current have that value.

 

Ideas?

1 ACCEPTED SOLUTION

@Ankur Bawiskar 

I understand that it would likely need to be done via a flow script, but was hoping someone might be able to assist with the how.

Since I posted my question I have managed to make it work, but just not sure it's the best way to do it?

Ultimately, I created a flow variable called "Highest Queue Number" then did a scripted date 

 

Moedeb_1-1739764593416.png

 var largestQueueNumber = 0;
    var userGR = new GlideRecord('sys_user');
    userGR.addQuery('u_queue_number', '!=', '');
    userGR.query();
    
    while (userGR.next()) {
        var currentQueueNumber = parseInt(userGR.u_queue_number, 10);
        if (!isNaN(currentQueueNumber) && currentQueueNumber > largestQueueNumber) {
            largestQueueNumber = currentQueueNumber;
        }
    }
    return largestQueueNumber;

 

Result:

Moedeb_2-1739764860967.png

So it works, but is it the best way?

View solution in original post

6 REPLIES 6

@neetusingh 

I like the idea of improving the script to limit the database calls, however when I tried this in a flow I got the following error:

Invalid integer value for flow variable='null': {highestQueueNumber=5.0, countOfHighest=0}

 

The script is running in a set flow variables script

 

Hello @Moedeb,

This might be a bit late, anyway I see a nice script solution.

I see also that without script, a solution would not be possible.

Unless I miss something, this is not true.
A solution without script is actually rather simple, with the following steps:

1. "Set Flow Variable" Highest Queue Number (or whaterever you want) to zero.
2. "Look for Records" with the conditions you wish (e.g.  "u_queue_number is not empty")

3. "For Each" loop on 1., in which:
3.1 if u_queue_number > Highest Queue Number then "Set Flow Variable" Highest Queue Number to u_queue_number

At the end of the loop you have the highest value of u_queue_number in the sys_user table.

To get the number of the records in sys_user with the highest value of u_queue_number, you can use another Flow variable as a counter, either in the same "For each" loop, incrementing it if the u_queue_number matches the flow variable Highest Queue Number (reset it to "1" when 3.1 above applies), or with an additional "Look for Records" with condition u_queue_number = Highest Queue Number, after the "For Each" loop above.

I don't discuss performances, but a solution without scripting is (much) better for maintenability.

Hope it helps
Flavio