Monday, December 27, 2021

What are these parameters in FindSet([Boolean] [, Boolean]))?

Hello All, 
Long time no see, huh? Sorry that it took me so long to write another blog, but here I am now with the solutions to your problems. Just kidding :p 

Also, comments like these inspire me. Thank you so much, means a lot! 



As you must have already read the title and have asked this question so many times. I have. But thanks to Erik Hougaard for making me understand what exactly it does. So, I thought why not put into words what I have learned. 

Enough about me and the background, let's get to the point ;)

We know what Findset is. It is used when you want to find a set of records. Say, you want to modify all the records that have 'i' in Customer Name to 'ee'. You will not do a Findfirst() as this will hit the database every time for the same action, whereas Findset() will retrieve all records at once. 
But, what are these parameters? 

The parameters are [ForUpdate][, UpdateKey] and hold Boolean values: True, False 

ForUpdate:  Set True if the loop contains an update of a value. 

UpdateKey: Set True if the loop contains an update of a key. 

Following are the combinations and when to use:

1. Findset(false,false)/ Findset()
Use this when you do not have any modify in the loop. For example, Copy data from one table to another or run a function.

3. Findset(true,false)
Use this when there is an update in the loop excluding the key.

4. Findset(true,true)
Use this when there is an update in the loop including the key. 

Now you will ask me why Findset(false, true) is not a combination. If you think logically if there is no update then how will there be an update for keys? So, this combination doesn't make sense. 

Another question can be, will there still be a modify() if we do not use the parameters? Absolutely yes! But, when we talk about optimization and following the right way to code, always use these parameters with Findset(). 
On another note, if you use these parameters, it also makes it easier for other developers or when you look at your code after ages to gaze at what goes inside the loop without going through the whole code. 


I hope this gave you a better understanding and helps you! Have a great day and A very Happy New Year! 

I will be back soon with another blog, I promise :D 

Check out other blogs, if you haven't already. 

Please suggest what else do you want me to blog about. Keep following and supporting!

You can also email me at jyotsnaoberainav@gmail.com

Also, visit my website JONAV if you are looking for NAV/D365BC Training and/or Services!

Thank you! 

No comments:

Post a Comment