Scripting for a field selected by the user in a dialogue box

6 posts / 0 new
Last post
rahulsaxena3
Offline
Joined: 01/09/2018 - 14:02
Scripting for a field selected by the user in a dialogue box

Can Anyone PLEASE help me !
I am attempting to make a dialogue box where:1) The user selects a database2) Selects upto 15-20 feilds from a drop down which are mapped in my report.3) The fields the user selects are then renamed(modified) to a particular name.4) I have a generlaised script that will then, run for further analysis basis those new fields names. The problem i am facing is - How do i script the following: 
--> Changing the user selected field from a drop down to a particular new field name i have decided, after which the rest of my script which has my analysis can run.

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

The option I would usually take is when the user selects the different fields from the drop-down I would then map the user selection to a variable and use the variable every place that the field is referenced.  You can see how I do it in this video, the tagging is near the end so you can jump closer to the end.  https://www.youtube.com/watch?v=KpaJCx72OO8&t=394s

If you want to rename all the fields then you would have to add this code for each field you want to modify:

Set db = Client.OpenDatabase("My File.IMD")
Set task = db.TableManagement
Set field = db.TableDef.NewField
field.Name = "FIELD1"
field.Description = ""
field.Type = WI_DATE_FIELD
field.Equation = "YYYYMMDD"
task.ReplaceField "FIELD", field
task.PerformTask
Set task = Nothing
Set db = Nothing
Set field = Nothing

So the set db will probably be a variable based on the file your user selected.  The task.ReplaceField the "FIELD" part will be replaced by the variable that is holding your selection from your dialog drop-down for that field and the FIELD1 would be the name of the field you want to change it to.

Hopefully that makes sense.  In my scripts I usually make my first option as I don't like to change the source file unless I absolutely have to and generally in those instances I make a copy but if this is an internal script then you can do whatever is best for your analysis.

Brian

rahulsaxena3
Offline
Joined: 01/09/2018 - 14:02

I will also take the first option (with variables) in that case, if you reccomend it. Thank you so much for a quick response. Will see your video and let you know how it goes.
 
PS. I can't thank you enough. The amount i have learnt from your forums is unbelievable.

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

Thanks Rahul, it is great to hear that you are finding the site helpful.  This is why I set it up :-)

If you get used to doing this you will find it is easier to create scripts that you can reuse with different files.

rahulsaxena3
Offline
Joined: 01/09/2018 - 14:02

Hi Brian,
I took youradvise and used your teemplate to create a simple tester script. I am trying to tell the user to select a field then, make a copy of the data base using a direct extraction with no criteria, then the script performs a field modification to chnage the name of the selected field. But the script is throwing an error. Can you please see once and tell me where im going wrong.
 
It throws an error saying "Valid Field Name Required" when i try to change the name of a field.

rahulsaxena3
Offline
Joined: 01/09/2018 - 14:02

Hi Brian, 
I figured it out on my own. No need to see it. I was writing the wrong syntax for replacing the field name !