Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 6064 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

Hello

I have written a script that works (this is my first one so I am rather proud).

It is a script that via a button click creates a record and copy & pastes certain info from either fields or value lists from one table to another.

A pict of the script is attached.

My problem is that it is not very elegant and prone to going mad on occasion. So I am asking my betters to show me how to make it more stable & efiecient.

PS. I know it rather basic but we all have to start somewhere.

Picture_1.png

Posted

Do away with the copy and paste.

You can use Set Field for these, and you do NOT have to keep going back to the layouts, as the Set Field doesn't require the field to be on the current layout.

Lee

Posted

Just thinking here...

Another possibility is to make use of FM's lookup and default value options to set the fields automatically when the record is created. That could reduce your script to a simple Add New Record.

A third option would be to pass the field values into the script from the button, using these parameters to set the field values in the script without going to and fro.

These approaches depend on the rules and structure of your application, though.

David

Posted

Well, Lee is right about copy/paste. And David is right about alternate approach of using lookups or variables but ...

and copy & pastes certain info from either fields or value lists from one table to another.

... the fact that you are duplicating data from one table to another actually suggests that you are not taking advantage of relationships. Redundant data shouldn't happen; particularly on a per record basis (as you are doing). It indicates that this is NOT a full-blown archive process even ... but rather moving data around manually instead of relating it.

Can you explain your purpose here and allow others to possibly give you alternate approaches to achieve it? Moving data is 1) wasteful of resources/time, 2) opens up possibility of error (power loss in middle of script moving process etc) and 3) makes keeping the data in sych a nightmare.

LaRetta

Posted

All good advice so far. There are many techniques that may work in a given situation. Here is one that is not necessarily optimal, but would be reliable and I think is easy to understand:

(Starting from your found set...)

Loop

 Set Variable[ $projectID ; Project ID ]

 Set Variable[ $invID ; Inventory ID ]

  ...

 Go to layout[ Machine Movement ]

 New Record

 Set Field[ Project ID ; $projectID ]

 Set Field[ Inventory ID ; $invID ]

  ...

 Go to layout[ original layout]

 Go to record[ Next ; exit after last ]

End Loop

The concept is: for each item that you wish to "copy," use Set Variable, and then for each item that you wish to "paste" use a corresponding Set Field.

Posted

... the fact that you are duplicating data from one table to another actually suggests that you are not taking advantage of relationships. Redundant data shouldn't happen; particularly on a per record basis (as you are doing). It indicates that this is NOT a full-blown archive process even ... but rather moving data around manually instead of relating it.

: *******.

I Zeroed in on the steps, and ignored what was being done. Good catch LaRetta.

Lee

Posted

Thank you for all your suggestions.

Sorry that I did not think to be more precise. This is a way copy barcode and associated info from an 'input' page that when filled creates a record. What I have not worked how to do is to empty all the input fields once the script button has been pushed.

Posted

I am having a little trouble getting this to work. I think it has something to do with the :

Set Variable[ $projectID ; Project ID ]

Set Variable[ $invID ; Inventory ID ]

The set variable comes up empty when I ask it to look at Project ID field for example. yet if I set just a piece of text in the calc, it xfers the info.

As I am having alot of trouble understanding what a variable is (I find the manual explanation completely nonsensical for a neophyte as myself). I get the impression that it does lots of things. What does Variable mean in FM. A piece of info that can change? Why is this a variable action. There does not seem to very much variable for me.

Anyway, a few of the fields in the layout are drop down menus. I presume that if I can copy them, the variable can see them.

Many thanks in advance for any suggestions

PS Lee, thanks for the clear suggestion.

Posted

A variable is just a 'space' where you can place data that you wish to temporarily store for further use.

You give variables names so that you can have more than one such 'space' and any name that begins with one '$' exists only for the life of the script that creates it while any name that begins with '$$' can be passed from script to script should you need it to.

If it helps then visualise variables as those scribbled notes that one makes at the side of a piece of work cos I use them in much the same way.

hth

Phil

Posted

In addition to what Phil said, another way to think about a variable is by visualizing a container. You can put a bunch of stuff in it and from then on you can call it what you would like such as toys or food etc. You can still access all the stuff you put in it as it doesnt change. The stuff is your data and the variable is your container. The local variables can only be used within the script, whereas the global variable can be used throughout the file until either you empty it yourself or close the file.

Posted

Thank you very much for the very clear explanations. I now understand the concept behind the above script and it helped me find the solution to why it was not working for me. I personally would like FM to take your descriptions rather than the incomprehensible jargon in their help.

This topic is 6064 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.