I am using force:recordData in a lightning component to get the data by passing in the Opportunity id. It works without any issues. However, I would like to change the opportunity stagename value from let's say "01-Prospecting" to just "Prospecting" by leaving out the numbers and the hyphen. The string functions I saw for the lightning components don't seem to help to get a substring out of a string.

Below is the code:

<force:recordData aura:id="recordHandler" 
                  targetFields="{!v.simpleRecord}" />

I would like to get a substring out of the {!v.simpleRecord.StageName}.

I tried using the init handler to set a different attribute with the substring from the controller method (doInit), but it seems the record data is fetched after the initialization of the component and I get null for the v.simpleRecord.

Please let me know if the question is not clear and I will try to post some examples.


1 Answer 1


You are correct that the record may not be initialized during your component's init event handler. Instead, you want to add a change handler on v.simpleRecord and perform any logic necessary when that variable changes (due to the record being loaded).

  • Thanks @dsharrison. It worked. I used another string attribute to store the substring and then display that value.
    – Karthik
    Commented Nov 22, 2017 at 16:06

You must log in to answer this question.

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