Error Message if I Ran the Script the Second time!

Enthusiast ,
Dec 22, 2021 Dec 22, 2021

Copy link to clipboard

Copied

Hi Experts

I wrote little Script to convert first table rows to header row, and it work good for the first time but if i ran the script again after converting every table first row to header in all tables it give an error? how i can avoid that? because if i add new tables needed to be convert their first row  it will not work again and give error!, so how i can let the script ignore the errors and continue to find any new tables needed to be convert its first table row! and thanks in advance 

//Convert Every First Table Row to Header Row
var myDoc = app.activeDocument;
var myRows = myDoc.stories.everyItem().tables.everyItem().rows[0].getElements();

for (var i = 0; i < myRows.length; i++) {
    if (myRows[i].rowType == RowTypes.BODY_ROW);
    myRows[i].rowType = RowTypes.HEADER_ROW;
}

The Error Message for the Second time

1111111111111.jpg

Best
M.Hasanain
TOPICS
Scripting

Views

90

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , Dec 23, 2021 Dec 23, 2021
The problem is with your if statement, remove the ; after the if and it will work fine. In the current state the if statement has no effect as the statement it's controlling is a blank statement denoted by a ; The line after it is executed always and hence you see the error -Manan

Likes

Translate

Translate
Adobe Community Professional ,
Dec 23, 2021 Dec 23, 2021

Copy link to clipboard

Copied

The problem is with your if statement, remove the ; after the if and it will work fine. In the current state the if statement has no effect as the statement it's controlling is a blank statement denoted by a ; The line after it is executed always and hence you see the error

-Manan

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Dec 23, 2021 Dec 23, 2021

Copy link to clipboard

Copied

@Manan Joshi 

Thanks a lot , you saved me

Best
M.Hasanain

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 01, 2022 Jan 01, 2022

Copy link to clipboard

Copied

LATEST

Also, It may not work if any cell has rowSpan greater than 1.

 

-Sumit

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines