Datamapper - how to test for empty values in the source XML file and replace with a default.

I’m using PlanetPress Connect Designer (v1.4.2) to process an XML file into a datamap. There are some sections where the data value (all strings) may be blank and, in those cases, I’d like to use a default in place of the blank.

Can I use the Postprocessor to do this? If so, could someone help me with a sample script to test for empty values and replacing them with a default value. If not, how can I achieve this?

you could add an additional data field to your data model and assign the XML field or a default value depending on the content of the original XML data; this could be done with JavaScript in an Action step.

Hi, thanks for the answer. I’m not experienced with the datamapper - could you elaborate on your answer please?

In an Action step after the Extraction you add JavaScript::

if (record.fields[‘field0’].trim().length > 0) {

record.fields[‘field1’] = record.fields[‘field0’];

} else {

record.fields[‘field1’] = ‘default content’;

}

where ‘field0’ is assumed to be the original record field you need to check and ‘field1’ is the additional field added to the data model (don’t forget to give it a default value when adding to make it usable).

The code is assigning a default string (‘default content’ in the sample above) to the custom field if the original field is empty, otherwise it’s assigning the content of the original field.

Thanks! I’ll try this out.