Highlighted

Syntax error with if Then under withWriteAccessDo

Explorer ,
Jun 27, 2020

Copy link to clipboard

Copied

So I have a syntax error somewhere, and after hours of chasing it, I am asking for help. 

I am creating keywords in a heirarchy based on input from a dialogue. The following code yields an error : '=' expected near 'keywordAdd'    and references the line 

If keywordAdd == 'Secondary' then

Here is the rest of the snippet

            local photo = sourceRendition.photo
            local keywordAdd = propertyTable.keyword_list
			
            -- Write to the catalog
			catalog:withWriteAccessDo( 
                    'Add Keywords',
                    function(context) 
                        local keywordTop = catalog:createKeyword( 'Top', nil, false, nil, true )
                        local keywordSec = catalog:createKeyword( 'Secondary', nil, false, keywordTop, true )
                    If keywordAdd == 'Secondary' then
                        photo:addKeyword( keywordSec )
                    else
                        local keywordAdd = catalog:createKeyword( propertyTable.keyword_list, nil, false, keywordSec, true )
                        photo:addKeyword( keywordAdd )       
                    end
                  end
                )

 

When I remove the If then, the code functions as expected, but not desired as the heiarchy ends up like Top>Sec>Sec, instead of Top>Sec. So this code works: 

            local photo = sourceRendition.photo
            local keywordAdd = propertyTable.keyword_list
			
            -- Write to the catalog
			catalog:withWriteAccessDo( 
                    'Add Keywords',
                    function(context) 
                        local keywordTop = catalog:createKeyword( '_CopyRight', nil, false, nil, true )
                        local keywordSec = catalog:createKeyword( 'Published', nil, false, keywordTop, true )
--                    If keywordAdd == 'Published' then
--                        photo:addKeyword( keywordSec )
--                    else
                        local keywordAdd = catalog:createKeyword( propertyTable.keyword_list, nil, false, keywordSec, true )
                        photo:addKeyword( keywordAdd )       
--                    end
                  end
                )

 

What am I missing? TIA

Most Valuable Participant
Correct answer by johnrellis | Most Valuable Participant

You mention "syntax error", which usually means that the code can't even be executed because the code can't be parsed according to the language's strict grammar rules, and the parser/compiler returns an error.  In your code fragments above, you've misspelled the keyword "if" as "If" (capital I). Is that in fact in your code? Are you getting a syntax error when you try to load the plugin and execute it?  What's the error message?

 

[Use the blue reply button under the first post to ensure replies sort properly.]

Topics

SDK

Views

46

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

Syntax error with if Then under withWriteAccessDo

Explorer ,
Jun 27, 2020

Copy link to clipboard

Copied

So I have a syntax error somewhere, and after hours of chasing it, I am asking for help. 

I am creating keywords in a heirarchy based on input from a dialogue. The following code yields an error : '=' expected near 'keywordAdd'    and references the line 

If keywordAdd == 'Secondary' then

Here is the rest of the snippet

            local photo = sourceRendition.photo
            local keywordAdd = propertyTable.keyword_list
			
            -- Write to the catalog
			catalog:withWriteAccessDo( 
                    'Add Keywords',
                    function(context) 
                        local keywordTop = catalog:createKeyword( 'Top', nil, false, nil, true )
                        local keywordSec = catalog:createKeyword( 'Secondary', nil, false, keywordTop, true )
                    If keywordAdd == 'Secondary' then
                        photo:addKeyword( keywordSec )
                    else
                        local keywordAdd = catalog:createKeyword( propertyTable.keyword_list, nil, false, keywordSec, true )
                        photo:addKeyword( keywordAdd )       
                    end
                  end
                )

 

When I remove the If then, the code functions as expected, but not desired as the heiarchy ends up like Top>Sec>Sec, instead of Top>Sec. So this code works: 

            local photo = sourceRendition.photo
            local keywordAdd = propertyTable.keyword_list
			
            -- Write to the catalog
			catalog:withWriteAccessDo( 
                    'Add Keywords',
                    function(context) 
                        local keywordTop = catalog:createKeyword( '_CopyRight', nil, false, nil, true )
                        local keywordSec = catalog:createKeyword( 'Published', nil, false, keywordTop, true )
--                    If keywordAdd == 'Published' then
--                        photo:addKeyword( keywordSec )
--                    else
                        local keywordAdd = catalog:createKeyword( propertyTable.keyword_list, nil, false, keywordSec, true )
                        photo:addKeyword( keywordAdd )       
--                    end
                  end
                )

 

What am I missing? TIA

Most Valuable Participant
Correct answer by johnrellis | Most Valuable Participant

You mention "syntax error", which usually means that the code can't even be executed because the code can't be parsed according to the language's strict grammar rules, and the parser/compiler returns an error.  In your code fragments above, you've misspelled the keyword "if" as "If" (capital I). Is that in fact in your code? Are you getting a syntax error when you try to load the plugin and execute it?  What's the error message?

 

[Use the blue reply button under the first post to ensure replies sort properly.]

Topics

SDK

Views

47

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
Most Valuable Participant ,
Jun 27, 2020

Copy link to clipboard

Copied

You mention "syntax error", which usually means that the code can't even be executed because the code can't be parsed according to the language's strict grammar rules, and the parser/compiler returns an error.  In your code fragments above, you've misspelled the keyword "if" as "If" (capital I). Is that in fact in your code? Are you getting a syntax error when you try to load the plugin and execute it?  What's the error message?

 

[Use the blue reply button under the first post to ensure replies sort properly.]

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
Reply
Loading...
Explorer ,
Jun 27, 2020

Copy link to clipboard

Copied

Yes that is my code, and I get the following in the Plugin manager -
error : '=' expected near 'keywordAdd'   

 

I think you may have indentified what I have been staring at and not seeing. If instead of if. 

 

I will check it and see. Thanks

 

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
Reply
Loading...
Explorer ,
Jun 27, 2020

Copy link to clipboard

Copied

Yep, that was it.....many hours later. 

I should have posted this last night, but I kept thinking it would become obvious over time

Sometimes another set of eyes is needed. 

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
Reply
Loading...
Most Valuable Participant ,
Jun 27, 2020

Copy link to clipboard

Copied

...or sleep. 😆 

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
Reply
Loading...