I don't understand this logic:
"if(name is not None):
thisMboSet = mbo.getThisMboSet()
thisMboSet.setWhere("name in(select displayname from person where displayname=" + name)
thisMboSet.reset()
thisMbo = thisMboSet.getMbo(0)"
If your custom attribute is on assignment and you want to set that assignment record, there is no reason to reset that. What I think you are trying to do is get the person record to get the personid. I think you'd want something like this:
personSet=mbo.getMboSet("$EMXPERSON","PERSON","displayname=:name")
personMbo=personSet.getMbo(0)
if personMbo:
personid=personMbo.getString("PERSONID")
thisMbo.setValue("LABORCODE",personid,thisMbo.NOACCESSCHECK)
That being said, I wouldn't personally feel comfortable with this customization. If you have 2 people named John Smith for example that would be a problem (display name is not unique) and you would randomly grab one of them. If you're on Oracle/DB2, that search would be case sensitive so the users would need to type it identically to how it is on the person record. And even setting LABORCODE to the PERSONID has the potential to fail because there is no requirement that they match and we have seen multiple systems where they don't.
------------------------------
Steven Shull
Projetech Inc.
------------------------------
Original Message:
Sent: 06-21-2021 17:22
From: Jhonatan Jerez
Subject: Automation Script in the Assignment Section (Quick Reporting app)
Hello,
I'll like to build an automation script to perform the following:
- A name will be entered in a custom field in the Assignment section of Quick Reporting.
- The name entered on the custom field needs to be validated against the person table (displayname)...................... I'm pulling the same list of names from the Person table so the name is selected from a lookup.
- If the two matches (entered name and displayname field in the person table), the person ID needs to be added to the assignment (specifically in the laborcode field...)
Notes: Can I use the entered name to compare with the displayname field even though the value entered is not saved in the database?
Here's what I have:
from psdi.mbo import MboRemote
from psdi.mbo import MboSetRemote
from psdi.util import MXApplicationException
from psdi.mbo import MboConstants
from psdi.server import MXServer
name = mbo.getString("NAME") <---------------------This is a custom attribute added to the assignment table.
labor = mbo.getString("LABORCODE")
if(name is not None):
thisMboSet = mbo.getThisMboSet()
thisMboSet.setWhere("name in(select displayname from person where displayname=" + name)
thisMboSet.reset()
thisMbo = thisMboSet.getMbo(0)
personid = thisMbo.getString("PERSONID")
thisMboSet.setValue("LABORCODE", personid, MboConstants.NOACCESSCHECK)
thisMboSet.save()
I have two launch points for testing purposes, (Object launch point, running after saving), and (attribute launch point, running after the custom attribute is updated with the assignee's name). Only one launch point runs at a time. I activate only one for testing but both are returning the same null pointer error.
#Administration
------------------------------
Jhonatan Jerez
Electronic Data, Inc.
------------------------------