2

I am trying to prepopulate a field on record creation.For this,I have created Lightning component and a controller.

Lightning component code:

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    <lightning:button label="Create an application" 
        onclick="{!c.createRecord}" />
</aura:component>

Controller:

({
   createRecord: function(component, event, helper) {
      var createRecordEvent = $A.get("e.force:createRecord");
      createRecordEvent.setParams({
         "entityApiName": "Application__c" 
          "defaultFieldValues": {
        'Name' : 'System Number',
        }
      });
      createRecordEvent.fire();
   }
})

But on saving controller,it throws the error:

Failed to save CreateapplicationrecordController.js: ESLINT_ERROR: {c:Createapplicationrecord - CONTROLLER} line:col [6:11] --> Parsing error: Unexpected token "defaultFieldValues" : Source

Name in defaultfieldvales is the API name of a standard field labelled as Number. Data type is Text.

Please help with this error.

1
  • I have created a button in lightning component which calls lightning controller.Once that button is clicked,a create record page is displayed with pre populated field values.Is it possible to display a create record page with pre populated values as soon as lighting component i.e. without clicking button in lightning component
    – devsfdc
    Commented Oct 17, 2017 at 10:10

1 Answer 1

6

You missed a comma and had an extra one:

({
    createRecord: function(component, event, helper) {
        var createRecordEvent = $A.get("e.force:createRecord");
        createRecordEvent.setParams({
            "entityApiName": "Application__c",
            // was missing in above line, so added one
            "defaultFieldValues": {
                'Name' : 'System Number'
                // removed comma from above line
            }
        });
        createRecordEvent.fire();
    }
})

enter image description here

5
  • Yeah,it got saved! I am very new to lightning and not familiar with syntax.Thanks!!
    – devsfdc
    Commented Oct 17, 2017 at 7:58
  • JavaScript fails silently and is bit difficult to debug in lightning. But eventually it would get easy with time :)
    – Raul
    Commented Oct 17, 2017 at 8:08
  • I have created a button in lightning component which calls lightning controller.Once that button is clicked,a create record page is displayed with pre populated field values.Is it possible to display a create record page with pre populated values as soon as lighting component i.e. without clicking button in lightning component
    – devsfdc
    Commented Oct 17, 2017 at 10:11
  • Kindly post a new question for something new, otherwise it would be hard to follow when other people look at this having similar issue.
    – Raul
    Commented Oct 17, 2017 at 10:33
  • OKay..I am going to post a new question.Marking your answer as accepted
    – devsfdc
    Commented Oct 17, 2017 at 10:36

You must log in to answer this question.

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