Sample script to run a macro...

14 posts / 0 new
Last post
drumond
Offline
Joined: 02/19/2014 - 06:13
Sample script to run a macro...

Does anybody have an IDEAscript to run a macro?

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Hi Drumond,

Are you talking about running an IDEAScript from another IDEAScript?  If so you can see this thread that has an example on how to do it: http://ideascripting.com/forum/call-script-within-script

Or do you mean something else with macro like an Excel macro?

Brian

drumond
Offline
Joined: 02/19/2014 - 06:13

 
Hi Brian
Thanks for your reply.
 
My question was not complete. Sorry!
 
What I meant was a sample IDEAscript to define an action field to run a macro.
 
More specific: What I need to know is the set of parameters for tableField.SetActionFieldForIDEAScript
 
drumond
 

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Hi Drumond,

I don't know the parameters off hand but I have a script on my home computer that uses this so I will look it up tonight or this weekend and get back toyou.

Brian

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57
Hi Drumond, here is some example code that will hopefully help you out.
Const AF_FIELD = 2
Const AF_RECORDNUMBER = 0
Const AF_USERDEFINETEXT = 1

Sub Main

End Sub

Function addActionField()
	Dim db As database
	Dim table As table
	Dim field As field
	
	Set db=Client.OpenDatabase("my database.imd)
	Set table = db.TableDef
	Set field = table.GetField("MY_FIELD" )

	'1st parameter is script name
	'Then takes up to 4 parameters to send to script, for more than that a work around is to create a text file and save the variables in the text file
	'Each set of parameters first states if this is a field (2 - AF_FIELD) record number (0 - AF_RECORDNUMBER) or user defined text (1 - AF_USERDEFINETEXT )
	'In this example the first 2 set of parameters is referencing FIELD1 and FIELD2 so the contents of these fields will be sent.
	'The last two parameters are defined as user defined and being sent blank information.
	field.SetActionFieldForIDEAScript "My Script.iss", AF_FIELD,  "FIELD1", AF_FIELD, "FIELD2", AF_USERDEFINETEXT ,  "", AF_USERDEFINETEXT ,  ""
	
	Set db = Nothing
	Set table = Nothing 
	Set field = Nothing
End Function

 

drumond
Offline
Joined: 02/19/2014 - 06:13

 Hi Brian,
 Thank you very much for your help.
 This sample of code works fine. It is just  what I was looking for.
 Regards
Drumond 

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Glad I could help.

bakerroll
Offline
Joined: 01/29/2014 - 13:59

Hi Brian - I am experimenting for the first time with scripting the action field that will run a macro.  I have your script from above that is setting up the action field and it has worked correctly - I now have the action field. I am stuck on how do i get the parameters to pass? The scenario:
The action field is on a table that was created by suymmarizing on EMPLIDs.  The EMPLID field is my action field. When the user clicks on an EMPLID on this table i want a different script to run that will basically open the original transaction file, extract all transactions matching that EMPLID then summarizing the activty and charting it.  So i only have 1 paramter to pass - it is type AF_FIELD and the field name is "EMPLID" - the rest of the parameters are blank (""). So, in my testing to see if it is working I click on the EMPLID and the script runs to completion but it is not picking up the parameter EMPLID (so it is running the script against all transactions instead of just the ones for that EMPLID).  When running a script from within a script the variables that have to be used are arg1, arg2, arg3, and arg4.  Are there specific variable for this that have to be used as well? Thanks for any help.

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Hi bakerroll,

I have attached an example for you.  So in the database you would select define action field, select the IDEAScript to run, in my example it is the Action Field Demo.iss and then in the first parameter go in and select the field, such as the EMPLID.  Now when it runs the script arg1 will have the contents of that parameter, and you can either transfer arg1 to another varialbe or use it in your script.  The next message will contain the contents of the script, for some strange reason at work I can't mix code with other items, no idea why.

Brian

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57
Sub Main
	
	Set db = Client.OpenDatabase("Action Field Demo-Sheet1.IMD")
	Set task = db.Extraction
	task.IncludeAllFields
	dbName = client.UniqueFilename("Emplid " & arg1 )
	task.AddExtraction dbName, "", "EMPLID == """ & arg1 & """"
	task.CreateVirtualDatabase = False
	task.PerformTask 1, db.Count
	Set task = Nothing
	Set db = Nothing
	Client.OpenDatabase (dbName)
	client.RefreshFileexplorer
End Sub

 

bakerroll
Offline
Joined: 01/29/2014 - 13:59

Thank you for the help, Brian. It is working. 

Pages