Recursive CTE Query / BAQ, need a sanity check and help

Hello.

Up until a few days ago I was convinced Epicor couldn’t actually do true recursion. Was proven wrong, and now found a case where I coincidentally need to apply it. I believe the recursion part is working, however something in my calculation is off that I can’t wrap my head around.

What I’m doing: Building a recursive query to rip out all of the xyz parts of the XML string in XXXDef. I want to extrapolate a list of all of the custom controls and scripts added to our environment across the different screens, so we can better catalog them and target them for our Kinetic conversions.

CustomizationDetails.baq (49.7 KB)

I’ve attached where I’m at in the query. Basically, I calculate out the First block in the top CTE, then calculate the position in the content field, the length of the block, and the “Leftover” part of content after the block as my anchor. The leftover was a recent add, as you could just do it in relation to the original Content field always, with clever positioning. I originally attempted this way with the same result.

In the recursive member I calculate it relative to the “Leftover” bit stored in LastContent. I get the position of the next block, the length, and the new LastContent. I find and store the new “first block” in the field.

All is well, and it recurses down a single layer as shown below

However, it throws a sql error saying that a length was bad for one of the substrings.
image

I cannot for the life of me figure out where it is entering badly. I tried to ensure that I wasn’t calculating if the length of the calculated against object was smaller than the sum of the relative position and length. Wondering if anyone here can see something I’m not.

Something is getting cut off somewhere, a coworker noticed it is starting with in the LastContent field meaning the tag is occuring before the tag meaning it is going to be a negative length.

Haha, my LastContent was trying to chop of a block that was already chopped off. Instead I should be premptively chopping off the “Current” block so it’s gone on the next iteration. Replaced LastContent reference to the CTE’s Position and Length with the recursive member’s Position and Length.

There is still an error on the final block calculation, but at least he recursion is working :smiley: