0

I'm working on an existing component that was passed on to me, and it stores some information in a map attribute type

<aura:attribute name="acct" type="Map" />

At one point, address information and name information gets populated into this map attribute type, and I need to be able to populate that information in an aura "String" type attribute.

The goal would be to have {!v.acct.address}, {!v.acct.phone}, {!v.account.name} to be stored in 3 individual String variables so that the information can be easily referenced in a Salesforce Flow.

4
  • What type of values are put in the map? Likewise, what's the process here - is a user entering info on an aura component that is later going into a flow? Commented Sep 25, 2019 at 1:18
  • @KrisGoncalves someone wrote a component that grabs a business address location and business name from google maps but its stored in a map. I'm building a flow and need that information into the flow
    – Stvvn
    Commented Sep 25, 2019 at 1:20
  • How is it stored in the map? In terms of key-value pairing or if you have an example of a console output of a map in that component. I'm assuming the address/phone/name is all in that map? Commented Sep 25, 2019 at 1:25
  • @KrisGoncalves I'll be able to provide an example tomorrow morning, buy yes address/phone/name is all in the same map.
    – Stvvn
    Commented Sep 25, 2019 at 1:35

1 Answer 1

2

You can have change handler on acct attribute so that whenever acct changes you can invoke a JS method load local field values. BUT because it is a Map type (type of javascript object), the change handler does not trigger without explicitly setting the acct - component.set("v.acct", account) in parent component (which somebody implemented).

You can implement as below in your component:

COMPONENT:

<aura:attribute name="acct" type="Map" />
<aura:attribute name="accPhone" type="String" />
<aura:attribute name="accName" type="String" />

<aura:handler name="change" value="{!v.acct}" action="{!c.loadAccountFields}" />

CONTROLLER:

loadAccountFields : function(component, event, helper) {
    let acct = component.get("v.acct");
    component.set("v.accPhone", acct.Phone); // Phone should be exact property in acct - Case SenSiTiVe
    component.set("v.accName", acct.Name);
}

If you are getting acct on load itself, then you can also use init handler:

<aura:handler name="init" value="{!this}" action="{!c.loadAccountFields}" />

You must log in to answer this question.

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