skip form field if not blank

Support for iMacros. The iMacros software is the unique solution for automating every activity inside a web browser, for data extraction and web testing.

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.

skip form field if not blank

by Alexx54 on Mon Jan 08, 2018 9:51 am

Hi everyone,

First of all, thanks to the ipswitch team for creating imacros! I purchased it recently and am just starting to see how powerful it is... can't wait to play more with it!

For one of my first projects, I need to fill in an online database from a CSV and followed the Form Filling instructions in the Wiki. It's working great so far. However, I would like the macro to skip the field on the page if it's NOT blank (i.e. if it already contains a value)

I could not find any thread about it, although I saw comments that this had been addressed in the past. Maybe someone knows the answer on the top of their head or point me to an old discussion on this?

my config:
windows 10
Internet Explorer 11.125
iMacros 12.0.501.6698

This is the script I use so far. COL1 is the URL of the form, and COL2 is the value that needs to be entered in the form.

Code: Select all
SET !PLAYBACKDELAY 1.00
SET !DATASOURCE namefill.csv
SET !LOOP 2
SET !DATASOURCE_LINE {{!LOOP}}
URL GOTO={{!COL1}}
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:Data_Name CONTENT={{!COL2}}
TAG POS=1 TYPE=INPUT:SUBMIT ATTR=CLASS:btn<SP>btn-default<SP>btn-success


any help would be greatly appreciated! :)
Alexx54
 
Posts: 5
Joined: Mon Jan 08, 2018 9:37 am

Re: skip form field if not blank

by Alexx54 on Mon Jan 08, 2018 10:44 am

... in case it helps finding a solution, I also tried going the following route:

Code: Select all
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:Data_Name EXTRACT=TXT
SET !VAR1 {{!EXTRACT}}
SET !EXTRACT NULL
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:Data_Name CONTENT={{!COL2}}
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:Data_Name CONTENT={{!VAR1}}
TAG POS=1 TYPE=INPUT:SUBMIT ATTR=CLASS:btn<SP>btn-default<SP>btn-success


what this does is that before writing the value {{!COL2}} in the target field, I can extract whatever value is already present in that field. And then I overwrite that value again at the end (after pasting the value from my csv file). My hope was that if the field was previously empty, that overwrite would do nothing, but sadly it just erases the value I've just entered.

But maybe there is a way to make that work by checking if the extracted value is blank or not using EVAL? I just don't understand well enough how EVAL works..
Alexx54
 
Posts: 5
Joined: Mon Jan 08, 2018 9:37 am

Re: skip form field if not blank

by chivracq on Mon Jan 08, 2018 10:51 am

Alexx54 wrote:Hi everyone,

First of all, thanks to the ipswitch team for creating imacros! I purchased it recently and am just starting to see how powerful it is... can't wait to play more with it!

For one of my first projects, I need to fill in an online database from a CSV and followed the Form Filling instructions in the Wiki. It's working great so far. However, I would like the macro to skip the field on the page if it's NOT blank (i.e. if it already contains a value)

I could not find any thread about it, although I saw comments that this had been addressed in the past. Maybe someone knows the answer on the top of their head or point me to an old discussion on this?

my config:
Code: Select all
windows 10
Internet Explorer 11.125
iMacros 12.0.501.6698


This is the script I use so far. COL1 is the URL of the form, and COL2 is the value that needs to be entered in the form.

Code: Select all
SET !PLAYBACKDELAY 1.00
SET !DATASOURCE namefill.csv
SET !LOOP 2
SET !DATASOURCE_LINE {{!LOOP}}
URL GOTO={{!COL1}}
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:Data_Name CONTENT={{!COL2}}
TAG POS=1 TYPE=INPUT:SUBMIT ATTR=CLASS:btn<SP>btn-default<SP>btn-success


any help would be greatly appreciated! :)

