Multiple datasources in one script problem

Discussions and Tech Support specific to the iMacros Firefox add-on.
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
Legalien
Posts: 111
Joined: Mon Feb 15, 2016 6:47 pm
Contact:

Multiple datasources in one script problem

Post by Legalien » Thu Jun 23, 2022 10:23 pm

Windows 10
Firefox 55.0.2
iMacros 8.9.7

So I have a bit of a problem with using multiple datasources in 1 iMacro script (.iim script).

Code: Select all

SET !ERRORIGNORE YES
SET !TIMEOUT_PAGE 20

SET !DATASOURCE C:\Users\user\Documents\iMacros\Datasources\Folder1\mam.txt
SET !DATASOURCE_COLUMNS 2

SET !VAR1 EVAL("var min = 9; var max = 10; var randomNumber = Math.floor(Math.random() * (max - min + 1)) + min; randomNumber;")
SET !VAR2 EVAL("var min = 2; var max = 3; var randomNumber = Math.floor(Math.random() * (max - min + 1)) + min; randomNumber;")

SET !DATASOURCE_LINE 1

WAIT SECONDS={{!VAR2}}
URL GOTO=https://www.site.com/login/
WAIT SECONDS=2
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:login ATTR=ID:username CONTENT={{!COL1}}
WAIT SECONDS=1
SET !ENCRYPTION NO
TAG POS=1 TYPE=INPUT:PASSWORD FORM=ID:login ATTR=ID:password CONTENT={{!COL2}}
WAIT SECONDS=2
TAG POS=1 TYPE=SPAN ATTR=TXT:Submit
WAIT SECONDS=3



URL GOTO=https://www.site.org/page.php
WAIT SECONDS={{!VAR1}}
SET !DATASOURCE C:\Users\user\Desktop\1\tools\result.txt
WAIT SECONDS={{!VAR2}}
EVENTS TYPE=KEYPRESS SELECTOR="#some_code" CHARS="{{!COL1}}"
So the script runs and uses the first datasource (mam.txt) to insert a username and password on a website, and then it logins.

Then it gets to the second datasource (result.txt) and tries to insert some text on the site. The problem is that this second datasource file doesn't always exist.

When the second datasource file doesn't exist, then iMacros inserts the COL1 from the first datasource. But I don't want it to do that. I told it to switch to the second datasource, why is it even taking the first datasource under consideration? What should happen if the second datasource doesn't exist, is to behave like it would if I ran the script using only the second datasource with the file not existing - iMacros should insert nothing, because there is nothing there.

Things work fine when the second datasource actually exists. Then iMacros inserts the text from it in the field.

Is there a solution to this?

---

I do have a solution. Breaking my script into 6 scripts, and then jumping from one to the other using URL GOTO=

1) Script 1 logs me in
2) Script 2 does what it does, then logs me out
3) Script 3 logs me in
4) Script 4 does what it does, then logs me out
5) Script 5 logs me in
6) Script 6 does what it does, then logs me out

In the end script 6 jumps back to script 1 and the process repeats itself.

In this way, it seems that when iMacros jumps from one script to another, it forgets the previous datasource and starts with a clean slate.

But there has to be a better way. Such a long solution to such a simple problem :cry:

Doesn't iMacro have a command to, like, reset it? Like you would run a command to clear the cache and cookies of a browser. Can't you run a command to clear the cache/cookies/memory of the iMacro extension?

Any solution is welcome. Thanks :)
Buy Social Media Services - https://Socialesale.com
Legalien
Posts: 111
Joined: Mon Feb 15, 2016 6:47 pm
Contact:

Re: Multiple datasources in one script problem

Post by Legalien » Thu Jun 23, 2022 11:11 pm

Legalien wrote:
Thu Jun 23, 2022 10:23 pm

1) Script 1 logs me in
2) Script 2 does what it does, then logs me out
3) Script 3 logs me in
4) Script 4 does what it does, then logs me out
5) Script 5 logs me in
6) Script 6 does what it does, then logs me out

In the end script 6 jumps back to script 1 and the process repeats itself.

In this way, it seems that when iMacros jumps from one script to another, it forgets the previous datasource and starts with a clean slate.
This won't work either. Scripts 2, 4 and 6 would have a total of eight inputs from the datasource. But iMacro just remembers the first input and keeps repeating it over and over again, no matter what appears in the txt file after :(
Buy Social Media Services - https://Socialesale.com
Legalien
Posts: 111
Joined: Mon Feb 15, 2016 6:47 pm
Contact:

