If CSV cell is blank move on to next command

Support for iMacros. The iMacros software is the unique solution for automating every activity inside a web browser, for data extraction and web testing.
Forum rules
iMacros EOL - Attention!

The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.

Thank you again for your business and support.

Sincerely,
The Progress Team

Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
dawidR
Posts: 13
Joined: Thu May 31, 2018 3:27 pm

If CSV cell is blank move on to next command

Post by dawidR » Thu May 31, 2018 3:43 pm

Hello,
I have done a lot of searching about IF / Else command but could not find anything about CSV blank cell. Does anyone know how to ignore the first two lines of this code if COL1 has no data?
Thank you :)

FillInformations += "TAG POS=1 TYPE=SELECT FORM=NAME:CategoryEdit ATTR=ID:Availablechoose_rank CONTENT=${{!COL1}}" + "\n";
FillInformations += "TAG POS=2 TYPE=INPUT:BUTTON FORM=NAME:CategoryEdit ATTR=*" + "\n";
FillInformations += "TAG POS=1 TYPE=SELECT FORM=NAME:CategoryEdit ATTR=ID:Availablechoose_rank CONTENT=${{!COL2}}" + "\n";
FillInformations += "TAG POS=2 TYPE=INPUT:BUTTON FORM=NAME:CategoryEdit ATTR=*" + "\n";
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: If CSV cell is blank move on to next command

Post by chivracq » Fri Jun 01, 2018 1:59 am

dawidR wrote:Hello,
I have done a lot of searching about IF / Else command but could not find anything about CSV blank cell. Does anyone know how to ignore the first two lines of this code if COL1 has no data?
Thank you :)

Code: Select all

FillInformations += "TAG POS=1 TYPE=SELECT FORM=NAME:CategoryEdit ATTR=ID:Availablechoose_rank CONTENT=${{!COL1}}" + "\n";
FillInformations += "TAG POS=2 TYPE=INPUT:BUTTON FORM=NAME:CategoryEdit ATTR=*" + "\n";
FillInformations += "TAG POS=1 TYPE=SELECT FORM=NAME:CategoryEdit ATTR=ID:Availablechoose_rank CONTENT=${{!COL2}}" + "\n";
FillInformations += "TAG POS=2 TYPE=INPUT:BUTTON FORM=NAME:CategoryEdit ATTR=*" + "\n";
(F)CIM for me to have a look..., read my Sig...! :mrgreen: :idea:
I have done a lot of searching about...
Hum, oh-oh, you're a "naughty big-big LIAR"...!, ah-ah...!!, => Nope you didn't, or you would have found at least 20 Threads of mine, ah-ah...! Oops...!! :wink:
Last edited by chivracq on Sat Jun 02, 2018 12:51 pm, edited 1 time in total.
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
dawidR
Posts: 13
Joined: Thu May 31, 2018 3:27 pm

Re: If CSV cell is blank move on to next command

Post by dawidR » Fri Jun 01, 2018 12:10 pm

Honestly I have no idea what (F)CIM is, or how to find out what Macro system I have. As for my system MAC OS 10.13 and Firefox 55.0.2. I am not even sure if thats what is needed to answer your question about (F)CIM.

Secondly I did noticed all 4 pages worth of replies when I did a search for IF / ELSE. But none of the answers worked for my example and I have tried them.

I am sorry if I am bothering everyone with this question. I though maybe some can help.

Have a nice Friday.

Dawid
iMacros for FF V8.9.7
FF v55.0.2
MacOS v10.13
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: If CSV cell is blank move on to next command

Post by chivracq » Fri Jun 01, 2018 4:40 pm

dawidR wrote:Honestly I have no idea what (F)CIM is, or how to find out what Macro system I have. As for my system MAC OS 10.13 and Firefox 55.0.2. I am not even sure if thats what is needed to answer your question about (F)CIM.

Secondly I did noticed all 4 pages worth of replies when I did a search for IF / ELSE. But none of the answers worked for my example and I have tried them.

I am sorry if I am bothering everyone with this question. I though maybe some can help.

Have a nice Friday.

Dawid
Hum, the "big Liar" meant a bit as a joke of course, but good we have your FCI...:

Code: Select all

MAC OS 10.13 and 
Firefox 55.0.2.
Ah beh, no!, the iMacros Version is still missing..., grrr...! :roll:
I will never understand why counting until 3 seems to be so complicated for certain People, ah-ah...! :shock:
But OK, I reckon it will be v9.0.3 or v8.9.7 then... OK-OK...! Well, I read your Qt anyway... :wink:
Like mentioned in my Sig, I usually simply don't read and even less answer if that Info is not mentioned...

