Skip to main content

C4C: Reuse functions - don't forget the return parameter!

Submitted by Stefan Barsuhn on

I recently wrote a reuse function that handled all kinds of scenarios and returned different values. However, I forgot to handle the negative case, i.e. where none of these scenarios apply and no (or an empty) value should be returned.

C4C does something funny in this case: It doesn't just return a "blank" value, it returns the value of the last successful "return". 

This is especially critical in scenarios where you process multiple objects in a loop and the reuse function gets called repeatedly by the same work process (e.g. data workbench upload, MDR , inbound replication).

Example: Assume your reuse function checks a customer's classification and returns A, B or C. If you only return A, B or C, but forgets to return "blank" if the customer does not have a classification the following would happen if you upload 3 customers via data workbench and this function is triggered for all of them. Assume customer 1 has no classification, customer 2 has classification B and customer 3 has no classification. 

Expected Behaviour: Customer 1 returns blank, Customer 2 returns B, Customer 3 returns blank.

Actual Behaviour: Customer 1 returns blank, Customer 2 returns B, Customer 3 returns B

Because the return is missing, it returns the result from the last successful return (customer 2). Customer 1 works as expected because there is no "last successful" return.

Solution: Make sure you always add an explicit return to the very end of your script and return the desired default value etc.! Even if your default value is a blank string!