A revised version of the existing post Delete a Person from Person Groups (LIST VIEW QUERY) using Automation Script | Maximo.
We are going to add a dialog box on the list view of Person Group Application to choose the Person to be deleted.
1. New Non-Persistent Object with one attribute Personid
- Object Name: NP_DELETE_PERSONID
- Attribute: NP_personid
2. New Relationship from Persongroup to NP_DELETE_PERSONID
RelationShip: NP_DELETE_PERSONIDChild Object: NP_DELETE_PERSONIDWhereClause: Leave it empty
3. Dialog in the presentation (PERSONGR.XML)
<dialog id="deletepersonid" label="deletepersonid" relationship="NP_DELETE_PERSONID"><section id="1567883350896"></section><buttongroup id="deletepersonid_2"><pushbutton default="true" id="deletepersonid_2_1" label="OK" mxevent="dialogok"/><pushbutton id="deletepersonid_2_2" label="Cancel" mxevent="dialogcancel"/></buttongroup></dialog>
4. Signature and Select Action Menu in Application Designer
- Create new Signature (DELETEPERSONID, Delete a Group Member)
- Create new Select Action Menu ( ElementType: Option, Key value: DELETEPERSONID)
5. Create Object Launch Point Automation Script
- Script Name: PERSONDELETE
- Object: NP_DELETE_PERSONID (non-persisitent object we created in step 1)
- Event : Before Save, on update/add
- Script as below
from psdi.server import MXServerfrom psdi.mbo import MboConstantsfrom psdi.common.context import UIContextmxServer = MXServer.getMXServer()userInfo = mxServer.getUserInfo("maxadmin")dbo = mboset.getMbo(0) #to get non-persisitent objectorigWo = dbo.getOwner() # actual mbo is the owner of non-persistent dialog's attributevPersonid = dbo.getString("NP_PERSONID")pgWhere = service.webclientsession().getCurrentApp().getResultsBean().getMboSet().getUserAndQbeWhere()#service.error("",pgWhere)pgSet = mxServer.getMboSet('PERSONGROUP', userInfo)pgSet.setWhere(pgWhere)pg = pgSet.moveFirst()while pg: # Loop through the persongroups of list view one by onepgTeamSet = pg.getMboSet('ALLPERSONGROUPTEAM')pgMember = pgTeamSet.moveFirst()while pgMember: # Loop each person in a groupif pgMember.getBoolean("GROUPDEFAULT") == False: #it will skip the default group personif pgMember.getString("resppartygroup") ==vPersonid:pgMember.delete()pgMember = pgTeamSet.moveNext()pgSet.save()pg = pgSet.moveNext()
Great Post. Just want to make sure are we able to use Before Save, on update/add events on non persistent objects as there was limitation for these events to get triggered on non persistent objects.
ReplyDeletehttps://www.ibm.com/support/pages/automation-scripts-and-non-persistent-object
yes we can use them to trigger our scrits.
ReplyDelete