But..., OK..., to make your first 2 Lines conditional, I see 2 easy ways, but both involve checking for example the 'Length' of the String contained in '!COL1', which will be "0" if the Cell is empty I reckon. Upon that Check you make then those first 2 Lines conditional by splitting your Macro into 2 Sub-Macros. And prior to your original first 2 Lines, you need to add another mini-Macro to first retrieve '{{!COL1}}' from your '.CSV' to pass it to your main '.js' Script through the '!EXTRACT' + 'iimGetExtract()' Mechanism.

The 2nd Method can be done completely "inside" the (on-the-fly) Macro by using 'EVAL()' to check as well on the Length for '{{!COL1}}' and to return for example a "1"/"0" to reuse on 'POS=n' for the 1st Line and "2"/"0" for the 2nd Line.
Using 'EVAL()' inside an on-the-fly' Macro is always a little bit cumbersome anyway as it means using JavaScript embedded inside JavaScript and the Double Quotes needed inside the 'EVAL()' can be a little bit tricky as you need to escape them for each Level of (Nested) Double Quotes...

As the 2nd Method can be done directly inside your '.iim' Macro, if making those 2 Lines conditional is the only Conditional Logic for your whole Script, then you could write your Macro directly as an '.iim' Script, you don't even need to use a '.js' Script... :idea:
(And that Script would then even run in all Browsers..., while '.js' Scripts only run on FF... And I'm not completely sure, but some v10.b for FF Beta Version just got released in the last few days, to work on FF57/60 and it looks like at the moment '.js' Scripts are not supported anymore... So if it remains like that in the Final Release, and if you ever want to update your FF55 to some later FF Version, you'll need one day to convert your '.js' Script to a pure '.iim' Macro anyway... :idea: [Oh...!, but nope..., you are on MacOS I see, then for the time being, you won't be able to update to v10 anyway as you use a DataSource but the FIO Mechanism needed to access Local Files is not supported (yet) on MacOS, oops...! (Starting to "understand" why mentioning your FCI is "relevant" when opening a Thread, ah-ah...!? :wink: )])

OK, I hope you understand the "Principle" (well, the "Principles" as I mentioned 2 Methods), OK, we'll see, as counting until 3 was already a bit difficult, ah-ah...! :wink:
OK, good luck and post your Final Script or if you get stuck...

EDIT_1:
Oh...!, and you need '!ERRORIGNORE' of course for the 2nd Method, as iMacros doesn't like "POS=0" ah-ah...!, and you could shorten '!TIMEOUT_STEP' to "0" or "1" to avoid your Script waiting for twice 6 sec for both Lines that won't do anything anyway...

EDIT_2:
Hum..., being "nice", or maybe a bit "bored", ah-ah...!: 8)
=> And if you mention your iMacros Version, I will even post a Script "implementing" my 2nd Method (in pure '.iim', I don't "do" '.js'), that you could use as-is if those 2 Lines are the only Conditional Logic you need in your Script, or that you could easily reuse/adapt if you still want/need to use a '.js' Script... :idea:

EDIT_3:
Hum..., thinking again about this Thread, and I see you haven't checked your Thread again yet..., but hum, concerning Method 1 where you do the Check from the '.js' Script, you might need to be "careful" and to do some Testing yourself if you are on v9.0.3 as I think the Behaviour of passing an empty String with '!EXTRACT' changed in v9.0.3 compared to v8.9.7 (proving again btw why mentioning your FCI is always relevant...!), especially when using the "natural" 'EXTRACT' Mechanism and extracting an empty Field which v9.0.3 treats as "NULL" (and not an empty String), and I'm not sure if that applies as well to an empty '{{!COL1}}', (I never bothered to instal v9.0.3 for FF myself as it was a bit too buggy and limited compared to v8.9.7), so you may still need to do some Check already in the first mini-Macro meant to pass '{{!COL1}}' to the '.js' Script, to pass some "0" or "EMPTY" or "X" (whatever you want) as I'm not sure what the Length of '!EXTRACT' will return if '!EXTRACT' is NULL, probably "__undefined__" I reckon...
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
dawidR
Posts: 13
Joined: Thu May 31, 2018 3:27 pm

Re: If CSV cell is blank move on to next command

Post by dawidR » Mon Jun 04, 2018 1:56 pm

First of all thank you for all these suggestions, I will try to figure it out now :) . AS for the version of Imacro I just figured out today how to check on that. Sorry it took me a while to find out where to find it: iMacros for Firefox 9.0.3 LEGACY

I will try to do some testing now.
iMacros for FF V8.9.7
FF v55.0.2
MacOS v10.13
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: If CSV cell is blank move on to next command

Post by chivracq » Mon Jun 04, 2018 2:50 pm

dawidR wrote:First of all thank you for all these suggestions, I will try to figure it out now :) . AS for the version of Imacro I just figured out today how to check on that. Sorry it took me a while to find out where to find it:

