Forum Discussion
If you have the liberty to restructure your test.expr expression library file, I would recommend moving to the match control operator syntax for reduced code and simpler reference. For the test.expr file, you could change it to:
{
"main": cm => match cm {
"T" => "",
"100000" => "9999",
"200000" => "",
_ => ""
}
}
After, you can use a simpler reference:
lib.test.main($CM)
However, if you can’t make a major change to the structure for some reason, but can adapt it to an arrow function, you can incorporate bojanvelevski’s suggestion in the expression library and still use the simpler lib.test.main($CM)
reference. The file might look something like this:
{
"main": (cm =>
[
{
"CM": "T",
"TM": ""
},
{
"CM": "100000",
"TM": "9999"
},
{
"CM": "200000",
"TM": ""
}
].filter(x=> x.CM==cm)[0].TM)
}
There are other restructuring options, as well.
- jervin5 years agoNew Contributor III
Thank you @Spiro_Taleski. That would work, but I also need to run the Data Validator snap on other fields as well.
I have managed to work around the issue for now by using a Conditional snap before the Data Validator that checks for null values in the $DOB field and transforms them to an empty string ‘’. Then use the this regex that matches either an empty string or the date: ^$|\d{1,2}/\d{1,2}/\d{4}$
- del5 years agoContributor III
While the Conditional snap may work in this case, I would also recommend looking at the Mapper snap with the following $.get expression as an alternative for the same:
(Note: Pass through is checked so that the only fields you need to concern with are those you need to run through the validator as a string.)
I don’t know that it’s a huge benefit, but it seems cleaner/easier to me and it allows for additional transformations/mappings on other fields in the same snap.
Helpful tip: In this forum, you can use the
icon to encapsulate code to preserve formatting
^$|\d{1,2}/\d{1,2}/\d{4}$
- jervin5 years agoNew Contributor III
There is supposed to be a dollar sign $ after the caret ^ symbol in the regex above. Somehow it gets filtered out of the post.