We have a flow that takes a raw text file as an input (a list of accounts and statements), and a process that then datamaps this and formats it onto letterheaded stationary for output.
I’m trying to add a new field that picks up a value at a specific location in the input text (always in the same place, so no issues there) and then determine an output value based on some simple logic. Basically, there are only five possible values that can be detected in the input, and I’d just like the output to be something specific depending on what that input value is.
I think I’ve got most of it working, in that I’ve created a new field, it’s correctly picking up the data I want from the right location in the source documents, and capturing that. I’ve also set up a script with a handful of ‘if’ clauses to identify the input text value, and determine what the output value needs to be:
var field, result = “”;
field = record.fields[“Depot”];
if (field == “Trafford Park”) result = “Depot 2”;
if (field == “Shortwood Business Park”) result = “Depot 3”;
if (field == “Waterglade Industrial Est”) result = “Depot 4”;
if (field == “Hainge Park”) result = “Depot 5”;
if (field == “Kingsland Business Park”) result = “Depot 9”;
results.html(result);
What I’d like to be able to do, is reference this new value (the ‘depot’ value above) in the output mappings, by calling the field as meta data. When I do this though (adding the field as Meta data in the Job Creation settings), it only contains the original value (what was on the input data), not the amended value (assigned via my script). If I add the field to the output template itself, the value correctly shows that assigned by the script however.
I’m clearly missing a step here, can anyone point me in the right direction?
You need to create a new field in the datamapper and set its value using the java script.Then use the new field name in the output mapping by calling the field as meta data which will pick up the updated value. The script in designer will not be able to update the value of the existing datamapper field, hence you will need to create a new field and set its value using the script.
Thanks for your reply - apologies if I’m being a bit thick, but I can’t see how to create or set java script from the DataMapper.
All I have on screen within the DataMapper is the Settings / Steps window, the Text Viewer window and the Data Model window (see screenshot below). I’ve been able to create the Depot field in the Data Model, and assigned the relevant section of text to it from the Text Viewer, but can’t see where I can define any script on it.
You add a new blank field to either a current extract step or a new extract step. This field obviously needs to be added after you captured the Depo field. By default this new blank field’s, which I called JavaField, mode will be set to JavaScript. In the Expression box is where you write your code. See below test data config, I think it is what you are after.
In the DataMapper, under the step properties pane, select the Field and in the Based on drop down as Javascript instead of Location.
and apply the java script for the field. Below is the sample script for your reference:
let field = record.fields[“Depot”];
if (field == “Trafford Park”) “Depot 2”;
if (field == “Shortwood Business Park”) “Depot 3”;
if (field == “Waterglade Industrial Est”) “Depot 4”;
if (field == “Hainge Park”) “Depot 5”;
if (field == “Kingsland Business Park”) “Depot 9”;
Hope this helps. Please let us know in case of any queries.
Many thanks for that, that did exactly what I needed! I’ve incorporated that into my datamapper now and it’s working just fine. Much appreciated.
Thanks too to Meena, your input pointed me in the right direction. I had somehow managed to hide / lose the Step Properties pane, took me a while to figure that out!
Glad I could help. FYI, if you lose one of your panes again it is easier sometimes to just reset the designers UI. This can be done via Window -> Reset Perspective.