I'd be happy to try and tackle it with ya when time frees up for both of us. Feel free to send me a message with your e-mail and we can chat offline.
Original Message:
Sent: 08-28-2024 12:34
From: Travis Herron
Subject: Would someone be willing to critique my work on an Automation Script?
Haven't figured it out yet, but have had to put it on the back burner for the start of our semester and a couple of other higher-priority things. But there are a couple of forum members who have offered to help!
I think it is safe to say that the Location record would already exist. Then I'd have a Person Group with an ID value the same as the Location ID. For example, Location = CS2158 already exists. Then, I'd create a Person Group with ID = CS2158.
At the time of Person Group creation, I might make the Group, Save it, then add members; or I might create it and add members then Save. Later, I might add members, remove one or more members, change which member is the Group Default, or delete the Group -- even if it has members in it. These are all things that Maximo allows for the Person Group. I want all those changes to be reflected in the corresponding Location's Users list, except for when deleting the Group, I only want the Users purged, but don't delete or change status to the Location itself.
------------------------------
Travis Herron
Pensacola Christian College
------------------------------
Original Message:
Sent: 08-28-2024 11:33
From: Matt F
Subject: Would someone be willing to critique my work on an Automation Script?
Hey Travis,
How did you make out? @Jason VenHuizen, please correct me if I'm wrong, but I think it might be best for Travis to perhaps leverage a multi-launchpoint script here? Working with Person Groups as you are, I think you'll need to manage both PERSONGROUP and PERSONGROUPTEAM. I do this in one scenario where I have a Action launchpoint script to Create a temporary person group based on a certain launch point, and then I have it delete that Person Group based on another launch point.
if launchPoint == "LAUNCHPOINT_NAME": do thiselif launchPoint == "LAUNCHPOINT_NAME2": do that
However, as I continue to think about this, if you're never create/deleting the groups themselves, but just managing the people within them, it should be fine to use only PERSONGROUPTEAM if I'm understanding correctly.
In your script, you can also set the groupdefault to 1 for the first person added. I do this in mine. If I didn't share my example with you already, let me know and I can.
------------------------------
Matt F
Original Message:
Sent: 08-16-2024 15:32
From: Travis Herron
Subject: Would someone be willing to critique my work on an Automation Script?
I'm starting to feel like I'm way off. . .
What I "simply" want is:
We have lots of Person Groups.
There's a custom boolean field on the PERSONGROUP table.
Some of those Person Groups have that boolean field checked (value = 1). For the Person Groups that have this field checked, it is also already true that the PERSONGROUP.PERSONGROUP (the ID field) will have an exactly-matching LOCATIONS.LOCATION.
For those Person Groups where that boolean is checked, then as (primary) Members are added, removed, or modified (really just if whoever is the Group Default changes -- Site Default and Org Default are irrelevant to me here in our single Org/single Site implementation), then I want those changes to be mirrored in the corresponding Location's Users list.
For example: suppose we have a rental house at 123 Main Street. I would have created a LOCATIONS record with LOCATIONS.LOCATION = 123MAIN. I also would create a Person Group with PERSONGROUP.PERSONGROUP = 123MAIN; and on this record, my custom boolean field would be checked (value = 1).
So, in this Person Group, I add Members:
--Albert, as the Group Default, Sequence 1
--Billy, Sequence 2
--Charlie, Sequence 3
What I want to happen is that Albert, Billy, and Charlie are added as Users to LOCATIONUSERCUST for Location = 123MAIN; and Albert would be the primary User.
Later, Albert gets removed from the Person Group. To allow that to happen, Charlie gets set as the Group Default. At the same time, Doug is added as a new member of the Person Group.
So now the same should be seen in the LocationUserCust list for 123MAIN: Charlie is now the primary user, Doug is added as a user, Albert is deleted from the user list.
My initial attempts were to do this for each record in PERSONGROUPTEAM, but there were times I would get an error stating that someone needed to be the primary. I presume that's due to that I had changed the Group Default within the Person Group, so two records got updated, so the script should have fired for both of them, and it happened to have processed the one who was no longer the Group Default first, so that on the LocationUserCust side there wouldn't have been anyone marked as the Primary.
So now I think I need to have this as an Object Launch Point script on Object = PERSONGROUP, not PERSONGROUPTEAM.
------------------------------
Travis Herron
Pensacola Christian College
Original Message:
Sent: 08-16-2024 11:49
From: Jason VenHuizen
Subject: Would someone be willing to critique my work on an Automation Script?
Hi Travis,
Sorry for the late response to this, I am not sure how I missed it earlier.
For critiques, here we go:
You can import multiple classes from a package like so:
from psdi.mbo import MboSetRemote, MboRemote, MboConstants
That said, you are not using MboSetRemote or MboRemote in your code so those are not required.
That brings us to the MboConstants, which for every entry you are skipping validation and read-only rules. There are cases when this is valid and desirable, but as a default position you should be working in a way that respects Maximo's business rules and generally these should not be required.
As Manu pointed out, you are trying to set a value on the set and not on a specific record. Note that this also applies to your ondelete code. I am a little unclear on logic, but what I think you want is:
locationusercustSet = mbo.getMboSet("PCC_LOCATIONUSERCUST_LOCATION") locationusercust = locationusercustSet.getMbo(0) # get the first Mbo and I assume only # locationusercust = locationusercustSet.moveFirst() # This is another way of doing the same thing. locationusercust.setValue("ISPRIMARY", groupdefault)
You may not have included the full script, but it groupdefault is not defined anywhere in the script, so you will need to make sure that is defined somewhere.
Next, you are saving and closing the set, which is going to cause a problem since you retrieved the set off a relationship from the parent. In this case you do not need or want to either save or close the set because its lifecycle is going to be handled by the parent Mbo. When the parent Mbo saves and closes so will the part of the transaction you are adding here.
Some other things I would consider are checking that the implicit mbo variable is set as a matter of defensive programming. Something like this.
if 'mbo' in globals():
Same goes for any other implicit / global variables you are using such as onupdate, ondelete, etc.
You may also want to consider using a main function as I describe here: https://www.sharptree.io/blog/2021/2021-11-03-js-functions/
I find this is just a good pattern to follow and helps keep a clear execution path.
If you have any specific questions, feel free to reach out.
Regards,
Jason
------------------------------
Jason VenHuizen
Sharptree