Help

How can I update a cell value in Airscript

Topic Labels: Scripting extentions
Solved
Jump to Solution
5050 6
cancel
Showing results for 
Search instead for 
Did you mean: 
Eric_SHARMA
5 - Automation Enthusiast
5 - Automation Enthusiast

I have a field named Echeance that has date of the deadline for each project
I have a field named Statut which referres to the project status (to do, done etc…)
I want if the current date > Echeance and the status is “A faire” then update the cell to “En retard”, which means late.

let action = base.getTable('Action');
let tache = await action.selectRecordsAsync();
let aujourdhui = new Date(); // Date of today

for (let ligne of tache.records){
      let statut = ligne.getCellValue("Statut");
      
      let echeance = ligne.getCellValue("Echéance");
      let dateEcheance = new Date(echeance);

      if (dateEcheance < aujourdhui && statut["name"] == "A faire"){

            await action.updateRecordAsync(ligne, {
            'Statut': "En retard", // Here is the problem
        });
      }

}```
1 Solution

Accepted Solutions
kuovonne
18 - Pluto
18 - Pluto

Is the Statut field a single select?

If so, you need to use the write format for a single select field.

   'Statut': {"name": "En retard"}, 

You can see the write format for different field types in the documentation.

See Solution in Thread

6 Replies 6

Why not do this with a single formula? In fact, why would you do it any other way? The problem here might be in the single quotes around the ‘statut’ (I’ll have you known I even understood “ligne” and “tache” :stuck_out_tongue: ), or the fact that you are coercing your statut[""] and “A faire” types /(always use the === operator unless you specifically don’t want to do that), but it doesn’t matter - do this with a formula, then query the data when you need it from the script.

Less code = less bugs.

bonne chance

Thanks for the reply, but I really want to code this part, it’s really that little thing that is blocking me and I think it will be all fine

Ah, a desire for learning, I can understand, then definitely start from the bottom up, and try to make it a habit to always stick by one style of quotes because it’s never just the one, you’ll soon need two, and you might not want to turn them into three. I’m talking about the single quotes around action, in this instance.Those aren’t responsible for your code not running but the mindset that led to those inconsistencies will lead you to many bigger problems in the future if you don’t squash it asap.

kuovonne
18 - Pluto
18 - Pluto

Is the Statut field a single select?

If so, you need to use the write format for a single select field.

   'Statut': {"name": "En retard"}, 

You can see the write format for different field types in the documentation.

@Eric_SHARMA Did @kuovonne’s response answer your question? If so, please mark her comment as the solution to your question. This helps others who may be searching with similar questions. Thanks!

Can’t believe it was that easy, ofcourse it’s the key value format… I feel so dumb now…
Anyway thank you very much