Here is a Python script for doing what you want to do. Note there are two launch points one that is on the Allow Object Creation and the other on Initialize Value. I have named them PRLINE.ADD.VALIDATE and PRLINE.ADD.COPY respectively and those names do matter as they are used in the script to determine the correct behavior.
I have also included the Maximo Deployment Tools scriptConfig so you should be able to directly deploy the script using the VS Code extension https://marketplace.visualstudio.com/items?itemName=sharptree.maximo-script-deploy
and the launch points will be created for you correctly.
Let me know if you have any questions.
Jason
# As good practice define a main entry point to the script.
# Focused on JavaScript but the principle remains.
#
# https://www.sharptree.io/blog/2021/2021-11-03-js-functions/
def main():
# There are two launch points, one to check if the record can be added
# the other to copy the value.
# In the Allow Object Creation launch point the global / implicit variable "mbo" does
# not exist and in the Initialize Value launch point the "mboset" variable does not exist.
# Define a common named variable called "check" and set it to the appropriate global variable.
check = None
if 'mboset' in globals():
check = mboset
elif 'mbo' in globals():
check = mbo
# Check that the mbo or mboset variable is available and that it is the expected PRLINE type.
if check is not None and check.isBasedOn("PRLINE"):
# Make sure we can get a reference to the owner and that it is a PR
if check.getOwner() is not None and check.getOwner().isBasedOn("PR"):
# If we are in the validate launch point then if the owner (PR) vendor is null then throw an error.
if launchPoint == "PRLINE.ADD.VALIDATE":
if check.getOwner().isNull("VENDOR"):
service.error("msggroup","msgkey")
elif launchPoint == "PRLINE.ADD.COPY":
# if in the initialize if the Mbo is to be added then copy the vendor from the parent PR
if mbo.toBeAdded():
check.setValue("CUSTOM_VENDOR", check.getOwner().getString("VENDOR"))
# Call the main function
main()
# Configuration for the script and launch points to be deployed using the VS Code Maximo development tool extension
# https://marketplace.visualstudio.com/items?itemName=sharptree.maximo-script-deploy
scriptConfig="""{
"autoscript": "PRLINE.ADD",
"description": "Automation script to validate the PR has a vendor and copy it if it does",
"version": "",
"active": true,
"logLevel": "ERROR",
"scriptLaunchPoints": [
{
"launchPointName": "PRLINE.ADD.VALIDATE",
"launchPointType": "OBJECT",
"active": true,
"description": "Automation script to validate the PR has a vendor",
"objectName": "PRLINE",
"allowObjectCreation": true
},
{
"launchPointName": "PRLINE.ADD.COPY",
"launchPointType": "OBJECT",
"active": true,
"description": "Automation script to copy the PR vendor to the line",
"objectName": "PRLINE",
"initializeValue": true
}
]
}"""
------------------------------
Jason VenHuizen
https://sharptree.iohttps://opqo.io------------------------------