Help

The Community will be temporarily unavailable starting on Friday February 28. We’ll be back as soon as we can! To learn more, check out our Announcements blog post.

How can I make a button to add or clear a value based on a cell conditon?

1159 1
cancel
Showing results for 
Search instead for 
Did you mean: 
dsyke
4 - Data Explorer
4 - Data Explorer

I'm currently running a script button that will copy the 'Reservation Requested By' value to 'Reserved for'  value.

 
let table = base.getTable("Status Report");
 
let record = await input.recordAsync('Reservation Requested By', table);

if (record) {
   let oldValue = record.getCellValueAsString("Reservation Requested By");
   
   let newValue = oldValue;
   output.text(newValue);
   
   await table.updateRecordAsync(record,{"Reserved for": newValue});
} else {
    output.text('');
}
 
I want to add a condition to this button so that if the 'reserved for' value is not empty, or exceeds certain days then remove the value.
 
Can I do that?
1 Reply 1
Karlstens
11 - Venus
11 - Venus

Here is one approach you could consider - we're checking if the "Reserved for" field is empty, and if it is - then we take the "Reservation Requested By" info and stamp it into the "Reserved for".

let table = base.getTable("Status Report");
 let record = await input.recordAsync('Reservation Requested By', table);

if (!record?.getCellValueAsString("Reserved for")) {
    let newValue = record?.getCellValueAsString("Reservation Requested By")
    await table.updateRecordAsync(record ,{"Reserved for": newValue});
};