Passing arguments to sub-scripts?

Discussions and Tech Support related to the iMacros Firefox Add-on, including the built-in Javascript scripting interface for playing .js files.
Forum rules
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
RCobb1
Posts: 20
Joined: Thu Jun 26, 2008 6:19 pm

Passing arguments to sub-scripts?

Post by RCobb1 » Wed Nov 05, 2008 2:46 pm

Is there a mechanism for passing prompted arguments to sub-scripts? For example, I have this JavaScript macro that calls other macros as follows:

Code: Select all

iimPlay("Common/login")
iimPlay("Test/DoSomething")
iimPlay("Common/logout")
and I would like to do something more like this:

Code: Select all

iimPlay("PROMPT Enter<SP>target<SP>URL: !VAR1")
iimPlay("Common/login", !VAR1)
iimPlay("Test/DoSomething", !VAR1)
iimPlay("Common/logout", !VAR1)
... so I can collect a human entered value for something like a URL that each of the sub-macros use.

Is this an alien concept that isn't supported? Or, have I simply missed something in the documentation somewhere?

Thanks in advance!
Randy
User avatar
Tech Support
Posts: 4948
Joined: Tue Sep 20, 2005 7:25 pm
Contact:

Re: Passing arguments to sub-scripts?

Post by Tech Support » Wed Nov 05, 2008 9:28 pm

This is a good question! It is supported via the data extraction feature:

In the macro1 use:
PROMPT Enter<SP>target<SP>URL: !VAR1
ADD {{!EXTRACT}} !VAR1
PROMPT Enter<SP>name: !VAR1
ADD {{!EXTRACT}} !VAR1


In the script you can retrieve the "extracted" values:
iimPlay("Macro1")
url = iimGetLastExtract(1)
name = iimGetLastExtract(2)

Then you can pass the values to the next macro2:
iimSet ("myurl", url)
iimSet ("myname", name)
iimPlay("Macro2")

And inside the second macro use:
TAG ... CONTENT={{myurl}}
TAG ... CONTENT={{myname}}
RCobb1
Posts: 20
Joined: Thu Jun 26, 2008 6:19 pm

Re: Passing arguments to sub-scripts?

Post by RCobb1 » Thu Nov 06, 2008 4:07 pm

Excellent! That's exactly what I needed.

Many thank yous!
sputnik13
Posts: 3
Joined: Fri Feb 26, 2010 7:16 am

Re: Passing arguments to sub-scripts?

Post by sputnik13 » Sat Feb 27, 2010 6:38 pm

No matter what I try I cant seem to pass my var's to my scripts in javacript. I have to use 2 different macros as I need to access two different data source .csv's. Ive tried coding out the 2nd script in javascript in its entirety ... and it works if i use a static value instead of pass in the var [ which is always ends up "undefined" ]

Ive tried multiple examples and none are working

Code: Select all

var macro;
var randArticle;
var randRow
// Generate a number between 2 and 2500 
{
iimPlay("myLogin.iim")
randArticle = Math.round(15*Math.random());
iimDisplay(randArticle)
iimSet("randRow","randArticle")
iimDisplay(randRow)
iimPlay("myPost.iim")
ab30
Posts: 1
Joined: Sun Nov 06, 2011 1:55 pm

Re: Passing arguments to sub-scripts?

Post by ab30 » Sun Nov 06, 2011 2:49 pm

Tech Support wrote:It is supported via the data extraction feature:
In the macro1 use:
PROMPT Enter<SP>target<SP>URL: !VAR1
ADD {{!EXTRACT}} !VAR1
PROMPT Enter<SP>name: !VAR1
ADD {{!EXTRACT}} !VAR1
I think there may have a typo error in the code here, it should be:

PROMPT Enter<SP>target<SP>URL: !VAR1
ADD !EXTRACT {{!VAR1}}
PROMPT Enter<SP>name: !VAR1
ADD !EXTRACT {{!VAR1}}
Also, i personally can't get it to work with the new renamed iimGetExtract function:

Code: Select all

ReferenceError: iimGetExtract is not defined (Error code: 991)
But the iimGetLastExtract function works.
MattBell7
Posts: 627
Joined: Thu Nov 26, 2009 11:07 am
Location: United Kingdom

Re: Passing arguments to sub-scripts?

Post by MattBell7 » Mon Nov 07, 2011 1:04 pm

iimGetExtract is for v7.40 of the iMacros scripting interface onwards.

I don't know if they've changed it for the Javascript scripting interface in iMacros for FX.

check your version if you're using the full version though
kind03cn
Posts: 16
Joined: Mon Nov 03, 2014 10:19 pm

Re: Passing arguments to sub-scripts?

Post by kind03cn » Wed Jan 07, 2015 5:57 am

sputnik13 wrote:No matter what I try I cant seem to pass my var's to my scripts in javacript. I have to use 2 different macros as I need to access two different data source .csv's. Ive tried coding out the 2nd script in javascript in its entirety ... and it works if i use a static value instead of pass in the var [ which is always ends up "undefined" ]

Ive tried multiple examples and none are working

Code: Select all

var macro;
var randArticle;
var randRow
// Generate a number between 2 and 2500 
{
iimPlay("myLogin.iim")
randArticle = Math.round(15*Math.random());
iimDisplay(randArticle)
iimSet("randRow","randArticle")
iimDisplay(randRow)
iimPlay("myPost.iim")
I think one sentence may be wrong
iimSet("randRow","randArticle") should be changed to
iimSet("randRow",String(randArticle))
snuhhh
Posts: 5
Joined: Thu Oct 22, 2015 8:06 pm

Re: Passing arguments to sub-scripts?

Post by snuhhh » Thu Oct 29, 2015 10:43 am

Hello,

I also would like to pass a VAR created in my iim macro to a vbs loop. The purpose is to read out the number of elements in a drop down list, save it in a variable and then use this number in the vbs script in order to loop through the drop down menu.
In the following code, the counting of dropdown items works fine, but using the GetExtract command only produces a "_undefined_" output. Do you have any idea, why?

Code: Select all

schleife = "CODE:"
	schleife = schleife + "TAG POS=1 TYPE=SELECT FORM=ID:ctl00 ATTR=ID:_pageHeader_fin_dropdown_source EXTRACT=TXTALL" + vbNewLine	
    'Calculate Nb of Options in DDLB (by using the Length of the Array after a 'split()'):
    schleife = schleife + "SET DDLB_Nb_of_Options EVAL(""var s='{{!EXTRACT}}'; var x,y; y=s.split('[OPTION]'); x=y.length; x;"")" + vbNewLine
	'schleife = schleife + "PROMPT DDLB_Nb_of_Options:<SP>_{{DDLB_Nb_of_Options}}_" + vbNewLine
	schleife = schleife + "ADD !EXTRACT {{!DDLB_Nb_of_Options}}" + vbNewLine
	schleife = schleife + "TAG POS=1 TYPE=SELECT FORM=ID:ctl00 ATTR=ID:_pageHeader_fin_dropdown_source CONTENT=#{{loopNumber}} " + vbNewLine
	

	Dim recentyear, ddlb
	ddlb = 1
	recentyear = 0
	do while not (recentyear > ddlb) 'loop until last entry of dropdown reached
		recentyear = recentyear +1
		status = iim.iimSet("loopNumber", Cstr(recentyear))
		status = iim.iimSet("warte", Cstr(warte))
		status = iim.iimPlay(schleife)
		ddlb = iim.iimGetExtract(2)
		WScript.Echo ddlb
		if (recentyear > ddlb) OR (status < 0) then ' 
			exit do
		end if
	loop
Post Reply