Code: Select all

iMacros for Firefox 9.0.3 LEGACY
I will try to do some testing now.
Oh...!, good, we finally have your FCI: :D

Code: Select all

iMacros for FF v9.0.3
FF v55.0.2
MacOS v10.13
OK, then as promised, from your original 4 Line Script, this is what it would become in pure '.iim' by implementing my 2nd Method:

Code: Select all

SET !ERRORIGNORE YES
SET !TIMEOUT_STEP 1

SET COL1_Check EVAL("var c1='{{!COL1}}'; var x,y,z; x=c1.length; if(x>0){z=1;} else{z=0;}; z;")
PROMPT COL1:<SP>_{{!COL1}}_<BR>COL1_Check:<SP>_{{COL1_Check}}_
'>
TAG POS={{COL1_Check}} TYPE=SELECT FORM=NAME:CategoryEdit ATTR=ID:Availablechoose_rank CONTENT=${{!COL1}}
TAG POS=R1 TYPE=INPUT:BUTTON FORM=NAME:CategoryEdit ATTR=*
'>
TAG POS=1 TYPE=SELECT FORM=NAME:CategoryEdit ATTR=ID:Availablechoose_rank CONTENT=${{!COL2}}
TAG POS=2 TYPE=INPUT:BUTTON FORM=NAME:CategoryEdit ATTR=*
(Not tested..., and the "R1" for the 2nd Line is a "Guess" to avoid a 2nd 'EVAL()' to spit out the "2"/"0"...)
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
dawidR
Posts: 13
Joined: Thu May 31, 2018 3:27 pm

Re: If CSV cell is blank move on to next command

Post by dawidR » Mon Jun 04, 2018 4:34 pm

thank you again :) I am getting some syntax errors but will keep testing until i figure it out :)
iMacros for FF V8.9.7
FF v55.0.2
MacOS v10.13
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: If CSV cell is blank move on to next command

Post by chivracq » Mon Jun 04, 2018 5:44 pm

dawidR wrote:thank you again :) I am getting some syntax errors but will keep testing until i figure it out :)
Yeah, "some syntax errors" is a bit vague, but for "my" Script to work, you need of course to specify your DataSource... Was not included in your original 4 Line Script, then I cannot guess it...

I just tested it with a '!VAR1' instead of '!COL1', set to an empty String and to a not empty String, and it works... (I can only test the 'EVAL' + 'PROMPT' part, of course...)

If converting the 'EVAL()' Statement to your on-the-fly Macro if you still want to use a '.js' Script, you need to (extra) escape all Double Quotes for each Nested Level, like I already mentioned..., and you might actually be able to avoid that by using Single Quotes for your own "FillInformations" String as that will alternate Double and Single Quotes for each Level like I already did by using Single Quotes inside the 'EVAL()' for '{{!COL1}}'.

If you post your Script and how far you came, then I can see what you are doing...
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
dawidR
Posts: 13
Joined: Thu May 31, 2018 3:27 pm

Re: If CSV cell is blank move on to next command

Post by dawidR » Tue Jun 05, 2018 3:04 pm

My apologies,

I thought I would only point out the area of script that I am trying to evaluate if macro should skip or follow steps.
the full script is here:

Setup = "CODE:";
Setup += "SET !ERRORIGNORE YES" + "\n";
Setup += "SET !ERRORCONTINUE YES" + "\n";
Setup += "SET !TIMEOUT_STEP 0" + "\n";
Setup += "TAB CLOSEALLOTHERS" + "\n";
Setup += "SET !TIMEOUT_PAGE 300" + "\n";

CheckSource = "CODE:";
CheckSource += "SET !DATASOURCE {{filename}}" + "\n";
CheckSource += "SET !DATASOURCE_LINE {{next}}" + "\n";

