function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Francesco Carmagnola 10Francesco Carmagnola 10 

Expressions in literals - Pass SObject to a aura component with dynamic field value

I've created a component which accepts as an attribute an SObject. When I simply pass a JSON SObject to it, like:
 
<c:ChildCreatorComponent obj="{
                                        sobjectType : 'Contact',
                                        LastName : 'Rossi',
                                        FirstName : 'Mario'
                                    }" />
Everything is fine. But right now, I need to pass a dynamic value (like an ID):
 
<c:ChildCreatorComponent obj="{
                                        sobjectType : 'Contact',
                                        AccountId : MY_DYNAMIC_ID,
                                        LastName : 'Rossi',
                                        FirstName : 'Mario'
                                    }" />
If I try to insert my ID with an expression, as I would do in Visualforce, I obtain an error. Example:
<c:ChildCreatorComponent obj="{
                                            sobjectType : 'Contact',
                                            AccountId : {!v.recordId},
                                            LastName : 'Rossi',
                                            FirstName : 'Mario'
                                        }" />
"Cannot mix expression and literal string in attribute value, try rewriting like {!'foo' + v.bar}: Source"

But if I do that, I am passing a String instead of an SObject to the component.
Any idea? I want to keep the simplest as possible the component attribute structure.. So I can not create other attribute for the dynamic field values.