Re: Multiple datasources in one script problem

Post by Legalien » Fri Jun 24, 2022 2:42 am

After many hours of banging my head up against the wall, I think I found the perfect solution!

Opening my txt file in a new tab, then copying my text using EXTRACT, and then pasting it in on the website.

Here is a little script:

Code: Select all

SET !EXTRACT_TEST_POPUP NO
TAB OPEN NEW
TAB T=2
URL GOTO="file:///C:/Users/user/Desktop/result.txt"
WAIT SECONDS=2
SET !EXTRACT NULL
TAG POS=1 TYPE=BODY ATTR=TXT:* EXTRACT=TXT
TAB T=1
WAIT SECONDS=2
SET !TIMEOUT 1
EVENTS TYPE=KEYPRESS SELECTOR="#someid" CHARS="{{!EXTRACT}}"
This is all I have, but it's all I need. I tested it and it seems to work great :D
Buy Social Media Services - https://Socialesale.com
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Multiple datasources in one script problem

Post by chivracq » Fri Jun 24, 2022 5:02 am

Legalien wrote:
Thu Jun 23, 2022 10:23 pm

Code: Select all

Windows 10
Firefox 55.0.2
iMacros 8.9.7
So I have a bit of a problem with using multiple datasources in 1 iMacro script (.iim script).

Code: Select all

SET !ERRORIGNORE YES
SET !TIMEOUT_PAGE 20

SET !DATASOURCE C:\Users\user\Documents\iMacros\Datasources\Folder1\mam.txt
SET !DATASOURCE_COLUMNS 2

SET !VAR1 EVAL("var min = 9; var max = 10; var randomNumber = Math.floor(Math.random() * (max - min + 1)) + min; randomNumber;")
SET !VAR2 EVAL("var min = 2; var max = 3; var randomNumber = Math.floor(Math.random() * (max - min + 1)) + min; randomNumber;")

SET !DATASOURCE_LINE 1

WAIT SECONDS={{!VAR2}}
URL GOTO=https://www.site.com/login/
WAIT SECONDS=2
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:login ATTR=ID:username CONTENT={{!COL1}}
WAIT SECONDS=1
SET !ENCRYPTION NO
TAG POS=1 TYPE=INPUT:PASSWORD FORM=ID:login ATTR=ID:password CONTENT={{!COL2}}
WAIT SECONDS=2
TAG POS=1 TYPE=SPAN ATTR=TXT:Submit
WAIT SECONDS=3


URL GOTO=https://www.site.org/page.php
WAIT SECONDS={{!VAR1}}
SET !DATASOURCE C:\Users\user\Desktop\1\tools\result.txt
WAIT SECONDS={{!VAR2}}
EVENTS TYPE=KEYPRESS SELECTOR="#some_code" CHARS="{{!COL1}}"
So the script runs and uses the first datasource (mam.txt) to insert a username and password on a website, and then it logins.

Then it gets to the second datasource (result.txt) and tries to insert some text on the site. The problem is that this second datasource file doesn't always exist.

When the second datasource file doesn't exist, then iMacros inserts the COL1 from the first datasource. But I don't want it to do that. I told it to switch to the second datasource, why is it even taking the first datasource under consideration? What should happen if the second datasource doesn't exist, is to behave like it would if I ran the script using only the second datasource with the file not existing - iMacros should insert nothing, because there is nothing there.

Things work fine when the second datasource actually exists. Then iMacros inserts the text from it in the field.

Is there a solution to this?

---

I do have a solution. Breaking my script into 6 scripts, and then jumping from one to the other using URL GOTO=

1) Script 1 logs me in
2) Script 2 does what it does, then logs me out
3) Script 3 logs me in
4) Script 4 does what it does, then logs me out
5) Script 5 logs me in
6) Script 6 does what it does, then logs me out

In the end script 6 jumps back to script 1 and the process repeats itself.

In this way, it seems that when iMacros jumps from one script to another, it forgets the previous datasource and starts with a clean slate.

But there has to be a better way. Such a long solution to such a simple problem :cry:

Doesn't iMacro have a command to, like, reset it? Like you would run a command to clear the cache and cookies of a browser. Can't you run a command to clear the cache/cookies/memory of the iMacro extension?

Any solution is welcome. Thanks :)
>>>
Legalien wrote:
Thu Jun 23, 2022 11:11 pm
Legalien wrote:
Thu Jun 23, 2022 10:23 pm

1) Script 1 logs me in
2) Script 2 does what it does, then logs me out
3) Script 3 logs me in
4) Script 4 does what it does, then logs me out
5) Script 5 logs me in
6) Script 6 does what it does, then logs me out

In the end script 6 jumps back to script 1 and the process repeats itself.

In this way, it seems that when iMacros jumps from one script to another, it forgets the previous datasource and starts with a clean slate.
This won't work either. Scripts 2, 4 and 6 would have a total of eight inputs from the datasource. But iMacro just remembers the first input and keeps repeating it over and over again, no matter what appears in the txt file after :(
>>>
Legalien wrote:
Fri Jun 24, 2022 2:42 am
After many hours of banging my head up against the wall, I think I found the perfect solution!

Opening my txt file in a new tab, then copying my text using EXTRACT, and then pasting it in on the website.

Here is a little script:

Code: Select all

SET !EXTRACT_TEST_POPUP NO
TAB OPEN NEW
TAB T=2
URL GOTO="file:///C:/Users/user/Desktop/result.txt"
WAIT SECONDS=2
SET !EXTRACT NULL
TAG POS=1 TYPE=BODY ATTR=TXT:* EXTRACT=TXT
TAB T=1
WAIT SECONDS=2
SET !TIMEOUT 1
EVENTS TYPE=KEYPRESS SELECTOR="#someid" CHARS="{{!EXTRACT}}"
This is all I have, but it's all I need. I tested it and it seems to work great :D
>>>

Quick Quote of your 3 Posts (in case you would decide to "mutilate" your Thread as you seem to have found a Sol in the 3rd one (happens very often)), I had seen your first 2 Posts a few hour ago, but had Friends over, ... and they noticed my "Look" about "oh-oh...!, some new Thread on "my" Forum", and I was "not allowed" to reply or do any "Thinking" about this "new Thread", ah-ah...! Now they've just left, but it's "pretty late" and you "sound" like you found a Sol, so I'll have a look "tomorrow" after some sleep, ah-ah...! :wink:

+ From the Thread Title and a mini-super-diagonal-scan Reading, the Thread doesn't "sound" like specific to the 'iMacros for FF' Sub-Forum, rather meant for the 'General' one I would think, from a very quick Scan... I'll check "tomorrow" and will move it to its "relevant" Sub-Forum if necessary... :wink:

... But I think I like the Title already: "Multiple datasources in one script problem", the "good news" is that I do use multiple DataSources myself in several of my own Scripts, in some "pretty advanced way" I suppose, as I've never seen anybody asking any Qt's on the Forum about that kind of Scenarios, and also in the same v8.9.7 for FF Version like you (+ FF v55.03 + Win10-Pro), (+ the same Scripts also cross-FCI used for v8.8.2 for FF + PM v26.3.3 + same OS), so I guess I'm probably "quite knowledgeable" about using multiple DataSources in one same Script, ah-ah...! :P
+ Also (Temp)-DataSources being used between different Scripts, => one Script creates/saves a (Temp)-DataSource that some "other" Script can "check" or use as DataSource for some "further" Processing... Cool...! :P

Hum, "cool", except that I sometimes don't have any "clue" anymore what some of my Scripts are doing, ah-ah...! Written 10-8 years ago, they still work perfectly, but sometimes, I want to add some extra Func, and even if I always put Comments in my Coding/Scripts, pffff..., I sometimes have "Difficulties" re-understanding the sometimes "hum, pretty clever" Implementation I had done 8 or 10 years ago from my own Scripts, ah-ah...! (or oops...!? :twisted: :shock: )

OK, till tomorrow then, I will have a Look, and Thanks already for "Sharing", as I understood you already found a Solution, good...! :D :wink:
- (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...
Legalien
Posts: 111
Joined: Mon Feb 15, 2016 6:47 pm
Contact:

Re: Multiple datasources in one script problem

Post by Legalien » Fri Jun 24, 2022 1:52 pm

chivracq wrote:
Fri Jun 24, 2022 5:02 am
Quick Quote of your 3 Posts (in case you would decide to "mutilate" your Thread as you seem to have found a Sol in the 3rd one (happens very often)), I had seen your first 2 Posts a few hour ago, but had Friends over, ... and they noticed my "Look" about "oh-oh...!, some new Thread on "my" Forum", and I was "not allowed" to reply or do any "Thinking" about this "new Thread", ah-ah...! Now they've just left, but it's "pretty late" and you "sound" like you found a Sol, so I'll have a look "tomorrow" after some sleep, ah-ah...! :wink:

+ From the Thread Title and a mini-super-diagonal-scan Reading, the Thread doesn't "sound" like specific to the 'iMacros for FF' Sub-Forum, rather meant for the 'General' one I would think, from a very quick Scan... I'll check "tomorrow" and will move it to its "relevant" Sub-Forum if necessary... :wink:

... But I think I like the Title already: "Multiple datasources in one script problem", the "good news" is that I do use multiple DataSources myself in several of my own Scripts, in some "pretty advanced way" I suppose, as I've never seen anybody asking any Qt's on the Forum about that kind of Scenarios, and also in the same v8.9.7 for FF Version like you (+ FF v55.03 + Win10-Pro), (+ the same Scripts also cross-FCI used for v8.8.2 for FF + PM v26.3.3 + same OS), so I guess I'm probably "quite knowledgeable" about using multiple DataSources in one same Script, ah-ah...! :P
+ Also (Temp)-DataSources being used between different Scripts, => one Script creates/saves a (Temp)-DataSource that some "other" Script can "check" or use as DataSource for some "further" Processing... Cool...! :P

Hum, "cool", except that I sometimes don't have any "clue" anymore what some of my Scripts are doing, ah-ah...! Written 10-8 years ago, they still work perfectly, but sometimes, I want to add some extra Func, and even if I always put Comments in my Coding/Scripts, pffff..., I sometimes have "Difficulties" re-understanding the sometimes "hum, pretty clever" Implementation I had done 8 or 10 years ago from my own Scripts, ah-ah...! (or oops...!? :twisted: :shock: )

OK, till tomorrow then, I will have a Look, and Thanks already for "Sharing", as I understood you already found a Solution, good...! :D :wink:
Hey man,

I hope you had a good evening with your friends. Sure, move the thread, I think it's probably better suited in the general forum.

So I actually may have solved my problem with SET !DATASOURCE NULL

Look a this script:

Code: Select all

SET !DATASOURCE C:\Users\user\Documents\iMacros\Datasources\Folder1\lpl3.txt
SET !DATASOURCE_COLUMNS 2

SET !VAR1 EVAL("var min = 4; var max = 5; var randomNumber = Math.floor(Math.random() * (max - min + 1)) + min; randomNumber;")


SET !DATASOURCE_LINE 1

URL GOTO=https://site.com/
WAIT SECONDS=2
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:login ATTR=ID:username CONTENT={{!COL1}}
WAIT SECONDS=1
TAG POS=1 TYPE=SPAN ATTR=TXT:Submit
WAIT SECONDS=3


URL GOTO=https://site.com/page.php
WAIT SECONDS={{!VAR1}}

SET !DATASOURCE NULL
WAIT SECONDS={{!VAR1}}
SET !DATASOURCE C:\Users\user\Desktop\3\tools\result.txt
WAIT SECONDS={{!VAR1}}
EVENTS TYPE=KEYPRESS SELECTOR="#someid" CHARS="{{!COL1}}"
WAIT SECONDS={{!VAR1}}
So the script starts, goes to a page, and inserts {{!COL1}} from lpl3.txt

Then it goes to another page, and inserts {{!COL1}} from result.txt

The problem is that the second datasource (result.txt) may or may not exist when it gets to it. And if it doesn't exist, then the script pastes in the COL1 from from the first datasource (lpl3.txt). I don't want that.

My solution is to make sure the result.txt always exists, except if nothing needs to be pasted then the file will be empty. If the file exists but is empty, then iMacros recognizes it, and pastes nothing (because the file is empty).

I'm actually at 99% with this, I'm going to test it right now :D
Buy Social Media Services - https://Socialesale.com
Legalien
Posts: 111
Joined: Mon Feb 15, 2016 6:47 pm
Contact:

Re: Multiple datasources in one script problem

Post by Legalien » Fri Jun 24, 2022 3:21 pm

Okay so I got it working perfectly, and in the end I didn't even need this - SET !DATASOURCE NULL

I just needed to make sure there is always a datasource file present, whether empty or not. This was the key :D
Buy Social Media Services - https://Socialesale.com
techimac
Posts: 482
Joined: Fri Feb 20, 2015 9:27 pm

Re: Multiple datasources in one script problem

Post by techimac » Mon Jul 04, 2022 6:00 pm

why dont you use js since using iMacros 8.9.7?
Available for custom iim, javascript iMacros scripts
Post Reply