Conditional SAVEAS

Discussions and Tech Support related to the iMacros Firefox Add-on, including the built-in Javascript scripting interface for playing .js files.

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.

Conditional SAVEAS

by ima123 on Mon Dec 04, 2017 10:57 pm

Hi,

I am looking for a piece of code performing a
SAVEAS command only if the length of text to be stored exceeds a predefined threshold
(the length of text is an indicator for whether the EXTRACT is of interest to be stored, at all).

I would guess that the piece of code could roughly look like following line:

SET !VAR4 EVAL("var s='{{!EXTRACT}}'; if(s.length < 5000){var x=\"\";}else{SAVEAS TYPE=EXTRACT FOLDER=E:\\username FILE=filename.csv};")

There are parallels to
viewtopic.php?f=2&t=27599&p=74301&hilit=length#p74301

However, I am still not firm enough in iMacros and JavaScript for creating runnable code starting from this and my sketchy ideas.

The searched piece of code should work at least on iMacros for FF 9.0.3, FF 55.0.3 (32-bit), and Win 7 Version 6.1.
ima123
 
Posts: 6
Joined: Sun Jan 29, 2017 3:15 am

Re: Conditional SAVEAS

by chivracq on Tue Dec 05, 2017 7:39 am

ima123 wrote:Hi,

I am looking for a piece of code performing a
SAVEAS command only if the length of text to be stored exceeds a predefined threshold
(the length of text is an indicator for whether the EXTRACT is of interest to be stored, at all).

I would guess that the piece of code could roughly look like following line:

Code: Select all
SET !VAR4 EVAL("var s='{{!EXTRACT}}'; if(s.length < 5000){var x=\"\";}else{SAVEAS TYPE=EXTRACT FOLDER=E:\\username FILE=filename.csv};")


There are parallels to
viewtopic.php?f=2&t=27599&p=74301&hilit=length#p74301

However, I am still not firm enough in iMacros and JavaScript for creating runnable code starting from this and my sketchy ideas.

The searched piece of code should work at least on
Code: Select all
iMacros for FF 9.0.3, FF 55.0.3 (32-bit), and Win 7 Version 6.1.

Yep, that's exactly the "Idea" like in your 'EVAL()' Statement (like I've already explained/demonstrated in several Threads on the Forum for "Conditional Sound" / "Conditional SAVEAS" / "Conditional FILEDELETE" / "Conditional CLOSE" / "Conditional REFRESH" / etc..., the Principle is each time the same...: compute some (empty) String that you will reuse in the next Statement), except that you cannot imbed another Command/Statement directly in the 'EVAL()'. ("Funny" to notice that several Users regularly try this kind of Syntax, ah-ah...!)
You compute the String, and you reuse it for the Command, and in your Case, the "String" will be your File Name to reuse for the 'SAVEAS' like in:
Code: Select all
SET !VAR4 EVAL("var s='{{!EXTRACT}}'; var x; if(s.length<5000){x='';} else{x='filename.csv';}; x;")
SAVEAS TYPE=EXTRACT FOLDER=E:\\username FILE={{!VAR4}}

(And I think you need '!ERRORIGNORE', iMacros might not be "happy" otherwise with the 'SAVEAS' on an empty String...!)

Here is another Example from one of my own Scripts, where I 'SAVEAS' on every Loop in some Temp File, but I need to issue a Conditional 'FILEDELETE' on the 1st Loop, in order to keep that File "Temporary", otherwise every new Run of the Macro would append new Data for each Loop to the Data from the previous Run(s)...:
Code: Select all
'Easy Access Vars:
SET File_Save Mac#71_2017_VR_Temp.csv
'[...]
'First, delete previous Save (only on 'LOOP=1'):
SET !ERRORIGNORE YES
SET FILEDELETE_File EVAL("var d='{{!LOOP}}', fs='{{File_Save}}', x,y,z; if(d==1){z=fs;} else{z='';}; z;")
FILEDELETE NAME={{FILEDELETE_File}}
SAVEAS TYPE=EXTRACT FOLDER=* FILE={{File_Save}}

(And 'FILEDELETE' definitely needs '!ERRORIGNORE', for when the File does not exist (yet) or has already been deleted.... or is locked by some other Application...)
- (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: 6474
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)


Return to iMacros for Firefox

Who is online

Users browsing this forum: No registered users and 13 guests

-->