Manipulating a non-existent field #6266
-
I've written the following function to ensure that fields don't get created in the XML out of order:
I call it with something like This works fine most of the time, but if there is no PV1.7 (e.g. PV1 only has the first 6 fields), it will fail on the I can avoid the error by inserting For the record, if I pass in a newly-created segment instead of a non-existent field,
Is there any way for this function to know how to do its job? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 13 replies
-
You could try something like this, which includes a check at the beginning to see if the field exists. If it doesn't, it creates the field and initializes the specified number of components. This ensures that the function can handle cases where the field is missing.
usage: padField(msg['PV1'], 'PV1.7', 9); <--- or whatever segment
|
Beta Was this translation helpful? Give feedback.
-
This doesn't directly answer your question, but if you plan on adding fields out of order, I'd take a look at this code template. You can add fields or components in any order you want and have it clean up for you at the end of the transformer. |
Beta Was this translation helpful? Give feedback.
Three main points -