How Can I delete cells-value in specific field

I wanna delete cells-value in Amount Field.
I am referring to this↓

but I can’t.参考にしています

I wanna just all clear Amount field Value…

help me.

//get table
let merchandiseTable = base.getTable("C_商品");
   let fieldAmount = merchandiseTable.getField("amount");
let merchandises = await merchandiseTable.selectRecordsAsync();
let merchandise = merchandises.records;
//console.log(merchandise);

//Amaount-fields value to null 
    while (merchandise.length > 0) {
        tmp = merchandise.slice(50);
        await merchandiseTable.updateRecordsAsync(merchandise.slice(50), 
            {
                id:merchandise.slice(50)
                fields: {
                    "amount": null,
                },
            },
        )

Hi,
you can use that piece
Just set you table name, and ensure that letter case is ok for “amount” fieldname.

let table = base.getTable(‘YourTable’);
let query = await table.selectRecordsAsync();
function setValue(rec){return {‘id’:rec.id,‘fields’:{‘amount’:’’}}};
let updates=query.records.map(setValue);
while (updates.length > 0) {
await table.updateRecordsAsync(updates.slice(0, 50));
updates = updates.slice(50); }

1 Like

Thank you so much!! You made it !!!

//在庫数の初期化
let table = base.getTable("C_商品");
let query = await table.selectRecordsAsync();

function setValue(rec){return {id:rec.id,fields:{amount:null}}};
let updates=query.records.map(setValue);

while (updates.length > 0) {
    await table.updateRecordsAsync(updates.slice(0, 50));
updates = updates.slice(50); }
1 Like

btw, using 50 record batch with ‘slice’ is good to show script basic for beginners.
since we have another array method ‘splice’, that delete X records and return them, we can do it in single step.
also, we can use our function not just to del, but also for copy from one field to another and whatever. like this:

let table = base.getTable('your_Table’);
let query = await table.selectRecordsAsync();
function setValue(rec){return {‘id’:rec.id,‘fields’:{‘destination’:rec.getCellValue(‘source’)}}};
let updates=query.records.map(setValue);
while (updates.length > 0) await table.updateRecordsAsync(updates.splice(0, 50));

1 Like

Thank you for additional explain.Deepen my understanding :face_with_monocle:

1 Like

This topic was solved and automatically closed 3 days after the last reply. New replies are no longer allowed.