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
k2018123k2018123 

saving a record on change of value

Hi,
I the component , i have created a field with the following code:
<lightning:input aura:id="field" label="Receipt Number" placeholder="Receipt Number" required="true" />
The field needs to be saved in a record with record id  = record.recordid. I am able to get the record.recordid .
I have created a save button with the following code:
<lightning:button label="Save and Close"
                                              aura:Id="saveBtn"
                                              iconPosition="left"
                                              variant="brand"
                                              onclick=""
                                              >
                            </lightning:button>

I want the receipt number to be updated to the record "record.recordid" whenever i click on save button. Can anyone please tell me how to acheieve this? A sample code will be really helpful
Best Answer chosen by k2018123
Narender Singh(Nads)Narender Singh(Nads)
Hi,
If you want to create a sObject record from a record then the first thing you need to do is create an attribute of that record in your component, like this():
<aura:attribute name="ReceiptNumber" type="number"/>

<lightning:input aura:id="field"  label="Receipt Number" type="number" value="{!v.ReceiptNumber}" />

//Now creating lightning button to save the record

<lightning:button label="Save and Close"
                                              aura:Id="saveBtn"
                                              iconPosition="left"
                                              variant="brand"
                                              onclick="{!c.SaveRecord}"
                                              />
//SaveeRecord will be function of your JS controller which will be called when button gets clicked.
In this function you will get the value of ReceiptNumber attribute using component.get("v.ReceiptNumber"). Now you can use that value anyhow you want in your logic.

Let me know if it helps.
Thanks!             

All Answers

Narender Singh(Nads)Narender Singh(Nads)
Hi,
I am having a little trouble understanding you request.
Can you elaborate using an example?
 
k2018123k2018123
Hi Narender,

i have created a input field to capture the receipt number from the component. the want to store that value in the record on click of save button. 
i want a sample code for it

 
Narender Singh(Nads)Narender Singh(Nads)
Hi,
If you want to create a sObject record from a record then the first thing you need to do is create an attribute of that record in your component, like this():
<aura:attribute name="ReceiptNumber" type="number"/>

<lightning:input aura:id="field"  label="Receipt Number" type="number" value="{!v.ReceiptNumber}" />

//Now creating lightning button to save the record

<lightning:button label="Save and Close"
                                              aura:Id="saveBtn"
                                              iconPosition="left"
                                              variant="brand"
                                              onclick="{!c.SaveRecord}"
                                              />
//SaveeRecord will be function of your JS controller which will be called when button gets clicked.
In this function you will get the value of ReceiptNumber attribute using component.get("v.ReceiptNumber"). Now you can use that value anyhow you want in your logic.

Let me know if it helps.
Thanks!             
This was selected as the best answer
k2018123k2018123
Hi Narender,

The record id which whom i want to bind thid value is in app.id .  How do i use it in JS controller logic to bind the value to specific record?
 
Narender Singh(Nads)Narender Singh(Nads)
It's better if you show me your code(both component and JS controller), I can't understand anything like this.