As with all scripts, the script file itself should be placed in the scripts folder under /Agiloft/data/[kb name]/scripts. To run the script a script action should be created with the name of the script file as the action name. The script action checks to see if the file exists in the proper location when it is saved.

To use the ALget and ALset functions they must be imported from the modules. All of the Agiloft sample scripts start with importing just these functions. The standard sys module should also be imported.

import sys
# interface modules to interact with input and output xml files
from ALget import ALget
from ALset import ALset

 The rest of the script can consist of a single function unless other references are needed. The Agiloft sample scripts define a single function called 'action' and calls that function at the end.

def action(inputXMLFile, outputXMLFile):
	function parts here
.
.
.
action(sys.argv[1], sys.argv[2])

The Agiloft python scripts are always called with 2 arguments: an XML file representing the current and former record states, and a second XML file for the version of the records which should be saved to the database when the script is complete.

The following lines are required to generate XML at the end of the script:

set_data.exitAction(ALset.ACCEPT) 
     set_data.save() 


A normal Agiloft python script involves reading values, history, and user data from the input file and saving any changes to the output file.

The first step in dealing with these files is to load them into Python objects that can be later referenced.

# Load input into internal structures. This is required step before
# accessing input by API calls.
	get_data = ALget(inputXMLFile)
	set_data = ALset(outputXMLFile)

The sample scripts and examples assume the scripts are structured this way and refer to “get_data” and “set_data” when using ALget and ALset.

Related articles