Skip to main content
Solved

How Can I delete cells-value in specific field

  • August 6, 2021
  • 4 replies
  • 45 views

111257
Forum|alt.badge.img+4
  • Participating Frequently
  • 9 replies

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

Best answer by Alexey_Gusev

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

4 replies

Alexey_Gusev
Forum|alt.badge.img+25
  • Brainy
  • 1261 replies
  • Answer
  • August 16, 2021

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


111257
  • Author
  • Participating Frequently
  • 9 replies
  • August 17, 2021

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

Alexey_Gusev
Forum|alt.badge.img+25
  • Brainy
  • 1261 replies
  • August 18, 2021

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


111257
  • Author
  • Participating Frequently
  • 9 replies
  • August 20, 2021

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: