#Dataflow Automation - Manipulating Each Value in a Record
Have you needed to format every value in a record? Do you want to apply the change to every value except a select few fields? With the following solution both challenges can be solved with a few easy steps.
First, from your RecordSet that will house the transformed data, copy/paste the following Javascript in the Transform Code text area:
// EDIT HERE: List of fields to exclude
var fields_to_skip = 'PARENT_PAGE_ID,PARENT_ELEMENT_ID';
var tmpObj = record;
var returnObj = {};
//Function to check if field(s) Exist
function doesContain(key) {
var split = fields_to_skip.split(",");
var returnThis = false;
for (var i = 0; i < split.length; i++) {
if (key.indexOf(split[i]) > -1) {
returnThis = true;
}
}
return returnThis;
}
//Loop through all keys and values
for (var key in tmpObj) {
//Check if Key is Found
if (doesContain(key)) {
//Do Nothing
} else {
if (tmpObj[key] == null) {
returnObj[key] = tmpObj[key];
} else {
// EDIT HERE: Statement(s) to transform the value
returnObj[key] = tmpObj[key].replace(/_/g, ' ').toUpperCase();
}
}
}
Next, there are two changes that likely need to be made to the pasted code. Adjust the fields_to_skip variable to whitelist fields that are to be ignored. Any field named in the comma-separated list will not be included.
Now, write the Javascript appropriate for the change(s) you wish to make. In the given example, each value will have spaces replaced by underscores and all letters will be capitalized.
The final step is to return the newly created JSON array. To do this, type the following in the Transform Return text field:
returnObj
This solution provides a flexible mechanism for modifying values in only the fields you want. That solution can be transferred to another project or modified for specific needs.
Please sign in to leave a comment.
Comments
0 comments