Help

How Can I delete cells-value in specific field

Topic Labels: Scripting extentions
Solved
Jump to Solution
3298 4
cancel
Showing results for 
Search instead for 
Did you mean: 
111257
6 - Interface Innovator
6 - Interface Innovator

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,
                },
            },
        )
1 Solution

Accepted Solutions
Alexey_Gusev
13 - Mars
13 - Mars

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); }

See Solution in Thread

4 Replies 4
Alexey_Gusev
13 - Mars
13 - Mars

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); }

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); }

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));

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