Yep..., fairly easy to implement...!: :D
Before trying to fill in that Input Field, you first extract its current Content.
Then, using 'EVAL()', you spit out for example a "1"/"0" to reuse on "POS=n" when you "really" fill in the '!COL2' Value for the 'Input' Field. ('POS=0' won't do anything...!)

And you need to enable '!ERRORIGNORE'...

More Info about the "Principle" and a List of relevant Threads with Code Examples in the following Thread:
- Workarounds for Conditional Logic in Macro Code
Good luck and post your Final Script... or give a shout if you get stuck, but it's not very complicated... :wink:
- (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: 6878
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: skip form field if not blank

by Alexx54 on Tue Jan 09, 2018 4:20 am

thanks for your feedback. I understand the logic I'm supposed to follow but am not getting the implementation correctly. This is what I have so far. Could you please let me know when i'm getting it wrong?

Code: Select all
VERSION BUILD=12.0.501.6698
SET !PLAYBACKDELAY 0.00
SET !ERRORIGNORE YES
SET !DATASOURCE namefill.csv
SET !LOOP 1
SET !DATASOURCE_LINE {{!LOOP}}
URL GOTO={{!COL1}}
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:Data_Name EXTRACT=TXT
SET !VAR1 EVAL(if {{!EXTRACT}}=NULL '1'; else '0';")
TAG POS={{!VAR1}} TYPE=INPUT:TEXT ATTR=NAME:Data_Name CONTENT={{!COL2}}
Alexx54
 
Posts: 5
Joined: Mon Jan 08, 2018 9:37 am

Re: skip form field if not blank

by chivracq on Tue Jan 09, 2018 4:43 am

Alexx54 wrote:thanks for your feedback. I understand the logic I'm supposed to follow but am not getting the implementation correctly. This is what I have so far. Could you please let me know when i'm getting it wrong?

Code: Select all
VERSION BUILD=12.0.501.6698
SET !PLAYBACKDELAY 0.00
SET !ERRORIGNORE YES
SET !DATASOURCE namefill.csv
SET !LOOP 1
SET !DATASOURCE_LINE {{!LOOP}}
URL GOTO={{!COL1}}
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:Data_Name EXTRACT=TXT
SET !VAR1 EVAL(if {{!EXTRACT}}=NULL '1'; else '0';")
TAG POS={{!VAR1}} TYPE=INPUT:TEXT ATTR=NAME:Data_Name CONTENT={{!COL2}}

I don't think your "NULL" is the correct Value to use for the Check, I would rather expect the 'EXTRACT=TXT' to return an empty String ("").
Simply use the exact Content/Value displayed by the '!EXTRACT_TEST_POPUP', or use "PROMPT _{{!EXTRACT}}_" after the Extract to check its extract Content as an empty String is maybe a bit difficult to "see" on the Popup, ah-ah...! (Hence the surrounding Underscores in the 'PROMPT'...)

Hum, and watch out, you have a missing Double Quote at the beginning of inside the 'EVAL()'...! :!:
But..., re-hum..., I notice several Syntax Errors in your 'EVAL()'... Simply reuse one of "my" Examples from one of the Threads linked to in the Thread I referred you to... I use a very "secure" and easy to understand and to reuse Syntax in all my 'EVAL()' Statements... :idea:
- (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: 6878
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: skip form field if not blank

by Alexx54 on Tue Jan 09, 2018 5:54 am

thanks for that. I have tried replacing NULL by "" and ("") but I think there is a syntax issue somewhere. As I've never done any javascript it's a bit tricky.

Also tried reusing some of the sample commands but they all seem to be slightly different use cases.

What I tried so far :

Code: Select all
'SET !VAR1 EVAL("if {{!EXTRACT}}=("") 1; else 0;")

Code: Select all
'SET !VAR1 EVAL("if {{!EXTRACT}}=("") '1'; else '0';")

Code: Select all
'SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var x; if(s=""){x='1';} else{x='0';}; x;")


(and a bunch of slightly different variants)

just not sure which way to go honestly
Alexx54
 
Posts: 5
Joined: Mon Jan 08, 2018 9:37 am

Re: skip form field if not blank

by Alexx54 on Tue Jan 09, 2018 8:29 am

I think I got it to work!

Code: Select all
SET !VAR1 EVAL("var x='{{!EXTRACT}}'; var z; if(x==''){z=1;} else{z=0;}; z;")
Alexx54
 
Posts: 5
Joined: Mon Jan 08, 2018 9:37 am

Re: skip form field if not blank

by chivracq on Tue Jan 09, 2018 9:02 am

Alexx54 wrote:I think I got it to work!

Code: Select all
SET !VAR1 EVAL("var x='{{!EXTRACT}}'; var z; if(x==''){z=1;} else{z=0;}; z;")

Yep..., very good...! Well done...! :D
- (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: 6878
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)


Return to General Support & Discussions

Who is online

Users browsing this forum: No registered users and 5 guests

-->