0

I have a component in my first flow screen that shows a list of objects I created using a wrapper class in Apex. The four fields on this object are modelNo, Description, StockOnHand, and Quantity.

I have to enter a value into Quantity and pass the Description and Quantity value from this screen, to a new component in the next screen.

Here's where I am running into problems:

  1. lightning:AvailableForFlowScreens doesn't allow me to have an aura:attribute with a type of either "List" or "Object[]"
  2. The Description field has a comma in the value, which is making it difficult for me pass the string in a CSV format.

What I am trying to achieve is:

  1. If my "object" were to be:

{ "Description":"Cooler, 2 Door" , "Quantity": 2 }

I want to then create 2 rows in a datatable that each have the same description. If the quantity value was 4, then I'd want to create 4 rows with the same description. This is so that I could set a value (Branding) for each cooler independently in the datatable in the next screen. (I then go on to create the individual records.)

Here's my code from my controller for the first screen. (pardon the mess in my .push line, but this is where i am falling apart). It seems I am formatting the string incorrectly, because although I can display it as a string, I am struggling to access the values and do anything with them:

handleClick : function(component, event, helper){ var response = component.get("v.equipmentList"); var newList = []; response.forEach(myFunction); function myFunction(item){ if (item.Quantity > 0){ newList.push('Description' + ':' + '"' + item.Description + '"' + ',' + 'Quantity' + ':' +item.Quantity ); console.log(newList) component.set("v.selectedEquipmentList", newList); } } },

1 Answer 1

0

In the worst case scenario, you could just serialize the object, then store that:

var response = component.get("v.equipmentList");
var newList = component.filter(row => row.Quantity > 0);
component.set("v.selectedEquipmentList", JSON.stringify(newList));

In the next component, you'd have to deserialize it again.

3
  • sfdcfox! Always to the rescue!
    – danmwendo
    Jan 17, 2020 at 0:40
  • What if i need to add multiple objects to the list? Would i be able to do it with the above? Or would I need to do a .push?
    – danmwendo
    Jan 17, 2020 at 0:41
  • @danmwendo Array.filter returns a list with the elements that match. You'll want to read up about arrays on MDN.
    – sfdcfox
    Jan 17, 2020 at 0:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .