Hello everyone. I'm running a very simple script, that basically updates a table with values that I get from Planner. My issue is that form Planner I download the Ids, and then I run a script to convert those Ids into names and then send a message to users on teams. Issue is that I'm getting an error at that point every single time. I've seen some people with a similar issue, apparently it has to do with taking longer than 120s, however when I run the script on my pc it doesn't even take 10 seconds to run. How can I fix this?
```
And here is the script:
```
Hi @njnunes - sorry to hear you're running into this issue! I believe that scripts often take a bit longer to run through Power Automate than they would within Excel, so we can probably start by trying to optimize the code. At first glance, I'd suggest the following:
So the updated script would look like this:
function main(workbook: ExcelScript.Workbook) {
let table = workbook.getWorksheet("Datos").getTables()[0]
let rows = table.getRangeBetweenHeaderAndTotal().getRowCount() + 1;
let lookupUserRange = workbook.getWorksheet("Ids").getTable("UserIds").getRange().getValues();
let lookupBucketRange = workbook.getWorksheet("Ids").getTable("BucketsIds").getRange().getValues();
let inputAssignedRange = table.getColumn(4);
let inputCreatorRange = table.getColumn(3);
let inputBucketRange = table.getColumn(2);
let inputAssignedValues: string[] = inputAssignedRange.getRange().getValues().map(cell => cell.toString());
let inputCreatorValues: string[] = inputCreatorRange.getRange().getValues().map(cell => cell.toString());
let inputBucketValues: string[] = inputBucketRange.getRange().getValues().map(cell => cell.toString());
let tableRange = table.getRange();
for (let k = 1; k < rows; k++) {
let lookupAssignedResult = performLookupLimited(inputAssignedValues[k], lookupUserRange);
let rangeToChangeAssigned = tableRange.getCell(k, 6);
rangeToChangeAssigned.setValue(lookupAssignedResult);
let lookupCreatorResult = performLookupLimited(inputCreatorValues[k], lookupUserRange);
let rangeToChangeCreator = tableRange.getCell(k, 5);
rangeToChangeCreator.setValue(lookupCreatorResult);
let lookupBucketResult = performLookupLimited(inputBucketValues[k], lookupBucketRange);
let rangeToChangeBucket = tableRange.getCell(k, 9);
rangeToChangeBucket.setValue(lookupBucketResult);
}
function performLookupLimited(inputString: string, values: (string | number | boolean)[][]): string {
let result = '';
if (inputString == "") {
return "Nadie";
}
for (let i = 0; i < inputString.length; i += 36) {
const substring = inputString.substr(i, 36);
// Find the row index of the cell that contains the substring
let rowLookup = values.findIndex(row => row.findIndex(value => value.toString().indexOf(substring) >= 0) >= 0);
if (rowLookup >= 0) {
result += values[rowLookup][1] + ', ';
}
}
if (result.endsWith(', ')) {
result = result.slice(0, -2);
}
return result;
}
}
Let me know if that helps? If you're still running into timeout issues, would you be able to share a sample workbook and your entire flow configuration (with sensitive data removed as needed) so that we can troubleshoot in more detail?
WarrenBelz
146,524
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,906
Most Valuable Professional