FillInformations = "CODE:";
FillInformations += "SET !REPLAYSPEED SLOW" + "\n";
FillInformations += "SET !DATASOURCE {{filename}}" + "\n";
FillInformations += "SET !DATASOURCE_LINE {{next}}" + "\n";

FillInformations += "URL GOTO={{!COL11}}" + "\n";
FillInformations += "wait seconds=1" + "\n";
FillInformations += "SET !DATASOURCE {{filename}}" + "\n";
FillInformations += "SET !DATASOURCE_LINE {{next}}" + "\n";


FillInformations += "TAG POS=1 TYPE=A ATTR=TXT:[add<SP>refinements]" + "\n";
FillInformations += "wait seconds=1" + "\n";


FillInformations += "TAG POS=1 TYPE=SELECT FORM=NAME:CategoryEdit ATTR=ID:Availablechoose_rank CONTENT=${{!COL1}}" + "\n"; //perform only if COL1 has data
FillInformations += "TAG POS=2 TYPE=INPUT:BUTTON FORM=NAME:CategoryEdit ATTR=*" + "\n";
FillInformations += "TAG POS=1 TYPE=SELECT FORM=NAME:CategoryEdit ATTR=ID:Availablechoose_rank CONTENT=${{!COL2}}" + "\n"; //perform only if COL2 has data
FillInformations += "TAG POS=2 TYPE=INPUT:BUTTON FORM=NAME:CategoryEdit ATTR=*" + "\n";
FillInformations += "TAG POS=1 TYPE=SELECT FORM=NAME:CategoryEdit ATTR=ID:Availablechoose_rank CONTENT=${{!COL3}}" + "\n"; //perform only if COL3 has data
FillInformations += "TAG POS=2 TYPE=INPUT:BUTTON FORM=NAME:CategoryEdit ATTR=*" + "\n";
FillInformations += "TAG POS=1 TYPE=SELECT FORM=NAME:CategoryEdit ATTR=ID:Availablechoose_rank CONTENT=${{!COL4}}" + "\n"; //perform only if COL4 has data
FillInformations += "TAG POS=2 TYPE=INPUT:BUTTON FORM=NAME:CategoryEdit ATTR=*" + "\n";
FillInformations += "TAG POS=1 TYPE=SELECT FORM=NAME:CategoryEdit ATTR=ID:Availablechoose_rank CONTENT=${{!COL5}}" + "\n"; //perform only if COL5 has data
FillInformations += "TAG POS=2 TYPE=INPUT:BUTTON FORM=NAME:CategoryEdit ATTR=*" + "\n";
FillInformations += "TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:CategoryEdit ATTR=*" + "\n";







main :
{



var filename= prompt("Please Provide Your Source File? ", "");



// Setup Imacros
erero = iimPlay(Setup);
next=1;


while (true){

// Next Informations Line
next++;

// Check If Still there is informations
iimSet("filename", filename);
iimSet("next", next);
erero = iimPlay(CheckSource);
if (erero==-951){break;}

//Fill Informations

iimSet("filename", filename);
iimSet("next", next);
erero = iimPlay(FillInformations);



}




alert ("Finished :) ");




}






FillInformations += "PAUSE" + "\n";
iMacros for FF V8.9.7
FF v55.0.2
MacOS v10.13
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: If CSV cell is blank move on to next command

Post by chivracq » Tue Jun 05, 2018 5:18 pm

dawidR wrote:My apologies,

I thought I would only point out the area of script that I am trying to evaluate if macro should skip or follow steps.
the full script is here:

Code: Select all

Setup = "CODE:";
Setup += "SET !ERRORIGNORE YES" + "\n";
Setup += "SET !ERRORCONTINUE YES" + "\n";
Setup += "SET !TIMEOUT_STEP 0" + "\n";
Setup += "TAB CLOSEALLOTHERS" + "\n";
Setup += "SET !TIMEOUT_PAGE 300" + "\n";

CheckSource = "CODE:";
CheckSource += "SET !DATASOURCE {{filename}}" + "\n";
CheckSource += "SET !DATASOURCE_LINE {{next}}" + "\n"; 

FillInformations = "CODE:";
FillInformations += "SET !REPLAYSPEED SLOW" + "\n";
FillInformations += "SET !DATASOURCE {{filename}}" + "\n";
FillInformations += "SET !DATASOURCE_LINE {{next}}" + "\n";

