Concatenation of strings — Round 2

Naresh Vaneshwar
Nareshwar R.
Published in
2 min readFeb 9, 2016

This post is the continuation of the previous post of mine on the same topic.
In the last post, I was discussing a requirement which is very specific.
When I shared the post with my colleagues, they want to rework it towards a generic requirement. Feel free to check out here.

A short story: I used Variants, yes a very old datatype in NAV, developers never ever wanted to use it unless someone asked them to use! Thank you Rasitha Chandrasekara for the valuable tips.

Code next…
The first part of the code will have the necessary filtration of the Item master table. Then the function call happens with appropriate parameters.
The second and last part of the code will be the function itself. Let’s jump in.

The first part of the code…

ConcatCU is the codeunit, ConcatStrings is the function which takes three parameters A Variant, The Field No., and the Sign to be used to concatenation.

The second and last part of the code…

The second part of the code actually does the concatenation with the parameters you passed in. Since the first parameter is Variant, you can pretty much pass anything.

I have done it for records only, hence, I used RecordRef.GETTABLE() to retrieve the Item Table. The sign can be a pipeline(|) or an and(&) or even double periods(..) if you use it appropriately.

The final concatenation is: 1000|1001|1100|1110|1120|1150

The blog post ends right here, but there are some interesting facts, and those will follow.

#TIL: You can only pass by value, not pass by reference when you are passing record variables as variants.

When I try to concat a Code and a FieldRef, the compilation error message is bit funny.

Code + JOKER

That’s coincidence because my PC wallpaper is featuring Joker!

If you like to get this wallpaper, head over to justinmaller.com.

--

--

Naresh Vaneshwar
Nareshwar R.

Technical findings and new developments on Business Central