Easily Finding a Dimension Set ID in Microsoft Dynamics NAV
With the advent of the Dimension Set feature in Microsoft Dynamics NAV (Navision), it can be tricky to figure out how to change the Dimension Set ID assigned to a record in code or how to assign new dimensions to code. If you don’t know what you’re doing, you’ll spend a few hours writing stuff to go through all the possible dimension sets until you find just the right one, or your code determines that there isn’t a valid dimension set at all and you have to create one. But there’s a way easier way. It’s just a little obtuse.
If you look at the DimensionManagement codeunit, you’ll find a function called GetDimensionSetID. There’s only one line of code in this function, and it’s a call to the GetDimensionSetID function in the Dimension Set Entry table.
Dimension Set Entry.GetDimensionSetID is the function we’re looking for to get a Dimension Set ID. It has only one parameter: DimSetEntry, which is a record variable with a subtype of Dimension Set Entry. The GetDimensionSetID function actually doesn’t care about the current Dimension Set ID record that it’s attached to—you can do an INIT on a Dimension Set ID record variable and then call that variable’s GetDimensionSetID function and get perfectly valid results. Instead, GetDimensionSetID pays very close attention to the DimSetEntry parameter that you pass in.
You may have seen this function and figured that it was exactly what you were looking for, so you had your code load up a Dimension Set Entry table with the combination of dimensions you wanted an ID for and you passed it in. And then you may have gotten an error saying something like “Dimension Set ID must not be 0 in Dimension Set Entry . . . “ from the line of code in the function that runs TESTFIELD on Dimension Set ID for each record in your passed-in set.
The secret of using this function successfully is actually pretty simple. You have to pass it a temporary set of Dimension Set Entry records containing all the dimensions you’re trying to find a Dimension Set ID for, but you have to make sure that the Dimension Set ID value on all of your temporary records is -1. (I suspect you could use some other negative number, but I like -1 for the sake of consistency.) At least, that’s the way I do it when I’m trying to get a Dimension Set ID; giving the temporary records the -1 value lets me know what I’m doing if I see them in the debugger. (Also, should I forget to mark the temporary property on the record variable and end up writing those records to the real database, using the negative number makes them easy to identify as errors when I go look at the records.)
Video Gaming Update
And finally, because I know that people only read my blog entries to hear about me playing video games: After over 100 hours, I finished my first playthrough of Persona 4 on my PS Vita. I missed out on P4 when it was a PS2 game by virtue of not really having that much time to sit in front of my TV, but having that game in my pocket made it super-easy to find time to play. It’s an absolutely amazing game; it’s my favorite JRPG since Final Fantasy IX. If you like JRPGs, you should pick it up. (And if you’re curious, I wound up dating Rise—although I considered going with Yukiko instead.)
If you have any further questions about this or other development issues, contact one of our development experts at ArcherPoint. If you enjoyed this blog, you might like to read more of Tom Hunt’s blogs, or check out our collection of Development Blogs.