0
[
  {
    "dataType": "BOOLEAN",
    "name": "checkbox_confidential",
    "isCollection": false,
    "flowName": "FlowData",
    "value": true,
    "objectType": null
  },
  {
    "dataType": "BOOLEAN",
    "name": "checkbox_password",
    "isCollection": false,
    "flowName": "FlowData",
    "value": false,
    "objectType": null
  },
  {
    "dataType": "BOOLEAN",
    "name": "checkbox_restriction",
    "isCollection": false,
    "flowName": "FlowData",
    "value": true,
    "objectType": null
  },
  {
    "dataType": "DATEONLY",
    "name": "date_dateReq",
    "isCollection": false,
    "flowName": "FlowData",
    "value": "2022-10-30",
    "objectType": null
  }]

I am getting the above JSON from the flow to LWC. I am capturing the above Json to a variable called outputVariables from event.detail;

let { outputVariables, status } = event.detail;
_searchOutputVariables = ['checkbox_restriction','date_dateReq'];

const result = outputVariables.filter(outvar => outvar.name == "checkbox_restriction");
  if(result != undefined && result.length > 0){
     this.restrictionLocal = result[0].value;
  }

I am trying to get the value by passing each variable like the above. But my lead wants me to create an array and add all the filter text and pass to the filter function. I create an array '_searchOutputVariables'. how to use that array in filter function? please help me to do this?



1 Answer 1

0

It is pretty easy:

const outputVariables = [
  {
    "dataType": "BOOLEAN",
    "name": "checkbox_confidential",
    "isCollection": false,
    "flowName": "FlowData",
    "value": true,
    "objectType": null
  },
  {
    "dataType": "BOOLEAN",
    "name": "checkbox_password",
    "isCollection": false,
    "flowName": "FlowData",
    "value": false,
    "objectType": null
  },
  {
    "dataType": "BOOLEAN",
    "name": "checkbox_restriction",
    "isCollection": false,
    "flowName": "FlowData",
    "value": true,
    "objectType": null
  },
  {
    "dataType": "DATEONLY",
    "name": "date_dateReq",
    "isCollection": false,
    "flowName": "FlowData",
    "value": "2022-10-30",
    "objectType": null
   }
 ];
 
const _searchOutputVariables = ["checkbox_restriction", "date_dateReq"];

const result = outputVariables.filter(node => {
  if (_searchOutputVariables.includes(node.name))
    return node;
});

console.log(result);

Sign up to request clarification or add additional context in comments.

2 Comments

Hi Thomas, thanks a lot for your help. I just started learning Javascript. one more question, How to get only the value by passing array of names?
@Lakshmi let result = []; outVar.forEach(o => { if (arrayOfNames.includes(o.name)) result.push(o.value); }); will give u a result array of "values". Happy to help! Consider voting for the answer if you like it :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.