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
Nobu.SNobu.S 

How to update sObject field value in Javascript LWC

Hello, 

I've created sample LWC to modify sObject list from UI. But when I invoke onchange event which update field value in some sObject, pop-up shows "[NoErrorObjectAvailable] Script error.".


Here is my sample code and error happens on the js line
//this.wiredAccount[idx][fname] = evt.target.value;//

Previous console.log shows properly the target field value. So I have no idea what cause the error. Could somebody teach me what is the cuase?
import { LightningElement, track, wire} from 'lwc';

import getList from '@salesforce/apex/manageAccListCtrl.getAccList';

export default class manageAccList extends LightningElement {
    @track wiredAccounts;
    @wire(getList)
        fetchAccs(result){
            this.wiredAccounts = result.data;
        } 

    chgValHandler(evt){
        var idx = evt.target.dataset.index * 1;
        var fname = evt.target.dataset.field;
        console.log("idx,fname,val:" + idx + "," + fname + "," + evt.target.value);
        console.log("wiredtarget:" + this.wiredAccounts[idx][fname]);        
        this.wiredAccounts[idx][fname] = evt.target.value;
        console.log(JSON.stringify(this.wiredAccounts));
    }

}
<lightning-card icon-name="custom:custom14" title="manage account">        
     
        <div class="slds-table--header-fixed_container">
        <div class="slds-scrollable_y" style="height: 100%;" >

        <table class="slds-table slds-table--header-fixed">
            <thead>
                <tr class="slds-text-title_caps">
                    <th scope="col"><div class="slds-truncate slds-cell-fixed">Id</div></th>
                    <th scope="col"><div class="slds-truncate slds-cell-fixed">Account Name</div></th>
                    <th scope="col"><div class="slds-truncate slds-cell-fixed">Account Number</div></th>
                </tr>
            </thead>

            <template if:true={wiredAccounts} >
                <tbody>                                            
                    <template for:each={wiredAccounts} for:item="acc" for:index="idx">
                        <tr key={acc.Id} class="slds-hint-parent">
                            <th>
                                {acc.Id}
                            </th>
                            <td>
                                <lightning-input value={acc.Name} data-index={idx} data-field="Name" onchange={chgValHandler} ></lightning-input>
                            </td>
                            <td>
                                <lightning-input value={acc.AccountNumber} data-index={idx} data-field="AccountNumber" onchange={chgValHandler}></lightning-input>
                            </td>
                        </tr>
                    </template>
                </tbody>
            </template>
        
        </table>
        </div>  
        </div>
    </lightning-card>
</template>