Using a variable to set the datasource name.

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.

Using a variable to set the datasource name.

by MattBuck on Thu Dec 03, 2015 2:10 pm

I searched through the forums and couldn't find anything that addressed what I am trying to do, so if this is a re-post, please accept my apologies.

I am running:
Win8.1 English
iMacros 10.4 (and only using the iMacros browser)

I am building scripts for my coworkers and want them to enter the name of the datasource they are using when running the script.

This is what I have:
Code: Select all
VERSION BUILD=10.4.28.1074
TAB T=1
SET !DATASOURCE {{!VAR2}}
SET !LOOP 2
SET !DATASOURCE_LINE {{!LOOP}}
SET !VAR1 {{!URLCURRENT}}
TAB CLOSEALLOTHERS

'********************************************************************************************************************
'Enter the datasource for the client's bldg./units
PROMPT "Enter the datasource for the client's bldg./units" !VAR2

'This variable will be used anywhere that the URL contains the application server number
'********************************************************************************************************************


I am prompted to enter the datasource name and the script runs; however, it runs no matter what datasource name I give it (including names of datasources that don't exist). I'm a little puzzled.

Is it possible to have the user prompted to enter the name of the datasource file and store it as a variable?
MattBuck
 
Posts: 6
Joined: Mon Nov 30, 2015 10:43 am

Re: Using a variable to set the datasource name.

by chivracq on Thu Dec 03, 2015 10:03 pm

MattBuck wrote:I searched through the forums and couldn't find anything that addressed what I am trying to do, so if this is a re-post, please accept my apologies.

I am running:
Win8.1 English
iMacros 10.4 (and only using the iMacros browser)

I am building scripts for my coworkers and want them to enter the name of the datasource they are using when running the script.

This is what I have:
Code: Select all
VERSION BUILD=10.4.28.1074
TAB T=1
SET !DATASOURCE {{!VAR2}}
SET !LOOP 2
SET !DATASOURCE_LINE {{!LOOP}}
SET !VAR1 {{!URLCURRENT}}
TAB CLOSEALLOTHERS

'********************************************************************************************************************
'Enter the datasource for the client's bldg./units
PROMPT "Enter the datasource for the client's bldg./units" !VAR2

'This variable will be used anywhere that the URL contains the application server number
'********************************************************************************************************************


I am prompted to enter the datasource name and the script runs; however, it runs no matter what datasource name I give it (including names of datasources that don't exist). I'm a little puzzled.

Is it possible to have the user prompted to enter the name of the datasource file and store it as a variable?

Yes my Dear, but you are a bit funny, sorry no offense...!, you need to change the Sequence of those 2 Statements in your Script (You want to use '!VAR2' before you've even defined it...!):
Code: Select all
SET !DATASOURCE {{!VAR2}}
...
PROMPT "Enter the datasource for the client's bldg./units" !VAR2

Your 'PROMPT' will set '!VAR2' (perfect) and only then you can use {{!VAR2}}' for what you want...
In your current Order/Sequence, you try to use '{{!VAR2}}' while is has not been defined yet... I'm nearly surprised you don't get some RuntimeError... Hum, OK, maybe not, saying "SET !DATASOURCE NULL" can be legit..., but '!DATASOURCE' usually yields some RuntimeError when the File does not exist...

What your current Script is doing is you are singing..., la-la-la...!, I want to use '!VAR2', I haven't defined it, I don't care..., la-la-la...!, I do a few Actions, hey...! User...! (sounds like a Pinkfloyd Song...!), what about giving me a Value for '!VAR2' that I tried to use for you a little bit before in the Script...!? Sorry too late...!

You could entice your Users to use a Default DataSource Name so that they only have to click/press OK/ENTER, instead of having to type the Name of a File, which is always prone to typing mistakes and your Script running directly into some RuntimeError...
After a few times running the Macro, they will change the Name of their DataSource to your Default Name or they will understand where they have to change it in your Macro, you could even use some Variable at the Top of your Macro that Users could change themselves for the Default_DataSource_Name...
- (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)

Re: Using a variable to set the datasource name.

by MattBuck on Fri Dec 04, 2015 10:38 am

Thank you! I figured it had to be something simple that I was overlooking, but after staring at it for hours I just couldn't see it. It's always nice to have a second pair of fresh eyes to help.

I modified my script to look like this:
Code: Select all
VERSION BUILD=10.4.28.1074
TAB T=1
'********************************************************************************************************************
'Enter the datasource for the client's bldg./units
PROMPT "Enter the datasource for the client's bldg./units" !VAR2

'This variablew will be used to set the datasource name for the client that you are working with.
SET !DATASOURCE {{!VAR2}}
'********************************************************************************************************************
SET !LOOP 2
SET !DATASOURCE_LINE {{!LOOP}}
SET !VAR1 {{!URLCURRENT}}
TAB CLOSEALLOTHERS


and it works perfectly!

Who would have thought that defining the variable before you need it would have solved the problem? :lol:

Thanks again!
MattBuck
 
Posts: 6
Joined: Mon Nov 30, 2015 10:43 am

Re: Using a variable to set the datasource name.

by chivracq on Sat Dec 05, 2015 12:54 am

MattBuck wrote:Thank you! I figured it had to be something simple that I was overlooking, but after staring at it for hours I just couldn't see it. It's always nice to have a second pair of fresh eyes to help.

I modified my script to look like this:
Code: Select all
VERSION BUILD=10.4.28.1074
TAB T=1
'********************************************************************************************************************
'Enter the datasource for the client's bldg./units
PROMPT "Enter the datasource for the client's bldg./units" !VAR2

'This variablew will be used to set the datasource name for the client that you are working with.
SET !DATASOURCE {{!VAR2}}
'********************************************************************************************************************
SET !LOOP 2
SET !DATASOURCE_LINE {{!LOOP}}
SET !VAR1 {{!URLCURRENT}}
TAB CLOSEALLOTHERS


and it works perfectly!

Who would have thought that defining the variable before you need it would have solved the problem? :lol:

Thanks again!

Tja..., no Pb, glad I could help... And glad to see that you have the same kind of Humour like me... (Even if I can't guarantee that my eyes will always be fresh, but my brain should remain a bit sharp...)

And nice of you to share your Final Script to finish your Thread neatly... Perfect... :)
- (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)

Re: Using a variable to set the datasource name.

by MattBuck on Fri Dec 18, 2015 8:20 am

I may have been a little premature when I stated that this worked perfectly.

It does work - I am prompted to enter the datasource name, and when I enter it, the script does execute. However, once the first iteration of the script has completed, I am prompted to enter the datasource name again (my initial test only contained one record in the datasource so it worked as I expected/wanted it to).

Here's my complete script:
Code: Select all
VERSION BUILD=10.4.28.1074
TAB T=1
'********************************************************************************************************************
'Enter the datasource name for the client's users (requesters)
PROMPT "Enter the datasource name for the client's users (requesters)" !VAR2

'This variable will be used to set the datasource name for the client that you are working with.
SET !DATASOURCE {{!VAR2}}
'********************************************************************************************************************
SET !LOOP 2
SET !DATASOURCE_LINE {{!LOOP}}
SET !VAR1 {{!URLCURRENT}}
TAB CLOSEALLOTHERS

'To add users (others) using this script, please follow these steps:
'1. Log into the account.
'2. Click the Account Setup tab
'3. Click the link to add Users
'4. Click the link to add new users
'5. Execute the script

'URL for adding users
'URL GOTO=https://app10.facilitydude.com/toolbox/mydtwo/mydtwo_s/mydtWO-participantsrole.asp?passback=1

'Select user role
TAG POS={{!COL2}} TYPE=INPUT:RADIO FORM=NAME:role ATTR=NAME:roleid CONTENT=YES

'Send login information to user via email
TAG POS=1 TYPE=INPUT:CHECKBOX FORM=NAME:role ATTR=NAME:sendemailtouser CONTENT={{!COL7}}

'Click save button
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:role ATTR=NAME:save

'Enter login name
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:frmParticipants ATTR=NAME:username CONTENT={{!COL5}}

'Enter first name
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:frmParticipants ATTR=NAME:FirstName CONTENT={{!COL3}}

'Enter last name
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:frmParticipants ATTR=NAME:LastName CONTENT={{!COL4}}

'Enter password
'**************************************************************************************************
'Password is defaulted to newuser
SET !ENCRYPTION NO
TAG POS=1 TYPE=INPUT:PASSWORD FORM=NAME:frmParticipants ATTR=NAME:password2 CONTENT=newuser
TAG POS=1 TYPE=INPUT:PASSWORD FORM=NAME:frmParticipants ATTR=NAME:password3 CONTENT=newuser
'**************************************************************************************************

'Enter email address
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:frmParticipants ATTR=NAME:email CONTENT={{!COL6}}

'Receive email notifications
TAG POS=1 TYPE=INPUT:CHECKBOX FORM=NAME:frmParticipants ATTR=NAME:MDReceiveEmailNotification CONTENT={{!COL8}}

'Click save button
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:frmParticipants ATTR=NAME:save

'Select location assignment
'**************************************************************************************************
'No selection is made on this page
'Click the save button
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:frmUserLocation ATTR=NAME:save
'**************************************************************************************************

'Select craft assignment
'**************************************************************************************************
'No selection is made on this page
'Click the save button
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:frmUserLocation ATTR=NAME:save
'**************************************************************************************************

'Enter labor rate
'**************************************************************************************************
'No entry is made on this page
'Click save button
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:frmrate ATTR=NAME:save
'**************************************************************************************************

'Delay
WAIT SECONDS=1

URL GOTO={{!VAR1}}

'EOS


My goal would be to enter the datasource name and have it stored for the duration of the script.
MattBuck
 
Posts: 6
Joined: Mon Nov 30, 2015 10:43 am

Re: Using a variable to set the datasource name.

by chivracq on Fri Dec 18, 2015 1:21 pm

MattBuck wrote:I may have been a little premature when I stated that this worked perfectly.

It does work - I am prompted to enter the datasource name, and when I enter it, the script does execute. However, once the first iteration of the script has completed, I am prompted to enter the datasource name again (my initial test only contained one record in the datasource so it worked as I expected/wanted it to).

Here's my complete script:
Code: Select all
VERSION BUILD=10.4.28.1074
TAB T=1
'********************************************************************************************************************
'Enter the datasource name for the client's users (requesters)
PROMPT "Enter the datasource name for the client's users (requesters)" !VAR2

'This variable will be used to set the datasource name for the client that you are working with.
SET !DATASOURCE {{!VAR2}}
'********************************************************************************************************************
SET !LOOP 2
SET !DATASOURCE_LINE {{!LOOP}}
SET !VAR1 {{!URLCURRENT}}
TAB CLOSEALLOTHERS

'To add users (others) using this script, please follow these steps:
'1. Log into the account.
'2. Click the Account Setup tab
'3. Click the link to add Users
'4. Click the link to add new users
'5. Execute the script

'URL for adding users
'URL GOTO=https://app10.facilitydude.com/toolbox/mydtwo/mydtwo_s/mydtWO-participantsrole.asp?passback=1

'Select user role
TAG POS={{!COL2}} TYPE=INPUT:RADIO FORM=NAME:role ATTR=NAME:roleid CONTENT=YES

'Send login information to user via email
TAG POS=1 TYPE=INPUT:CHECKBOX FORM=NAME:role ATTR=NAME:sendemailtouser CONTENT={{!COL7}}

'Click save button
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:role ATTR=NAME:save

'Enter login name
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:frmParticipants ATTR=NAME:username CONTENT={{!COL5}}

'Enter first name
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:frmParticipants ATTR=NAME:FirstName CONTENT={{!COL3}}

'Enter last name
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:frmParticipants ATTR=NAME:LastName CONTENT={{!COL4}}

'Enter password
'**************************************************************************************************
'Password is defaulted to newuser
SET !ENCRYPTION NO
TAG POS=1 TYPE=INPUT:PASSWORD FORM=NAME:frmParticipants ATTR=NAME:password2 CONTENT=newuser
TAG POS=1 TYPE=INPUT:PASSWORD FORM=NAME:frmParticipants ATTR=NAME:password3 CONTENT=newuser
'**************************************************************************************************

'Enter email address
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:frmParticipants ATTR=NAME:email CONTENT={{!COL6}}

'Receive email notifications
TAG POS=1 TYPE=INPUT:CHECKBOX FORM=NAME:frmParticipants ATTR=NAME:MDReceiveEmailNotification CONTENT={{!COL8}}

'Click save button
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:frmParticipants ATTR=NAME:save

'Select location assignment
'**************************************************************************************************
'No selection is made on this page
'Click the save button
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:frmUserLocation ATTR=NAME:save
'**************************************************************************************************

'Select craft assignment
'**************************************************************************************************
'No selection is made on this page
'Click the save button
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:frmUserLocation ATTR=NAME:save
'**************************************************************************************************

'Enter labor rate
'**************************************************************************************************
'No entry is made on this page
'Click save button
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:frmrate ATTR=NAME:save
'**************************************************************************************************

'Delay
WAIT SECONDS=1

URL GOTO={{!VAR1}}

'EOS


My goal would be to enter the datasource name and have it stored for the duration of the script.

Yep, (Conditional) PROMPT is not possible straightforward at this moment in pure .iim nor when looping a Macro.
See an Enhancement Request I already defined in this Thread, will be a good "excuse" to bump it btw...!, ah-ah...!:
- Re: PROMPT Messagebox - Yes - No - Cancel (end)

But, hum, I will quote my Post here as most of it is relevant to your Case... and I may update the other Thread later if "interesting" things come out in this Current Thread...:
chivracq wrote:Yep, that's indeed the Behaviour I observed..., but I wasn't shocked...! (But I only tested on iMacros for FF (v8.8.2).)

>>>

Nice as well if the Developer(s) "work" on the 'PROMPT' Command would be to add an Enhancement Request for an extra Parameter to define the Prompt Type:
- OK (Default if no Input Var is defined.)
- OK/Cancel (Default if an Input Var is defined.)
- YES/NO
- YES/NO/Cancel
(with OK/Cancel being the Default if nothing is specified...)

>>>

And nice as well would be to have another Parameter when looping a Macro to be able to specify when the PROMPT will be triggered:
- All Loops (Default).
- Only First Loop.
- Only Last Loop (-1).
- Only Loop n.
- Only Loops 3,4,5,10-15,*2*.

>>>

And while the Developer(s) look(s) at 'PROMPT', another thing related to PROMPT which is not working is this bit from the Wiki on 'URL GOTO':
Using Javascript

The URL can also call Javascript functions that are either defined in this line or are embedded in the page (V6.22 and later):
Code: Select all
URL GOTO=javascript:alert("TEST");

This prevents from making Conditional PROMPT's with 'EVAL()'...

The Section about the 'Loop' Parameter would then be relevant for you...

But the 'URL GOTO' Syntax with 'alert()' I mention which is broken, seems to be broken only in FF, Tom from TechSupport replied in a next Post in that Thread, meaning that you could still use it as you are "lucky" to be using the iMacros Browser...

In pure .iim, I do have a Workaround which I vaguely mentioned in that Thread without giving any Details, but I'm not sure it would work in the iMacros Browser, and hum..., for 2 Reasons actually, because I am using 2 unsupported "Tricks" of which I discovered recently one (using the 'run' Syntax for one .iim calling another .iim) doesn't work in CR (never tested on IE and iMB) and the other one (using Negative Loop) I've only used it in FF (so I've never checked on IE / CR / iMB) and according to Tom it's supposed not to work in iMB.

In pure .iim again, I handled a Thread a few months ago already (maybe 1 year now...?) with a "difficult" and not "very cooperative" User who mentioned they had found ("on some other Forum" they mentioned, without any other precision...) another way to do a Conditional PROMPT but they never posted it although I asked several times... :shock:
I tried as well to located that "other Forum" myself, but to no avail, maybe you might get luckier than me... :idea:
I wait until they have another Pb/Qt to "spank" them violently with a lot of joy until they publish that Method as a Condition to ueberhaupt eventually consider helping them again... :twisted:

The "royal" and supported way to achieve what you want to do would be anyway to handle the Conditional Behaviour of your Script from a main .js Script in FF or from the Scripting Interface for iMB, TechSupport and all JavaScript Coders will tell you...! :roll:

(iMB = iMacros Browser)

If you choose for the "'URL GOTO' Syntax with 'alert()'" way, post your Working Script, I'll be curious to see how it looks like for the 'EVAL()' and 'alert()' Statements and how you manage to pass your Variable for DataSource between the 'alert()' and the rest of your .iim Script. And that might help other Users 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: 6474
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Using a variable to set the datasource name.

by MattBuck on Fri Dec 18, 2015 1:58 pm

I was afraid you were going to tell me that. :cry:

This is exactly what would benefit me:

And nice as well would be to have another Parameter when looping a Macro to be able to specify when the PROMPT will be triggered:
- All Loops (Default).
- Only First Loop.
- Only Last Loop (-1).
- Only Loop n.
- Only Loops 3,4,5,10-15,*2*.


How do we get this "bumped" so that it appears in the next version of iMacros? Or maybe, it was included in the latest release (Ver. 11) and we just don't know it yet (fortunately, the company that I work for just renewed our support agreement and I can upgrade :D ).

:idea: Crossing my fingers that if it isn't in Ver. 11 that it is included in Ver. 11.1 :idea:

For now, I may have to rely on the users editing the script {shudders at the thought} until another solutions presents itself.
MattBuck
 
Posts: 6
Joined: Mon Nov 30, 2015 10:43 am

Re: Using a variable to set the datasource name.

by chivracq on Mon Dec 21, 2015 9:04 pm

MattBuck wrote:I was afraid you were going to tell me that. :cry:

This is exactly what would benefit me:

And nice as well would be to have another Parameter when looping a Macro to be able to specify when the PROMPT will be triggered:
- All Loops (Default).
- Only First Loop.
- Only Last Loop (-1).
- Only Loop n.
- Only Loops 3,4,5,10-15,*2*.


How do we get this "bumped" so that it appears in the next version of iMacros? Or maybe, it was included in the latest release (Ver. 11) and we just don't know it yet (fortunately, the company that I work for just renewed our support agreement and I can upgrade :D ).

:idea: Crossing my fingers that if it isn't in Ver. 11 that it is included in Ver. 11.1 :idea:

For now, I may have to rely on the users editing the script {shudders at the thought} until another solutions presents itself.

I've just bumped that other Thread, but you can do it yourself as well, otherwise TechSup/Dev might think I'm just suffering from some Personality Split Disorder...!

But, hum, I don't think that Functionality was included in v11 for the iMacros Browser and IE, I haven't installed it but I read the Change Log and I think the only big New Feature is that the EVENT Mode is now included in it as it was before that only available in the FF Add-on...

But, again, as I said before, you are in the luxury Situation to be using the iMacros Browser for which the 'URL GOTO' Syntax I mentioned with 'alert()' should work, which would allow you to only trigger it when you want...

Another Workaround I could think of in your Case, would be to ask your Users to first launch a separate mini-Macro when they want to specify a different DataSource from the last time they ran the "main" Macro, in which they would get the PROMPT and you would save that Info in some TEMP .TXT File that you would use as a first DataSource in your Macro to retrieve the Name of the "real" DataSource.

Like that, your Users don't need to do any Editing to your Macro(s)... 8)
The only a bit tricky part is that you'll have to use 'FILEDELETE' to delete the TEMP File before saving it (again) and I think that 'FILEDELETE' triggers some RuntimeError even with '!ERRORIGNORE' if the File does not exist...
Easy Workaround so that you don't have to go around the PC's of your 200 Users to first copy in the right Location that TEMP File is to do a fake SAVEAS before the 'FILEDELETE' that will just add an extra Row to the File if it was already there, and you don't care as you only want to read the Data contained in the first Row...
And you need to make sure that you issue the 'FILEDELETE' just before the "real" SAVEAS, meaning AFTER the PROMPT, in case they cancel or manage to stop the mini-Macro when they get the PROMPT.
- (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)

Re: Using a variable to set the datasource name.

by MattBuck on Tue Dec 22, 2015 6:29 am

Thank you!

How do I bump something to help? I certainly don't want iOpus to think you suffer from multiple personality disorder. :lol:

Like I said (and you said too), this added functionality would help me and others a lot.
MattBuck
 
Posts: 6
Joined: Mon Nov 30, 2015 10:43 am

Re: Using a variable to set the datasource name.

by chivracq on Tue Dec 22, 2015 9:23 am

MattBuck wrote:Thank you!

How do I bump something to help? I certainly don't want iOpus to think you suffer from multiple personality disorder. :lol:

Like I said (and you said too), this added functionality would help me and others a lot.

You just post like I did in the other Thread...
- (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 General Support & Discussions

Who is online

Users browsing this forum: chivracq and 6 guests

-->