Automatically run the same script multiple times

10 posts / 0 new
Last post
Mike72
Offline
Joined: 06/04/2018 - 06:29
Automatically run the same script multiple times

 
I have a table where all records have a unique id number. Very simply put I have a script that stores the data from a specific record in a new table. The problem is that i have a list of hundreds of ID’s that need to get stored in an individual table. Instead of running the script manually a couple of hundred times, each time with a different ID number, i would like to automate this. It should go through the list running the script for each ID number. I have searched the forum but i couldn’t find a matching topic. I was thinking about a loop function but my knowledge of idea script is to limited at this time. Can you help me please?
  
See the attached excel file for a simple example:
  
Thank you!Best regards, Mike

klmi
Offline
Joined: 02/13/2019 - 08:41

You can solve your problem by using a for loop:
 
for i in range(min, max):
       do_something()
 
Example: http://ideascripting.com/forum/experiences-python

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

Hi Mike,

Are you looking for an a python or IDEAScript answer to this?  Klmi supplied the python and in IDEAScript you would need a for loop such as:

for i = 1 to count

    do something

next i

 

Mike72
Offline
Joined: 06/04/2018 - 06:29

Hi Brian, i was just trying some things and to be honest i did not understand much of Klmi his or her's solution. I am looking for an ideascript. I allready got it working with the for i next i script, but now i run into another problem. In the extractian part i use an @isini function (see script: eqn = "@Isini(""" & keyword & """;VELD1)") . The problem with this is that i need an exact match with the keyword. For example when i search for records in table A with the keyword 1 from Table B, it will show not only 1 as a result, but also 10. There should be only the record with 1 as a result from the @isini function. Is there a way to add script to the @isini function so that the result is only an exact match. I hope you still follow me.
 
I added a txt with my script.
 

Mike72
Offline
Joined: 06/04/2018 - 06:29

Hi Brian, i solved my problem mentioned in the previous comment, i used the @match function instead of the @isini function.

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

That is great, thanks for letting me know.

Brian

Mike72
Offline
Joined: 06/04/2018 - 06:29

Hi Brian, the script (see attached file) works fine, however this script only works when the keyword field and field to match are character fields. What if those fields are numeric fields. What can i change in my script to use it with numeric fields. I've tried some different things but none of them worked.
 
Thanks!
 
 

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

Hi Mike,

What you need to do is first test to see if the field is numeric or character.  You can use the field.IsNumeric - field.IsCharacter for this test.  Create a variable to hold the results.

Next when you are extracting the value of the field your code would be:

if sFieldType = "Char" then 'assumes that your variable to hold the type has Char for a characteter field

     keyword = rec.GetCharValueAt(1)

else 'if not character then numeric

     keyword = rec.GetNumValueAt(1)

end if

Call Step_02(keyword, sFieldType )

Also you will have to redefine your keyword as variant so it can hold either string or numeric items.

For Step_02 change the (ByVal keyword As String) to (ByVal keyword As Variant, ByValy sFieldType as string) if you don't do this IDEA will give an error as the item being received has to be of the same type as the item being sent.  You also have to send over the field type.

If the step 2 function you will need to change the equation depending on the field type

if sFieldType = "Char" then

     eqn = "@match(DATAFIELD_1;""" & keyword & """)"

else

     eqn = "DATAFIELD_1= " & keyword & ")"

end if

Hopefully this makes sense.  I haven't actually tested the code so I might have a typo in the above code.

Good luck in your project.

Brian

Mike72
Offline
Joined: 06/04/2018 - 06:29

Hi Brian i took only the numeric part of your solution because the relevant fields in my tables where numeric so i didn't have to check whether they where char or num. And it worked great so my problem is solved!
Thanks for your help.
Mike

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

That is great to hear, thanks for letting me know.

Brian