Skip to main content
How do you set a dynamic aura attribute default value like current userinfo instead of hardcoding. See below.

The harcoding accountid works, not dynamic contactid/not supported.

 

<aura:attribute name="lookupcase" type="Case" default="{

'sobjectType': 'Case',

'ContactId': '{!v.userInfo.ContactId}',

'AccountId': '0012D000002oAkt'

}"/>

 
6 件の回答
  1. 2018年1月9日 4:02
    hi gaston, we can not set attribute default value as dynamic, you can achive this by set the attribute value by javaScript controller on component load for example :

     

    <aura:component>

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

    <aura:attribute name="lookupcase" type="Case" default="{

    'sobjectType': 'Case',

    'ContactId': '',

    'AccountId': '0012D000002oAkt'

    }"/>

    </aura:component>

    javaScript controller :

    ({

    doInit : function(component, event, helper) {

    var action = component.get("c.fetchUser");

    action.setCallback(this, function(response) {

    var state = response.getState();

    if (state === "SUCCESS") {

    var storeResponse = response.getReturnValue();

    // set current user information on userInfo attribute

    component.set("v.userInfo", storeResponse);

      // @@@@@ set default value here @@@@

      var getContactId = component.get("v.userInfo.ContactId");

      component.set("v.lookupcase.ContactId" , getContactId ) ;

    }

    });

    $A.enqueueAction(action);

    }

    })

    i hope it helps you.

          Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper solution for others

        thanks 

    http://sfdcmonkey.com  (http://sfdcmonkey.com )