i just noticed our LUA script not always works.
the script is
if string.find(string.lower('%PathName'), '/gct/3. booking token applied/') then
do something
en
for example, when the file is D://WFTP/Data/GCT/3. Booking token applied/a) Customer sample with booking ticket/Gold Class Hopper BRT Token 27-11-2020.xlsx, i can see an error 'Failed to execute lua script of event'
i initially though that was because of '-', but other files with '-' seem to be fine when in other folders.
An ideas?
problem with %PathName, %FileName in LUA
-
- Posts: 10
- Joined: Mon Nov 02, 2020 5:58 am
Re: problem with %PathName, %FileName in LUA
or maybe there's a length limit of %PathName can return?
-
- Site Admin
- Posts: 2084
- Joined: Tue Sep 29, 2009 6:09 am
Re: problem with %PathName, %FileName in LUA
I just tested with your script in the event "OnFileUploaded", everything is OK. Is it because that you missed a character "d" in the end? It should be:
Code: Select all
if string.find(string.lower('%PathName'), '/gct/3. booking token applied/') then
...
end
-
- Posts: 10
- Joined: Mon Nov 02, 2020 5:58 am
Re: problem with %PathName, %FileName in LUA
that was just not pasted from the code.
-
- Site Admin
- Posts: 2084
- Joined: Tue Sep 29, 2009 6:09 am
Re: problem with %PathName, %FileName in LUA
OK, so I think the error was caused by the code after "then", please check it.
-
- Posts: 10
- Joined: Mon Nov 02, 2020 5:58 am
Re: problem with %PathName, %FileName in LUA
after massive tests i think it's string.find and string.match don't like ')' in the strings.
for example:
if string.find(string.lower('%PathName'), '/gct/3. booking token applied/') then
do something
end
this is fine, but
if string.find(string.lower('%PathName'), '/gct/3. booking token applied/a) customer sample with booking ticket/') then
do something
end
this is not working, as long as ')' is in the string, any idea to bypass that? thanks
for example:
if string.find(string.lower('%PathName'), '/gct/3. booking token applied/') then
do something
end
this is fine, but
if string.find(string.lower('%PathName'), '/gct/3. booking token applied/a) customer sample with booking ticket/') then
do something
end
this is not working, as long as ')' is in the string, any idea to bypass that? thanks
-
- Site Admin
- Posts: 2084
- Joined: Tue Sep 29, 2009 6:09 am
Re: problem with %PathName, %FileName in LUA
OK, because some special characters like "( ) . % + - * ? [ ^ $" called magic characters in Lua language, you need to add a "%" before the magic character.
Code: Select all
if string.find(string.lower('%PathName'), '/gct/3. booking token applied/a%) customer sample with booking ticket/') then
...
end
-
- Posts: 10
- Joined: Mon Nov 02, 2020 5:58 am
Re: problem with %PathName, %FileName in LUA
lua is quite hard to understand...
if i get a path from %PathName, which contains special symbol like '()', how do I replace it before parse it to string.find or string.match function?
in other programming language, usually it's quite easy to force convert to string or other types...
Thank you.
if i get a path from %PathName, which contains special symbol like '()', how do I replace it before parse it to string.find or string.match function?
in other programming language, usually it's quite easy to force convert to string or other types...
Thank you.
-
- Posts: 10
- Joined: Mon Nov 02, 2020 5:58 am
Re: problem with %PathName, %FileName in LUA
the function i wrote:
function email(p1,p2,f,e)
if string.find(string.lower(p1), string.lower(p2)) then
c_SendMail(e,f.." is uploaded","File path is ["..p2..string.match(string.lower(p1), string.lower(p2)..'(.*)').."]","","SMTP")
end
end
email('%PathName','/path/','%FileName',"somebody@domain.com")
function email(p1,p2,f,e)
if string.find(string.lower(p1), string.lower(p2)) then
c_SendMail(e,f.." is uploaded","File path is ["..p2..string.match(string.lower(p1), string.lower(p2)..'(.*)').."]","","SMTP")
end
end
email('%PathName','/path/','%FileName',"somebody@domain.com")
-
- Site Admin
- Posts: 2084
- Joined: Tue Sep 29, 2009 6:09 am
Re: problem with %PathName, %FileName in LUA
OK, only the 2nd parameter of the function "string.find" needs to handle magic characters, please have a look at this document: https://riptutorial.com/lua/example/205 ... troduction" rel="nofollow