Tuesday 21 January 2020

Create SR from Conduct an Inspection Module

Conduct and inspection is a new work center in Maximo 7609. The user can conduct inspection base on Asset, Location and Work orders.

One of our requirements is to have an SR again if inspection Fails., below is the solution using automation script.



1) Create Automation Script

In automation Script, we have to select create  SCRIPT Launch POINT
Use the pre-defined structure of the script name OSACTION.MXAPIINSPRESULT.CREATEINSPSR
You can change the CRATEINSPR in the above name  OSACTION.MXAPIINSPRESULT will remain the same.

Use Below Script to Create SR, this script will create SR when the user selects Yes in the inspection form that He/She wants to create SR.



from psdi.security import UserInfo
from psdi.mbo import MboServerInterface
from psdi.server import MXServer
from psdi.mbo import SqlFormat
from psdi.util import MXApplicationWarningException
mxServer = MXServer.getMXServer()
userInfo = mxServer.getSystemUserInfo()
maxadmin=userInfo.getUserName()
def startwf(a):
   actionSet = MXServer.getMXServer().getMboSet("action", a.getUserInfo());
   sqf = SqlFormat("action = :1")
   sqf.setObject(1, "action", "action", "STWFEUNRI")
   actionSet.setWhere(sqf.format())
   actionSet.reset()
   actionSet.getMbo(0).executeAction(a)

if (mbo.getString("REFERENCEOBJECT")=="LOCATION") :
 ticketid = '';
 #Check if related record already created
# iterate through the responses
 resultSet = mbo.getMboSet("INSPFIELDRESULTMAX");
 resultSetStatus = mbo.getMboSet("INSPRESULTSTATUS_INSTATUS");
 txtres = "";
 y= 0 ;
 i= 0 ;
 while i < resultSet.count():
 #for i in range(0,resultSet.count()):
  currentResult = resultSet.getMbo(i);
  currentResultStatus = resultSetStatus.getMbo(0);
  user =  currentResultStatus.getMboSet("CHANGEBY").getMbo(0)
  questionDetailSet = currentResult.getMboSet("INSPQUESTION");
  desc = questionDetailSet.getMbo(0).getString("description") + " = " + currentResult.getString("TXTRESPONSE");
  inspFieldSet = questionDetailSet.getMbo(0).getMboSet("INSPFIELD");
  #while y < inspFieldSet.count():
  for y in range(0,inspFieldSet.count()):
      inspfieldques = inspFieldSet.getMbo(y).getString("Description")
      if inspfieldques == 'Required to Create SR':
     
          groupset=mxServer.getMboSet("INSPFIELDRESULT",userInfo)
          groupset.setWhere("INSPFIELDNUM='"+inspFieldSet.getMbo(y).getString("INSPFIELDNUM")+"' and revision='"+inspFieldSet.getMbo(y).getString("REVISION")+"' and resultnum='"+ mbo.getString("resultnum")+"'  ")
          print (groupset.count())
          if groupset.count() > 0:
       
            rcaSet= mxServer.getMboSet("SR", userInfo );
            srMbo= rcaSet.add()
            rcaSet.setValue("DESCRIPTION", "FAILED INSPECTION: " + currentResult.getString("RESULTNUM"));
            rcaSet.setValue("ZZCATEGORY", questionDetailSet.getMbo(0).getString("ZZCATEGORY"));
            rcaSet.setValue("SVTYPE", questionDetailSet.getMbo(0).getString("SVTYPE"));
            rcaSet.setValue("WORKTYPE", "RM")
            rcaSet.setValue("WOSUBTYPE", "I")
            rcaSet.setValue("ZZSREQUEST", "SYSTEM");             rcaSet.setValue("SERVICEPROVIDER", questionDetailSet.getMbo(0).getString("SERVICEPROVIDER"));
            rcaSet.setValue("CONTRACT", questionDetailSet.getMbo(0).getString("CONTRACT"))
            rcaSet.setValue("COMMODITYGROUP",questionDetailSet.getMbo(0).getString("COMMODITYGROUP"))
            rcaSet.setValue("COMMODITY",questionDetailSet.getMbo(0).getString("COMMODITY"))
            rcaSet.setValue("OWNERGROUP",questionDetailSet.getMbo(0).getString("OWNERGROUP"));
            rcaSet.setValue("LOCATION",mbo.getString("LOCATION"))
            rcaSet.setValue("REPORTEDBYID", user.getString("PERSONID"))
            #gernalremarks =  resultSet.getMbo(i+1).getString("TXTRESPONSE");
            rcaSet.setValue("INTERNALPRIORITY",questionDetailSet.getMbo(0).getString("INTERNALPRIORITY"))
            rcaSet.setValue("DESCRIPTION_LONGDESCRIPTION",desc );
            ticketid = rcaSet.getString("ticketid")
            rcaSet.save()
            resultSet.save()
            startwf(srMbo)
            txtres =  txtres  +"<br/>"+ ticketid
       
      y+=1
  i+=1
 errorgroup = "inpection"
 errorkey = "inspectionmsg"
 params = [txtres]

2) Add Automation Script in Inspection Form through which you want to create SR
Goto -> Manage Inspection Form -> Select Form -> Goto Settings - > Select Automation Script
which was created it will show automatically in the list

3) Create SR

Goto-> Conduct an Inspection - > Perform Inspection Based on Asset, Location or Work order - > Complete inspection - > Select Batch Action -> Create SR

1 comment: