Create Check Boxes Dynamically Based On File List

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
Dexter1
Pro Scripter
Posts: 64
Joined: Mon Jun 19, 2006 3:28 pm

Create Check Boxes Dynamically Based On File List

Post by Dexter1 » Mon Jun 07, 2010 4:40 pm

I maintain several databases and want to create a distribution tool which allows me to send out one or more installation files to my customers. I would like the tool to be dynamic so that I don't have to adjust whenever a database is created or retired. We use the same naming convention for each database/installation file which looks like this.

Application Name is the only variable we need to worry about.

\\NetworkLocation\ApplicationName\Production\ApplicationNameInstall.exe

What I'd like to do is have a checkbox generated for each folder in ApplicationName. The user could then select the applications they need and the tool would generate an email with all of the selected files attached.

This doesn't seem unreasonable to me but I have never done anything in this vein so I'm not sure how to go about it.
Thanks,
Josh

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

creating dynamic dialog

Post by adroege » Mon Jun 07, 2010 6:22 pm

This should give you some ideas. It dynamically builds a script with a dialog. It creates a checkbox for every folder it finds in the GetFileList> command. I'm using Macro Scheduler version 10.1.21 for this example.

[code]

IfFileExists>%TEMP_DIR%\Temp1.scp
DeleteFile>%TEMP_DIR%\Temp1.scp
Endif

WriteLn>%TEMP_DIR%\Temp1.scp,r,Dialog>Dialog1
WriteLn>%TEMP_DIR%\Temp1.scp,r, Caption=This is My Dialog
WriteLn>%TEMP_DIR%\Temp1.scp,r, Width=500
WriteLn>%TEMP_DIR%\Temp1.scp,r, Height=603
WriteLn>%TEMP_DIR%\Temp1.scp,r, Top=132
WriteLn>%TEMP_DIR%\Temp1.scp,r, Left=40


Let>GFL_TYPE=1
//GetFileList>\\NetworkLocation\ApplicationName\*.*,strFileList,;
GetFileList>s:\xfer\alan\*.*,strFileList,;
Separate>strFileList,;,folders

If>folders_count=0,End
Let>x=24
Let>y=30
Let>k=0
Repeat>k
Let>k=k+1
Let>y=y+20
Let>caption=folders_%k%
WriteLn>%TEMP_DIR%\Temp1.scp,r, CheckBox=msCheckBox%k%,%caption%,%x%,%y%,200,False
Until>k,folders_count


WriteLn>%TEMP_DIR%\Temp1.scp,r, Button=Bundle Install,20,10,89,33,3
WriteLn>%TEMP_DIR%\Temp1.scp,r, Button=Exit,120,10,100,30,2
WriteLn>%TEMP_DIR%\Temp1.scp,r,EndDialog>Dialog1

WriteLn>%TEMP_DIR%\Temp1.scp,r,Label>MainLoop
WriteLn>%TEMP_DIR%\Temp1.scp,r, Show>Dialog1,result
WriteLn>%TEMP_DIR%\Temp1.scp,r, If>result=2,End
WriteLn>%TEMP_DIR%\Temp1.scp,r, If>result=3,Bundle_Install
WriteLn>%TEMP_DIR%\Temp1.scp,r,Goto>MainLoop

WriteLn>%TEMP_DIR%\Temp1.scp,r,SRT>Bundle_Install
WriteLn>%TEMP_DIR%\Temp1.scp,r, MessageModal>Install Ready
WriteLn>%TEMP_DIR%\Temp1.scp,r, //
WriteLn>%TEMP_DIR%\Temp1.scp,r,WriteLn>%TEMP_DIR%\Temp1.scp,r, // your code here
WriteLn>%TEMP_DIR%\Temp1.scp,r, //
WriteLn>%TEMP_DIR%\Temp1.scp,r,END>Bundle_Install
WriteLn>%TEMP_DIR%\Temp1.scp,r,Label>End

//Now execute the script I just built
ExecuteFile>%TEMP_DIR%\temp1.scp

[/code]

Dexter1
Pro Scripter
Posts: 64
Joined: Mon Jun 19, 2006 3:28 pm

Post by Dexter1 » Mon Jun 07, 2010 7:45 pm

Update:
I am using the following to gather the list of folders and display them in a ListBox. Something along these lines will work, I just need a way to return the selected values and then cycle through them to fetch the appropriate attachments.

Code: Select all

Let>GFL_TYPE=1
GetFileList>\\rnodata01\scrub$\Live_Databases\*,FList,%CRLF%

