[SalesForce] Default field values in force:createRecord

Where am I going wrong? I am trying to make defaultFieldValues dynamic by adding a variable.

When I try this code, the fields do not default:

var strNewPhone ="{ 'Phone': '999-999-9999'}";
var createAcountContactEvent = $A.get("e.force:createRecord");
    createAcountContactEvent.setParams({
        "entityApiName": "Contact",
        "recordTypeId" : selectedRID,
        "defaultFieldValues"    : strNewPhone  
    });

when I try the below snippet, it works:

var createAcountContactEvent = $A.get("e.force:createRecord");
    createAcountContactEvent.setParams({
        "entityApiName": "Contact",
        "recordTypeId" : selectedRID,
        "defaultFieldValues"    : {
         'Phone' : '999-999-9999'
}  
    });

Best Answer

The issue you are facing is due to the fact that you are defining strNewPhone as a String (its value is enclosed by double quotes).

You should define it as an Object:

var strNewPhone = { Phone: '999-999-9999'};