<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Performing scripts with python-fmrest
This is a short example on how to perform scripts with python-fmrest.
Import the module
Step1:  Create the server instance
Step2:  Login
The login method obtains the access token.
Step3:  Setup scripts
You can setup scripts to run prerequest, presort, and after the action and sorting are executed. The script setup is passed to a python-fmrest method as an object that contains the types of script executions, followed by a list containing the script name and parameter.
Step4:  You only need to specify the scripts you actually want to execute. So if you only have an after action, just build a scripts object with only the 'after' key.
Call a standard method
Scripts are always executed as part of a standard request to the server. These requests are the usual find(), create_record(), delete_record(), edit_record(), get_record() methods the Server class exposes to you.
Let's make a find and then execute a script. The script being called contains an error on purpose, so that we can later read out the error number.
Step5:  Get the last script error and result
Via the last_script_result property, you can access both last error and script result for all scripts that were called.
Step6:  We see that we had 3 as last error, and our script result was '1'. The FMS Data API only returns strings, but error numbers are automatically converted to integers, for convenience. The script result, however, will always be a string or None, even if you exit your script in FM with a number or boolean.
Another example
Let's do another call, this time with a script that takes a parameter and does not have any errors.
It will exit with Exit Script[ Get(ScriptParameter) ], so essentially give us back what we feed in.
Step7:  ... and here is the result (error 0 means no error)
<ASSISTANT_TASK:>
Python Code:
import fmrest
Explanation: Performing scripts with python-fmrest
This is a short example on how to perform scripts with python-fmrest.
Import the module
End of explanation
fms = fmrest.Server('https://10.211.55.15',
                    user='admin',
                    password='admin',
                    database='Contacts',
                    layout='Demo',
                    verify_ssl=False
                   )
Explanation: Create the server instance
End of explanation
fms.login()
Explanation: Login
The login method obtains the access token.
End of explanation
scripts={
    'prerequest': ['name_of_script_to_run_prerequest', 'script_parameter'],
    'presort': ['name_of_script_to_run_presort', None], # parameter can also be None
    'after': ['name_of_script_to_run_after_actions', '1234'], #FMSDAPI expects all parameters to be string
}
Explanation: Setup scripts
You can setup scripts to run prerequest, presort, and after the action and sorting are executed. The script setup is passed to a python-fmrest method as an object that contains the types of script executions, followed by a list containing the script name and parameter.
End of explanation
fms.find(
    query=[{'name': 'David'}],
    scripts={
        'after': ['testScriptWithError', None],
    }
)
Explanation: You only need to specify the scripts you actually want to execute. So if you only have an after action, just build a scripts object with only the 'after' key.
Call a standard method
Scripts are always executed as part of a standard request to the server. These requests are the usual find(), create_record(), delete_record(), edit_record(), get_record() methods the Server class exposes to you.
Let's make a find and then execute a script. The script being called contains an error on purpose, so that we can later read out the error number.
End of explanation
fms.last_script_result
Explanation: Get the last script error and result
Via the last_script_result property, you can access both last error and script result for all scripts that were called.
End of explanation
fms.find(
    query=[{'name': 'David'}],
    scripts={
        'prerequest': ['demoScript (id)', 'abc-1234'],
    }
)
Explanation: We see that we had 3 as last error, and our script result was '1'. The FMS Data API only returns strings, but error numbers are automatically converted to integers, for convenience. The script result, however, will always be a string or None, even if you exit your script in FM with a number or boolean.
Another example
Let's do another call, this time with a script that takes a parameter and does not have any errors.
It will exit with Exit Script[ Get(ScriptParameter) ], so essentially give us back what we feed in.
End of explanation
fms.last_script_result
Explanation: ... and here is the result (error 0 means no error):
End of explanation
<END_TASK>