Limiting characters with Java script

Discussions and Tech Support related to automating the iMacros Browser or Internet Explorer from any scripting and programming language, such as VBS (WSH), VBA, VB, Perl, Delphi, C# or C++.

Moderators: Community Moderators, iMacros Moderators

Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the Google search box (at the top of each forum page) to see if a similar problem or question has already been addressed. This will search the entire contents of the forums as well as the iMacros Wiki.
3. We can respond much faster to your posts if you include the following information:

CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST

Answering your own posts (e.g. attempting to "bump" your topic) drops your topic from the list of unanswered threads, so it may actually receive less views.

Limiting characters with Java script

by Keith Jones on Thu Feb 26, 2015 10:11 am

I am using iMacros Enterprise for Internet Explorer (x86) Version 10.3.27.5830
Windows OS 7 Enterprise SP1
IE. v.10

I am trying to limit the amount of characters that an EXTRACT from one explorer tab inserts into a different explorer tab. Where the text is inserted, has a limit of 50 character and generates a pop up error that prevents me from saving my page until I manually edit that text to less than 50 characters. I found a JS that appears to do what I need, I just don't know or understand how to put the JS correctly into my iMacros script.
Can anyone assist please?


' Get WO description
TAG POS=1 TYPE=INPUT:TEXT ATTR=ID:mx922 EXTRACT=TXT
SET !VAR4 {{!EXTRACT}}
Set !EXTRACT NULL

'Insert Remarks/Description
'SET trimmedValue str.substring(1, 50)
SET !VAR4 EVAL ("var res = str.substring(1, 50)")
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:invoiceForm ATTR=NAME:ADE52565 CONTENT={{!VAR4}}
Keith Jones
 
Posts: 4
Joined: Wed Feb 11, 2015 9:35 am

Re: Limiting characters with Java script

by chivracq on Thu Feb 26, 2015 2:17 pm

Keith Jones wrote:I am using iMacros Enterprise for Internet Explorer (x86) Version 10.3.27.5830
Windows OS 7 Enterprise SP1
IE. v.10

I am trying to limit the amount of characters that an EXTRACT from one explorer tab inserts into a different explorer tab. Where the text is inserted, has a limit of 50 character and generates a pop up error that prevents me from saving my page until I manually edit that text to less than 50 characters. I found a JS that appears to do what I need, I just don't know or understand how to put the JS correctly into my iMacros script.
Can anyone assist please?

Code: Select all
' Get WO description
TAG POS=1 TYPE=INPUT:TEXT ATTR=ID:mx922 EXTRACT=TXT
SET !VAR4 {{!EXTRACT}}
Set !EXTRACT NULL

'Insert Remarks/Description
'SET trimmedValue str.substring(1, 50)
SET !VAR4 EVAL ("var res = str.substring(1, 50)")
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:invoiceForm ATTR=NAME:ADE52565 CONTENT={{!VAR4}}

You have several working Examples for using 'EVAL()' on the Wiki Page for 'EVAL()' for the correct Syntax...

This should work, and/or use 'PROMPT' to debug your Script...:
Code: Select all
' Get WO description
TAG POS=1 TYPE=INPUT:TEXT ATTR=ID:mx922 EXTRACT=TXT
'SET !VAR4 {{!EXTRACT}}
'Set !EXTRACT NULL

'Insert Remarks/Description
'SET trimmedValue str.substring(1, 50)
SET !VAR4 EVAL("var str='{{!EXTRACT}}'; var res = str.substring(1, 50); res;")
PROMPT Trimed<SP>Text:<SP>_{{!VAR4}}_
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:invoiceForm ATTR=NAME:ADE52565 CONTENT={{!VAR4}}
(Not tested...)

Instead of 'substring()' you could use 'substr()' as well...
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6471
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Limiting characters with Java script

by Keith Jones on Fri Feb 27, 2015 6:38 am

Thank you chivracq! I had tried using the EVAL command before but didn't have much luck with it, and then got off track when I was looking at the JS equivalent. I "thought" I had read that would only work with numbers so I was looking for something else. I will give this one a try today and let you know how it works. Thanks again!! :D
Keith Jones
 
Posts: 4
Joined: Wed Feb 11, 2015 9:35 am

Re: Limiting characters with Java script

by Keith Jones on Tue Mar 03, 2015 3:22 pm

chivracq,
I got your script to work, and thank you! I had to modify the order in which the JS was placed. With it down below on the insert section, it returned a strange value (four numbers), then I moved it up to where I was extracting the text. I also needed to changed the character values to start with "0" instead of "1" as it was cutting off the first character and it worked fine like this:
Code: Select all
'Extract Description from Maximo
TAG POS=1 TYPE=INPUT:TEXT ATTR=ID:mx922 EXTRACT=TXT
SET !VAR4 EVAL("var str='{{!EXTRACT}}'; var res = str.substring(0,49); res;")
PROMPT Trimed<SP>Text:<SP>_{{!VAR4}}_
SET !EXTRACT NULL


TAB T=1
'Insert remarks from Maximo
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:invoiceForm ATTR=NAME:ADE52565 CONTENT={{!VAR4}}
SET !EXTRACT NULL
Last edited by Keith Jones on Tue Mar 03, 2015 3:28 pm, edited 1 time in total.
Keith Jones
 
Posts: 4
Joined: Wed Feb 11, 2015 9:35 am

Re: Limiting characters with Java script

by Keith Jones on Tue Mar 03, 2015 3:27 pm

I am using iMacros Enterprise for Internet Explorer (x86) Version 10.3.27.5830
Windows OS 7 Enterprise SP1
IE. v.10

chivracq,
Now that is all working, another problem has posed itself. When the text from the field I am extracting from is less than 50 characters, I get the following error:

Error -1250: JScript statement in EVAL contains the following error: Expected ';'. Line 55: SET !VAR4 EVAL("var str='{{!EXTRACT}}'; var res = str.substring(0,49); res;")

Which is:
-1250 JScript Error: JScript parsing/evaluation error (in EVAL).

Is there some sort of command I can use to ignore the error and still have what text is in the field extracted?

Thanks,
Keith
Keith Jones
 
Posts: 4
Joined: Wed Feb 11, 2015 9:35 am

Re: Limiting characters with Java script

by chivracq on Wed Mar 04, 2015 6:49 pm

Keith Jones wrote:I am using iMacros Enterprise for Internet Explorer (x86) Version 10.3.27.5830
Windows OS 7 Enterprise SP1
IE. v.10

chivracq,
Now that is all working, another problem has posed itself. When the text from the field I am extracting from is less than 50 characters, I get the following error:

Error -1250: JScript statement in EVAL contains the following error: Expected ';'. Line 55: SET !VAR4 EVAL("var str='{{!EXTRACT}}'; var res = str.substring(0,49); res;")

Which is:
-1250 JScript Error: JScript parsing/evaluation error (in EVAL).

Is there some sort of command I can use to ignore the error and still have what text is in the field extracted?

Thanks,
Keith

'substring()' uses 2 Indexes, maybe it goes wrong when the 2nd Index is not found..., you should rather try with 'substr()' instead of 'substring()', like I mentioned earlier...

About the RuntimeError, it is strange because the Statement looks fine, but I once had the same Problem, and I finally managed to get it to work by just deleting all the ';' in the EVAL and just retyping them... :evil: No idea why...
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6471
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)


Return to Scripting and Command Line Interface

Who is online

Users browsing this forum: No registered users and 1 guest

-->