Sunday, 27 December 2020

Delete a Person from a list of Person Groups (Dialog, Automation Script) | Maximo

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_PERSONID
Child Object:  NP_DELETE_PERSONID
WhereClause:          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  

  1. Create new Signature (DELETEPERSONID, Delete a Group Member)

  2. 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 MXServer
from psdi.mbo import MboConstants
from psdi.common.context import UIContext
mxServer = MXServer.getMXServer()
userInfo = mxServer.getUserInfo("maxadmin")

dbo = mboset.getMbo(0#to get non-persisitent object
origWo = dbo.getOwner() # actual mbo is the owner of non-persistent dialog's attribute
vPersonid = 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 one
    pgTeamSet = pg.getMboSet('ALLPERSONGROUPTEAM')
    pgMember = pgTeamSet.moveFirst()
    while pgMember: # Loop each person in a group
        if pgMember.getBoolean("GROUPDEFAULT") == False#it will skip the default group person
            if pgMember.getString("resppartygroup") ==vPersonid: 
                pgMember.delete() 
        pgMember = pgTeamSet.moveNext()
        
    pgSet.save()
    pg = pgSet.moveNext()

2 comments:

  1. 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.
    https://www.ibm.com/support/pages/automation-scripts-and-non-persistent-object

    ReplyDelete
  2. yes we can use them to trigger our scrits.

    ReplyDelete