Dialog>Dialog4
   Caption=Dialog4
   Width=445
   Height=250
   Top=104
   Left=16
   ListBox=msListBox1,6,11,419,97,%FList%,true
EndDialog>Dialog4
Show>Dialog4,result
Thanks,
Josh

Dexter1
Pro Scripter
Posts: 64
Joined: Mon Jun 19, 2006 3:28 pm

Post by Dexter1 » Mon Jun 07, 2010 7:59 pm

Woops, my last was a cross-post. Thanks, Adroege, this will get me on the right path!
Thanks,
Josh

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Mon Jun 07, 2010 8:18 pm

Well, based upon the code you posted using the listbox, this should loop through the items selected.

[code]

Let>GFL_TYPE=1
//GetFileList>\\rnodata01\scrub$\Live_Databases\*,FList,%CRLF%
GetFileList>s:\xfer\alan\*.*,FList,%CRLF%

Dialog>Dialog4
Caption=Dialog4
Width=445
Height=250
Top=132
Left=40
ListBox=msListBox1,6,11,419,97,%FList%,true
Button=Build Selected,72,152,81,25,4
Button=Exit,288,152,81,25,3
EndDialog>Dialog4

Show>Dialog4,result
If>result=4
GoSub>Build
Endif


SRT>Build
Separate>Dialog4.msListBox1,%CRLF%,myitems
If>myitems_count>0
Let>mySelected=0
Repeat>mySelected
Add>mySelected,1
Let>myitem=myitems_%mySelected%
MessageModal>myitem
// Do what you what here
// more code...
//
Until>mySelected,myitems_count
Endif
END>Build


[/code]

Dexter1
Pro Scripter
Posts: 64
Joined: Mon Jun 19, 2006 3:28 pm

Post by Dexter1 » Mon Jun 07, 2010 10:37 pm

Ok, rummaging through the ListBox is a bit more in line with my limited expertise. I got what you sent me working but I have one more step to complete. My file structure/naming convention throughout is \\NetworkLocation\ApplicationName\Production\ApplicationNameInstall.zip. I want to use the \\NetworkLocation\ApplicationName from the list box, add \Production\ and then search for any file with "install.zip" within the production folder. I then need them all in one string so I can attach all selected application installers to a single email.

You have been a huge help so far, thanks!
Josh

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Tue Jun 08, 2010 12:00 am

Code: Select all


Let>GFL_TYPE=1
//GetFileList>\\rnodata01\scrub$\Live_Databases\*,FList,%CRLF%
GetFileList>c:\*.*,FList,%CRLF%

Dialog>Dialog4
   Caption=Dialog4
   Width=445
   Height=250
   Top=132
   Left=40
   ListBox=msListBox1,6,11,419,97,%FList%,true
   Button=Build Selected,72,152,81,25,4
   Button=Exit,288,152,81,25,3
EndDialog>Dialog4

Show>Dialog4,result


If>result=4
  GoSub>Build
Endif

SRT>Build
  Let>Attach_string=
  Separate>Dialog4.msListBox1,%CRLF%,myitems
  If>myitems_count>0
    Let>mySelected=0
    Repeat>mySelected
      Add>mySelected,1
      Let>myitem=myitems_%mySelected%
      Let>full_path=%myitem%\Production\Install.zip
      IfFileExists>full_path
	     Let>Attach_string=%Attach_string%%full_path%;
      Endif
      // Do what you want here
      // more code...
      //
    Until>mySelected,myitems_count
  Endif
  MessageModal>Attach_string
END>Build

I then need them all in one string so I can attach all selected application installers to a single email.
Not sure how one string is going to help.... but anyway my code sample builds one string named "Attach_string" with all the file names separated by a semicolon.

Dexter1
Pro Scripter
Posts: 64
Joined: Mon Jun 19, 2006 3:28 pm

Post by Dexter1 » Tue Jun 08, 2010 2:51 pm

Is there something missing from this line?

Code: Select all

  Let>Attach_string=
The final product should look like this, assuming I selected ApplicationName1 and ApplicationName2 in my list box. So that when I call it in my generated email I have all of the attachments in one string. Does that make sense?

\\NetworkLocation\ApplicationName1\Production\ApplicationName1Install.zip;\\NetworkLocation\ApplicationName2\Production\ApplicationName2Install.zip

Thanks again for your generosity,
Josh

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Tue Jun 08, 2010 3:03 pm

Let>Attach_string=
Nothing is missing... It's just my way of initializing the variable to an empty string.

I understand now about your attachments. I assume you are aware of the SMTPSendMail> command so that you can send your email from within Macro Scheduler?

Good Luck!

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts