Home >Tips >Excel Automation >Add an ID to the Recurring Tasks Script kalmstrom.com site map icon Site map  

Add ID in Recurring Tasks Script

An Excel tutorial by Peter Kalmström

Excel iconIn the demo below, Peter Kalmström enhances the Recurring Tasks script that he has already used in the two previous demos. Now, Peter wants to create a powerapp for the tasks that are due today, and for that each task needs to have a unique ID.

Power Apps uses ID numbers in the background to keep track of changes and unique rows in the Tasks table (which is the app's data source in this case). In the app creation process, it is possible to allow Power Apps to generate the ID numbers and add them to the table.

Peter prefers to create the ID column and its values himself, as this gives him better control over the app and Excel table. Therefore, he adds another column to the Tasks table and modifies the Recurring Tasks script to create an ID number for each task. He uses the millisecond that the task instance was added to the Tasks table as its ID value.


All steps to give each task a unique ID number are performed in Excel:
  • Add a new ID column to the left in the Tasks table. It should have Number format and not show decimals.
  • Open the AddTasks script in Edit mode.
  • Add code for ID column value after "TaskTable.addRow(null,[" in the Template class, AddAsTasks method: new Date().getTime(). This will get the millisecond included on each row in the Tasks table.
Now, the whole AddAsTasks method looks like this:

 public AddAsTask(WB:ExcelScript.Workbook){
      const TaskTable:ExcelScript.Table = WB.getTable("Tasks");
      TaskTable.addRow(null,[new Date().getTime(), this.Title,new Date().toISOString().substring(0,10),""]);
      let NewDate: Date = new Date();
      NewDate.setDate(NewDate.getDate() + this.Interval);
      this.Row.getLastCell().setValue(NewDate.toISOString().substring(0,10));
    } 

To make sure that the button is really taking the new script, Peter removes the old button and then adds the script with a button to the workbook again.

back icon next icon
Products Buy FAQ Services Tips Books Contact About Us Tools

Security and integrity

Copyright  Kalmstrom Enterprises AB  All rights reserved