Force Error in Execute Datamapping Operation

Is there a way to force an error in the Datamapper for the purpose of managing the error in Workflow.

For instance, I would like the datamapper to throw an error when a specific condition is met either in an Action step or in the Condition step. This should then in turn force the Execute Datamapping plugin in Workflow to error and I can then use the On Error tab to alert the control team.

The whole file should not process if a single record is invalid or does not meet specific conditions. I found a way to stop processing the current record, but I need it to stop the whole datamapping operation and throw an error that can be exploited in Workflow

I tried using the standard the javascript try\catch\throw but this doesn’t force the datamapping step in Workflow to error.

Any ideas?

You could set the Output type of the Execute Data mapping step to either Output records to Metadata or Output results in XML data file and setup a conditional script that would look for the presence or absence of what you are looking for.

In your Datamapper config, add an Action Step with JavaScript code that throws an error whenever some condition is met. For instance:

if((data.extract(59,80,2,1,"").indexOf("BAD RECORD"))>=0){
	throw "SOME ERROR";
}

Then in Workflow, run the DataMapper task but tick the “Validate only” option. This will go through the entire file without extracting anything and will store in the metadata all the documents in which the error was encountered. In each metadata Document node, you will have the error message and the index of the record in which it occured.

If there are no errors, then you can run the DataMapper for real, if not, then you can do whatever error processing you need based on the information in the metadata.

1 Like

Thanks Phil, this is interesting. I will give it a go. Many thanks.

@Phil can you do the validate only option when calling via API?

Yup. Just add ?validate=true to the endpoint. The return value will be different. See the API online help for more details.

1 Like