FillInformations += "URL GOTO={{!COL11}}" + "\n";
FillInformations += "wait seconds=1" + "\n";
FillInformations += "SET !DATASOURCE {{filename}}" + "\n";
FillInformations += "SET !DATASOURCE_LINE {{next}}" + "\n";

FillInformations += "TAG POS=1 TYPE=A ATTR=TXT:[add<SP>refinements]" + "\n";
FillInformations += "wait seconds=1" + "\n";

FillInformations += "TAG POS=1 TYPE=SELECT FORM=NAME:CategoryEdit ATTR=ID:Availablechoose_rank CONTENT=${{!COL1}}" + "\n"; //perform only if COL1 has data
FillInformations += "TAG POS=2 TYPE=INPUT:BUTTON FORM=NAME:CategoryEdit ATTR=*" + "\n";
FillInformations += "TAG POS=1 TYPE=SELECT FORM=NAME:CategoryEdit ATTR=ID:Availablechoose_rank CONTENT=${{!COL2}}" + "\n"; //perform only if COL2 has data
FillInformations += "TAG POS=2 TYPE=INPUT:BUTTON FORM=NAME:CategoryEdit ATTR=*" + "\n";
FillInformations += "TAG POS=1 TYPE=SELECT FORM=NAME:CategoryEdit ATTR=ID:Availablechoose_rank CONTENT=${{!COL3}}" + "\n"; //perform only if COL3 has data
FillInformations += "TAG POS=2 TYPE=INPUT:BUTTON FORM=NAME:CategoryEdit ATTR=*" + "\n";
FillInformations += "TAG POS=1 TYPE=SELECT FORM=NAME:CategoryEdit ATTR=ID:Availablechoose_rank CONTENT=${{!COL4}}" + "\n"; //perform only if COL4 has data
FillInformations += "TAG POS=2 TYPE=INPUT:BUTTON FORM=NAME:CategoryEdit ATTR=*" + "\n";
FillInformations += "TAG POS=1 TYPE=SELECT FORM=NAME:CategoryEdit ATTR=ID:Availablechoose_rank CONTENT=${{!COL5}}" + "\n"; //perform only if COL5 has data
FillInformations += "TAG POS=2 TYPE=INPUT:BUTTON FORM=NAME:CategoryEdit ATTR=*" + "\n";
FillInformations += "TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:CategoryEdit ATTR=*" + "\n";

main :
{
	var filename= prompt("Please Provide Your Source File? ", "");

	      // Setup Imacros
	        erero = iimPlay(Setup);
			next=1;
	
				while (true){
					
					// Next Informations Line
				next++;
				
				// Check If Still there is informations
				iimSet("filename", filename);
				iimSet("next", next);
				erero = iimPlay(CheckSource);
				if (erero==-951){break;}
				
				//Fill Informations 
				
				iimSet("filename", filename);
				iimSet("next", next);
				erero = iimPlay(FillInformations);
				}
				alert ("Finished :) ");		
}

FillInformations += "PAUSE" + "\n";
Okay..., but ouf-ouf...!, you've created for yourself quite a "Once in a Lifetime Project", ah-ah...! :shock: 8)
Pretty complex and cumbersome Implementation in my first Impression, with Nested Loops and quite a lot of Conditional Logic, hum, and I see you need the "Empty '!COL1' Logic" for all Cols actually, OK...

Your whole Script could be implemented in just a few Lines in pure '.iim' for a fairly short Macro to loop (per Cell/Col), I've already provided Solutions (in pure '.iim') for all "Ingredients" you need for that Script, the only "Difficulty" in pure '.iim' would then be the Conditional Input 'PROMPT' for the DataSource only for Loop_1. Much easier would be if the User can hard-code it at the beginning of the Script...

Your Script uses btw some Command(s) that have been deprecated for about 8 or 10 years btw, I'm not even sure if they still work in v9.0.3.

Your 'Setup' Macro doesn't do much, apart from closing other Open Tabs, the other Statements are "useless", all the Vars you try to set in it have already been forgotten/reset when you call the next Macros. ('iimPlay()' resets all those Vars by Design each time it is called..., which forces you repeat all those Statements for each separate on-the-fly Macro you want to create, which will make your whole '.js' Script even longer...)

But OK, you are still a long way to go, ah-ah...! Good luck anyway... :wink:

(Try to use the ]CODE[ Forum Formatting Meta-Tags btw when you post a Script, that makes your Post(s) and the whole Thread much more readable... :idea: )
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
Post Reply