I have an XML that contains string values like “Yes” or “No”.
It would simplify the code in my data mapper if it was possible to set the type of a field to Boolean and it would automatically recognize values like:
Yes, No, True, False (not case sensitive)
At the moment this only works with 0 and 1 where it translates properly to a true or false value.
I know this is default JavaScript behavior but now I first have to store the value in a variable and do some checks on it.
e.g.
let myvar = data.extract(‘./xpath’);
if (myvar && (myvar.toUpperCase() == “YES” || myvar.toUpperCase() == “TRUE”)) true; else false;
It would save me from going the JavaScript route and will just be able to leave the “Based on” on “Location” instead.
Not sure if this is possible as you need additional code for all booleans instead of passing it to a JavaScript engine but I still wanted to report it.
That is true but I see a trend that features in PlanetPress are designed in a way where it becomes less and less necessary to use scripts. I can use JavaScripts in the data mapper and that is what I already did.
I just was thinking of making it easier for users (and myself) where it is not necessary to create a script and for Boolean fields the system can accept values like “True”, “False”, “0”, “1”, “Yes”, and “No” and convert them properly to the right Boolean value.
Edit…note that this enhancement is not about sharing JavaScript code. It is about not having to use a script (and have the proper validations / conversions) and being able to select a boolean and have it translated properly with more values from the input than just 0 or 1.
This would actually be a bit more complex to implement than people might think. We’d have to implement the boolean conversion of “YES-NO” for all written languages (yes-no/oui-non/da-niet/si-no/ya-nein… etc.). Same for “TRUE-FALSE”.
Instead, you can simply use the Post function for your extracted field and set it to something like:
match(/true|yes|[^\D0]/i)
Here’s how it looks like in the DataMapper:
The code returns true if the case-insensitive words true or yes are in the data, or if a digit other than 0 is found. If you’ve only got English values in your data, it should work. And if you have both French and English values, for instance, then you’d amend it to:
Thank you. That is true and I had not thought of that. I do find the post function also interesting instead of using JavaScript so I will use that instead.