I figured, I'd start the blog off with my favorite extended rule of all time, the messagebox().
This powerful, yet widely overlooked, extended rule, can help you with many different scenarios.
It is often part of my first response, when someone asks me a question.
Why is my field writing out the wrong data? - Did you messagebox the variable, to see where it picked up the bad data?
Why isn't my IF statement working? - Did you messagebox the values to see what they contained?
Why is my temp group not writing out all iterations? - Did you messagebox the indexes?
I could go on and on, but you'd probably hit the back button, if you haven’t already.
For GSW (Sterling Gentran:Server for Windows), the messagebox will pop up an actual box to the screen. While the messagebox is on the screen, the translation is paused. Based on the 2nd parameter you use, different buttons will be available (such as OK, Yes, No, Cancel etc.), and can return different values back to the translator. But for now, we'll focus on just displaying values.
For SI (IBM Sterling B2B Integrator), the messagebox will write to the tx.log, and does not show on the screen.
(Stay tuned to the end of this blog entry, to get the super secret way to see the values easier!)
Using messagebox() is easy, you just pass it a string and the number 0 for the 2nd parameter (again, GSW can take values other than 0).
The string can either be a string variable or a #field name.
A lot of people get discouraged, when trying to use the messagebox(), because they’ll simply display the value. With SI especially, seeing a bunch of values show up in a log, isn’t that helpful. The secret, is to add literals to a string, and combine values into one line.
msg = "";
msg = "First field: "+#fielda+" Second field: "+#fieldb;
(Note the spaces within the quotes, for easier readability)
Assuming you had 2 fields in your map named fielda and fieldb, and they contained the data ABC and 123 respectively, your message would show up as:
First field: ABC Second field: 123
This is a lot more helpful, especially when looking thru logs, and the possibilities are wide open to all that you want to combine into 1 message. They can also help vent frustrations, when a rule is giving you trouble. I’ve been known to add messages like:
msg = "WHY IS VARIABLE store no: "+store_no+" WHEN IT SHOULD BE 1234?!";
(Yes, it’s those little things, that entertain me…)
One limitation with messagebox() (hey, pobody’s nerfect!) is that it can only use strings. So, any numeric or date values, that you want to peek into, have to be converted. But we can use the same logic with them. I use this a lot with indexes, when loops are not writing out correctly:
String str_x, str_y;
msg = "";
x = "";
y = "";
$Temp[x][y].#temp_field = #fielda;
msg = "Stored: "+#fielda+" into: ["+str_x+"]["+str_y+"]";
This would give a message such as:
Stored: ABC into: 
Usually, if you’re storing into a temp with indexes, there would be multiple lines, so this becomes helpful when you see a number get skipped, or the child not resetting correctly. Then you can narrow it down as to what’s causing the index not to have the correct value.
I could go on for days with examples. If there’s something that you would like to see more information on, leave a comment, and we can do an entry specifically for it!
Now, for the super secret, SI “I hate combing thru the logs to find my messages” way.
With the addition of SWIFTNet support a few versions back, you can use the cerror() extended rule instead of messagebox(), just switch the order of the parameters.
Whatever number you put for the first parameter, will be the “error number” that shows up in the translator report. I use this to my advantage, when I add multiple cerrors, I use unique numbers in each, so I know which cerror was executed.
This will display the message right in the translator report.
Section: INPUT Severity: ERROR
SyntaxSpecific: false Syntax: -1 Code: 1
10004: Field Name
Field 1: ABC
10019: Location Index
Code:, will show the number that you included, and if it’s a “real” error number, will show the description for that error. I like to use single digits, so I can tell them apart from real errors.
10004: Field Name, will show the string below it. In this case Field 1: ABC is the output from my msg variable.
Cerror() is real handy, but does have the limit of the number of errors that will show up in the translator report. Also, it does cause an actual error to show up in the translator report. This is fine for maptest, but if you’re testing an entire BP flow, it would cause an error.
Overall, learn to embrace the messagebox() and it will make your mapping life that much easier.
Thanks for reading!
Pat Frey – IBM Support