Hereby I would like to ask you the two following questions:
Does the extract field always contains a value of the same length (fifteen or four characters long) and are both values – in the shared example “10003211111” and “051” – always of the same length?
Are both values – in the shared example “10003211111” and “051” – always separated by a space?
Let’s say that you have the following three record fields “fieldOne”, “fieldTwo” and “fieldThree” whereby the Extract Mode of record field “fieldOne” is Location and the Extract Mode of the record fields “fieldTwo” and “fieldThree” are JavaScript, then you can use JavaScript code like the following for record field “fieldTwo”:
var result = "";
if (typeof record.fields.fieldOne === "string") {
if (record.fields.fieldOne.split(" ").length == 2) {
result = record.fields.fieldOne.split(" ")[0];
// For debugging purposes only:
//logger.info("fieldTwo (length): " + record.fields.fieldOne.split(" ")[0].length); // temp
}
}
result;
And you can use JavaScript code like the following for record field “fieldThree”:
var result = "";
if (typeof record.fields.fieldOne === "string") {
if (record.fields.fieldOne.split(" ").length >= 2) {
result = record.fields.fieldOne.split(" ")[1];
// For debugging purposes only:
//logger.info("fieldThree (length): " + record.fields.fieldOne.split(" ")[1].length);
} else if (record.fields.fieldOne.split(" ").length == 1) {
result = record.fields.fieldOne.split(" ")[0];
// For debugging purposes only:
//logger.info("fieldThree (length): " + record.fields.fieldOne.split(" ")[0].length);
}
}
result;
Personally, I would set both Field1 and Field2 to an empty string (via JS mode) in the Extract task.
Then I would add an Action task with the following code:
Of course, you would change the data.extract() statement to match your own data.
I’m not saying my method is better or worse than Marten’s, it’s just an alternative using record.set(). I prefer doing it this way because all the JS code is grouped in a single location.