2

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'
}  
    });
3
  • What do you mean by fails? It fails to compile? it fails to run? it gives any error? or logic doesnt work? Commented May 14, 2018 at 13:11
  • Have you tried, var strNewPhone ={ 'Phone': '999-999-9999'} --> without the double quotes? Commented May 14, 2018 at 13:13
  • @PranayJaiswal: By Fails I mean the phone number do not default.
    – user45906
    Commented May 14, 2018 at 14:32

1 Answer 1

5

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'};
1
  • Thanks POZ! As suggested by @the_phantom and you, I was setting it as a string. It should be an object. Updated code: This works var strNewPhone ={'Phone': '999-999-9999'};
    – user45906
    Commented May 14, 2018 at 14:53

You must log in to answer this question.

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