[SalesForce] Using force:recordData update a field that’s not present on the layout

is there a way to update what is in effect a hidden/system field when using force:recordData (ie a flag that is not displayed to the user) prior to saving the record? e.g. in the controller below i want to set the myCheckbox field to true.

Component

<force:recordData aura:id="accountRecordCreator"
                      layoutType="FULL"
                      targetRecord="{!v.newAccount}"
                      targetFields="{!v.simpleNewAccount}"
                      fields="Name,Industry,Type"
                      targetError="{!v.newAccountError}"
                      mode="New"/>
<div class="slds-form_stacked">
        <lightning:input name="name" label="Name"
                         value="{!v.simpleNewAccount.Name}" required="true"/>

        <lightning:input name="industry" label="Industry"
                      value="{!v.simpleNewAccount.Industry}" required="true"/>

        <lightning:input name="type" label="Type"
                      value="{!v.simpleNewAccount.Type}" />

        <lightning:button label="Save Account" onclick="{!c.handleSaveAccount}"
                   variant="brand" class="slds-m-top_medium"/>
   </div>

Controller

handleSaveAccount: function(component, event, helper) {
       // e.g. component.find("accountRecordCreator").myCheckbox = true;
component.find("accountRecordCreator").saveRecord(function(saveResult) {
                if (saveResult.state === "SUCCESS" || saveResult.state === "DRAFT") {
                    // handle the successful create
                } else if (saveResult.state === "INCOMPLETE") {
                    // handle the incomplete state
                    console.log("User is offline, device doesn't support drafts.");
                } else if (saveResult.state === "ERROR") {
                    // handle the error state
                    console.log('Problem saving contact, error: ' + JSON.stringify(saveResult.error));
                } else {
                    console.log('Unknown problem, state: ' + saveResult.state + ', error: ' + JSON.stringify(saveResult.error));
                }
            });

Best Answer

You should be able to set the field on the simpleNewAccount attribute:

var record = component.get("v.simpleNewAccount"),
  accountRecordCreator = component.find("accountRecordCreator");
record.myCheckbox = true;
component.set("v.simpleNewAccount", record);
accountRecordCreator.saveRecord(...);
Related Topic