Mbo Relation Script
This is an automation script without a launch point. This is used to define smart relations - relations that need to leverage conditional sqls in the where clause.
The following examples are some scenarios where it may be useful:
- Could be utilized to break a very complex sql where clause to simpler conditional blocks, thus improving performance in certain cases.
- Could be utilized to handle a database fetch that is dependent on the state of the application or on some user input. These are not cases for parameterized sql, but cases where the structure of the sql changes drastically depending on the conditions.
When the Mbo framework evaluates a relationship like
mbo.getMboSet("relation"), it figures out if the relation where is implemented by an automation script based on the registration of the relation
relation in the MAXREALATIONSHIP table.
The relation where clause should contain the expression
script:<script name> for the framework to execute the script named
|The source MBO record. This is inpput to the script.
|The response MboSet instance that is the target or the relation. The script is expected to create this mboset
if mbo.isNull("priority")==False:mboset = mbo.getMboSet("openwo")else:mboset = mbo.getMboSet("allwo")
Another advanced use case would be to pass certain context information from an app to the backend using api call. A sample REST call shown below:
Say we want to introduce some smart filtering on the assetmeter relation. We can replace this relation in the url with a custom one.
Now custassetmeter can be backed by an relation script that can leverage the information passed in the
ctx from the script and can come up with a smart where clause.
from psdi.iface.mic import IntegrationContextif IntegrationContext.getCurrentContext() is not None and IntegrationContext.getCurrentContext().isAPICall():val1 = IntegrationContext.getCurrentContext().getParameter("param1")#create a filter clause based on the val1 and set the mbosetelse:mboset = mbo.getMboSet("assetmeter")