Function return value custom code

I’m trying to use a function for the first time that returns a value in custom code BPM. I’m just not figuring out what the return data object is. There are 4 return values and I’m trying to use 1 of those for in my code. Is there a dataset inherent to the “function”?

Personally, if I’m going to the length of writing a function, I tend to shove all the code into said function.

BPM’s should be a stub, and ideally all widgets. Most of mine look like this:
image

Having said that, Functions intake and return tuples. Here’s an example.

Thank you @jtownsend . I am trying to compare two strings for similarity in a BAQ - basically trying to find orders that were written incorrectly so we can educate and correct. I can just write the custom code into that BAQ but I have a feeling this same type of comparator tool would be useful as a function for other purposes down the road… so I stuck the code into a function and tested it using Postman. Works great. But when I went to actually reference the function, I realized I can’t use the widget because I need to use the function in a loop… so I tried to reference it in custom code block and assumed it would be like an business object method where I set some out variables in the method and then those variables would get populated with the responses from the function. But yeah that didn’t work. Then I was like - oh duh - there should be easy examples to follow on epiusers. But lo and behold, after 2 days of skimming posts, it’s just not apparent. I thought I had read somewhere that they made the functions easier to access… but perhaps that’s after 2021.2.

If I have a really helpful general purpose tool, I’ll pack that into a library of helper methods. I’ll then call that from another function in another library.

I don’t think I actually have any personal examples of calling a function in a loop. I intentionally avoid that design pattern. My typical pattern is 1) build a dataset via BAQ, LINQ query, or (rarely) some kind of loop 2) pass the DS to the function.

By the same token, I don’t think I have any examples of a calling a function from code. I know I’ve done it (which is why I know the link I shared works), but I’ve never kept that design around to production. It goes against the whole “you should be calling functions from widgets so all the spaghetti stays contained within said functions” mantra.

1 Like

Well I guess that makes sense. I’ll try to pass the dataset in (rather than strings). I like keeping the spaghetti where it’s supposed to be.

This was the solution as found on a different thread. You will have to cast the object to an appropriate type if you want to use it for anything.