How to convert/ change a field to a value and to set the field name as the value in an object

The below image is an example of a flow where a Record Generator step is used as a source step.

In the Record Generator step, it is populated with a data load as per the image below.

Illustrated in the image below is the output of the data load when testing the Record Generator step.

image

The image below contains the code in the calculator step that is used to convert a field to a value and to set the field name as the value in an object.

Copy and paste the below code in your calculator step:

let inputRecord=input.record;
for (let key in inputRecord.result) {
let obj = inputRecord.result[key];

let newValue = Object.keys(obj)[0];
let newKey = obj[newValue]; // [“Field”]
obj[newKey] = newValue;
delete obj[newValue];
}

return inputRecord;

The below image is the output/ results. Highlighted are the new values that were previously fields and the fields have been set to the previous values.

image