Perform script on server for specific record

Hello!

I made a scrip that looks like this

Set Variable [$prim ; Value ; PrimaryKey]
Go to layout [Layout1]

Perform scrip on server [script name]

  1. Script is run from current window and I need to run the scrip on the current layout.

  2. To achive this i guess I need to query current record ID (primary key) from window and pass it as parameter to the script.
    In the script, read the parameter and go to that record.

How do I create the parameter? I tried set variable $$prim and $prim.

Anybody can give me an example how to do it.

Check this blog post:
Perform Script on Server with Audit for FileMaker Go

You may need a PSOS and pass the layout and the record primary key:

Perform Script on Server [ Specified: From list ; “Audit on server” ; Parameter: Get(LayoutName) & ¶ & MyTable::ID ; Wait for completion: Off ]

And now on server script do:

Set Variable [ $Param ; Value: Get(ScriptParameter) ] 
Set Variable [ $LayoutName ; Value: GetValue($Param; 1) ] 
Set Variable [ $RecordID ; Value: GetValue($Param; 2) ] 
# go to record
Go to Layout [ $LayoutName ; Animation: None ]
Perform Find [ Restore ] // with MyTable::ID = $ID
#

and on the end don't forget to commit. Be aware this won't work, if the record is locked by FMP if you edit it.

1 Like

hi @jojolito, welcome to the fmsoup :smile:

@MonkeybreadSoftware suggestion is good, especially if you only need to pass one or two values in the parameter.

If you need to pass more complex information to your script, look at the JSON functions.

I know it's picky, Christian, and I feel really awkward bringing it up, but didn't you mean instead for the variable in the last line to be $RecordID?

Welcome Jojolito!

Also, I hate typing extra stuff in a script, but one big exception to my rule is that I will get verbose about documentation. Being explicit about the contents of a find is a great example of self-documentation that makes skimming through a script so much easier:

Enter Find Mode [Pause Off]
Set Field [ MyTable::ID ; $RecordID ]
Perform Find

That's just me. Obviously, other opinions abound.

Jonathan

2 Likes

Welcome Jojolito,

please note that the PSoS logs in as a user and triggers the startup script ( OnFirstWindowOpen).

1 Like

This did not work, "No records match this criteria"

After changing
Perform Find [ Restore ] // with MyTable::ID = $ID
to
Perform Find [ Restore ] // with MyTable::ID = $RecordID

It works, thank you @ [MonkeybreadSoftware]
Thank you @ [jfletch]

After succsesfully running the script something strange happened.

I have a .gif file in a cointainer its a animation and it auto play. It works great in fmp desktop version and before running this script it worked in web direct. Now its stopped working.

The solution:

You may need a PSOS and pass the layout and the record primary key:

Perform Script on Server [ Specified: From list ; “Audit on server” ; Parameter: Get(LayoutName) & ¶ & MyTable::ID ; Wait for completion: Off ]

And now on server script do:

Set Variable [ $Param ; Value: Get(ScriptParameter) ] 
Set Variable [ $LayoutName ; Value: GetValue($Param; 1) ] 
Set Variable [ $RecordID ; Value: GetValue($Param; 2) ] 
# go to record
Go to Layout [ $LayoutName ; Animation: None ]
Perform Find [ Restore ] // with MyTable::ID = $RecordID
#