Testing for numeric or nil values in form template
I have a form where I need to perform a calculation on the "UnitPrice", which is passed in the XML. Normally, this works fine. There are some cases, however, where pricing is supressed. In these cases, the UnitPrice comes over nilled:
<UnitPrice xsi:nil="true"/>
This causes an error in the form and will not generate. I had tried, with no success, to come up with a way to handle this previously in XPath. I finally gave up and waited for the new scripting functionality to be release, but I cannot seem to come up with a way to do this in scripting, either. Any thoughts on how to perform this calculation only if UnitPrice has a valid numeric value?
As a side note, while working this issue, I did come across what I believe to be a bug in the scripting engine, and I have opened a ticket. The issue is with the "length" function, which is a documented, supported function.
length("abc") returns a 3 as expected
length("ab3") also returns 3 as expected
length("123") will throw an error (Yes, it is a number, but it is being presented a string, in quotes, that just happens to be a number).
length("1.23") will also throw an error
Best Answer
-
I don't really have any control of the XML, as it is coming straight out of the ERP application. (Baring writing some sort of extension to the print process, which is beyond my pay grade.
I've actually was able to come up with a working solution via the scripting in the new Word Addin, though it's a bit kludgy. I can clean it up a bit if they fix the above-mentioned bug. It does work for now.
1
Answers
-
Did you try the following? From the IDM output addendum:
Hiding Blank Values
To hide blank or empty values, update the xpath and add the condition not equal to ‘’
Ex. VFRQTY[.!=’’]
/M3OutDocument/DataArea/Document/DocumentTotal/VFRQTY[.!=’’]0 -
Simply hiding it didn't work, as it still apparently still tries to perform the calculation, even if the value will be hidden.
0 -
Yeah, you're not going to be able to perform a calculation if the value is null.
Have you considered performing the calculation in the XML as a virtual field, instead of in the xpath?0