Linked fields in datamapper


It would be nice to have option to “link” fields in datamapper so if first field change position/size (left/right offset) next field would automatically update it’s position.
Currently we have datamapper for TXT file that has ~50 fields. Our customer have nasty habit to change length of one field in txt file and we need to update all fields in datamapper one by one (Murphy law works 24/7). If they are linked … well it would be a lot easier.


There’s a way to do that:

  • In your Preprocessor step, create a new property named fldDef, with Scope set to Record and Type set to Object.

  • As your first step, add an Action step with Type set to Set Property. Select the property fldDef and set the Based on parameter to Javascript.

  • In the Javascript expression, create an array of fields that contain a start and an end value. Something like this:
    [ {s:1,e:10} , {s:12,e:36} , {s:38,e:47} , {s:49,e:55} ];
    Where for each field, s represents the starting location for that field, and e is its ending location

  • Then add an Extract step whose mode is set to Javascript and use the following code to extract a field:

    var f =[0]
    data.extract( f.s, f.e , 0, 1, "");

For each field, you just change the index of the field definition (i.e. (...).fldDef[0], (...).fldDef[1], (...).fldDef[2], etc).

That way, the next time your customer changes the length of any field, you just have to update the array accordingly. You could even pass that array dynamically from Workflow through one of the jobInfos, or you could read it from an external file in the DataMapper, that way you wouldn’t even have to make any changes to the data mapping config.

Not quite as user-friendly as your suggestion, but just as efficient! It also allows you to control the order in which you want to extract your fields, whereas the linked fields you suggested wouldn’t allow you to do that.