iiObjectId | input | integer | identity value |
icUserLogin | input | character | User that will perform the activity (Optional : when both icUserLogin and iiRoleId are empty, current user (from Session.Login) will be used) |
iiRoleId | input | integer | Role that will perform the activity (Optional : when both icUserName and iiRoleId are empty, current user (from Session.Login) will be used) |
tActivities | output | temp-table | |
oiReturnStatus | output | integer | Return status of the method. |
/* ===================================================================================================== */ /* This method gets a list of defined activity codes that can be performed on a specific business object */ /* This method takes into account : */ /* - activities which can be performed on the Component */ /* - activities related to the status of the object (ObjectStatus of CB) */ /* - activities which can be performed by User/Role (RoleBasedSecurity) */ /* - activities which can be performed by User/Role on this object (ObjectSecurity) */ /* */ /* Input : ObjectID, UserLogin (optional), Role (optional), */ /* Output: tActivities */ /* ===================================================================================================== */ /* ===================================================================================================== */ /* I Retrieve the List of Activitiese */ /* ===================================================================================================== */ /* Get all the Activities which can be performed on the status of the object */ /* If all are allowed, vcStatusCodes = '' */ <M-5 run GetActivitiesForStatus (input iiObjectId (iiObjectId), output vcStatusCodes (ocActivityCodes), output viFcReturnSuper (oiReturnStatus)) in database> if viFcReturnSuper <> 0 then oiReturnStatus = viFcReturnSuper. if viFcReturnSuper < 0 then return. /* Get All the Activities possible on this Component */ empty temp-table tActivities. if search ("appinfo/":U + lc(vcFcComponentName) + "_ac.r":U) <> ? or search ("appinfo/":U + lc(vcFcComponentName) + "_ac.p":U) <> ? then run value ("appinfo/":U + lc(vcFcComponentName) + "_ac.p":U) (input vhFcSuper, input table tActivities by-reference). /* Some Activities should be deleted */ for each tActivities WHERE tActivities.tiSequence = 0 on error undo, throw: delete tActivities. end. if not vlDraftsActive then for each tActivities where tActivities.tcName = "BrowseDrafts":U on error undo, throw: delete tActivities. end. /* If the activity is not possible for the status, delete it */ if vcStatusCodes <> "":U then for each tActivities where not can-do(vcStatusCodes,tActivities.tcName) on error undo, throw: delete tActivities. end. /* Check if object is in external control */ if vlWorkFlowActive then do : <M-25 run StartPersistence (output vhFcComponent (ohPersistence), output viFcReturnSuper (oiReturnStatus)) in database> if viFcReturnSuper <> 0 then oiReturnStatus = viFcReturnSuper. if viFcReturnSuper < 0 then return. assign vlExternalWF = (<M-26 ExternalControlId (input iiObjectId (iiObjectId)) in persistence> <> ?). end. else assign vlExternalWF = no. /* ===================================================================================================== */ /* II Check The RoleBasedSecurity */ /* a) No Role, No user was specified */ /* b) No Role, User was specified */ /* c) Role was specified */ /* ===================================================================================================== */ if iiRoleId = 0 or iiRoleId = ? then do: if (icUserLogin = "" or icUserLogin = ?) and (vcUserLogin = "" or vcUserLogin = ?) then do: /* tActivities is OK */ end. else do: /* Get all Activities based on User/Component */ <Q-17 run BusCompByActivityUser (all) (Read) (NoCache) (input vcFcComponentName, (BusComponentCode) input ?, (BusActivityCode) input ?, (UsrName) input (If icUserLogin = '':U Or icUserLogin = ? Then vcUserLogin Else icUserLogin), (UsrLogin) input (If icUserLogin = '':U Or icUserLogin = ? Or icUserLogin = vcUserLogin Then viUsrId Else 0), (UsrID) output dataset tqBusCompByActivityUser) in BBusinessComponent > for each tqBusCompByActivityUser on error undo, throw: <Q-24 assign vlFcQueryRecordsAvailable = CheckForCompany (Cache) (input viCompanyId, (CompanyId) input tqBusCompByActivityUser.tiUsrRole_ID, (UsrRoleId)) in BUserRole > if vlFcQueryRecordsAvailable = no then delete tqBusCompByActivityUser. end. /* Check the tActivities versus the tqBusCompByActivityUser */ for each tActivities on error undo, throw: find first tqBusCompByActivityUser where tqBusCompByActivityUser.tcBusComponentCode = vcFcComponentName and tqBusCompByActivityUser.tcBusActivityCode = tActivities.tcName and (tqBusCompByActivityUser.tlBusActivityDisableForWF = no or vlExternalWF = no) no-error. if available tqBusCompByActivityUser then assign tActivities.tlDefault = tqBusCompByActivityUser.tlBusActivityIsDefault. else delete tActivities. end. empty temp-table tqBusCompByActivityUser. end. /* User was specified */ end. /* No Role was specified */ else do: /* Get all Activities based on Role/Component */ <Q-16 run BusCompByRole (all) (Read) (NoCache) (input iiRoleId, (Role_ID) input vcFcComponentName, (BusComponentCode) output dataset tqBusCompByRole) in BBusinessComponent > /* Check the tActivities versus the tqBusCompByRole */ for each tActivities on error undo, throw: find first tqBusCompByRole where tqBusCompByRole.tcBusComponentCode = vcFcComponentName and tqBusCompByRole.tcBusActivityCode = tActivities.tcName and (tqBusCompByRole.tlBusActivityDisableForWF = no or vlExternalWF = no) no-error. if available tqBusCompByRole then assign tActivities.tlDefault = tqBusCompByRole.tlBusActivityIsDefault. else delete tActivities. end. empty temp-table tqBusCompByRole. end. /* A Role was specified */ /* ===================================================================================================== */ /* III Check row security */ /* ===================================================================================================== */ if vlObjectSecurityActive and ((iiRoleId <> 0 and iiRoleId <> ?) or (icUserLogin <> "" and icUserLogin <> ?) or (vcUserLogin <> "" and vcUserLogin <> ?)) then do: <M-15 run GetKeyFields (input-output vcObjectTable (bcTableName), output vcObjectPK (ocPrimaryKey), output vcObjectAK (ocAlternateKey), output vcObjectID (ocObjectID), output vcObjectStatus (ocObjectStatus), output viFcReturnSuper (oiReturnStatus)) in database> if viFcReturnSuper <> 0 then oiReturnStatus = viFcReturnSuper. if viFcReturnSuper < 0 then return. if vcObjectPK = vcObjectID then assign vcPK = string(iiObjectId). else do: <M-14 run ApiGetIdentification (input-output vcPK (bcPrimaryKey), input-output vcAK (bcAlternateKey), input-output vcRowid (bcRowid), input-output iiObjectId (biObjectId), output vcDummy (ocObjectStatusValues), output vcDummy (ocObjectStatusFieldNames), output vcObjectPK (ocPrimaryKeyFieldNames), output vcObjectAK (ocAlternateKeyFieldNames), output vcDummy (ocAlternateKeyFieldLabels), output viFcReturnSuper (oiReturnStatus)) in database> if viFcReturnSuper <> 0 then oiReturnStatus = viFcReturnSuper. if viFcReturnSuper < 0 then return. end. <Q-6 run ObjectActivities (all) (Read) (NoCache) (input vcPK, (ObjectRef) input vcFcComponentName, (BusCompCode) output dataset tqObjectActivities) in BObjectSecurity > for each tActivities where can-find (first tqObjectActivities where tqObjectActivities.tcBusComponentCode = vcFcComponentName and tqObjectActivities.tcBusActivityCode = tActivities.tcName) on error undo, throw: if iiRoleId = 0 or iiRoleId = ? then if can-find (first tqObjectActivities where tqObjectActivities.tcBusComponentCode = vcFcComponentName and tqObjectActivities.tcBusActivityCode = tActivities.tcName and tqObjectActivities.tcUsrLogin = (if icUserLogin = "" or icUserLogin = ? then vcUserLogin else icUserLogin)) then. else delete tActivities. else if can-find (first tqObjectActivities where tqObjectActivities.tcBusComponentCode = vcFcComponentName and tqObjectActivities.tcBusActivityCode = tActivities.tcName and tqObjectActivities.tiRole_ID = iiRoleId) then. else delete tActivities. end. empty temp-table tqObjectActivities. end.
define temp-table ttContext no-undo field propertyQualifier as character field propertyName as character field propertyValue as character index entityContext is primary unique propertyQualifier propertyName index propertyQualifier propertyQualifier. define dataset dsContext for ttContext. define variable vhContextDS as handle no-undo. define variable vhExceptionDS as handle no-undo. define variable vhServer as handle no-undo. define variable vhInputDS as handle no-undo. define variable vhInputOutputDS as handle no-undo. define variable vhOutputDS as handle no-undo. define variable vhParameter as handle no-undo. /* Create context */ create ttContext. assign ttContext.propertyName = "programName" ttContext.propertyValue = "database". create ttContext. assign ttContext.propertyName = "methodName" ttContext.propertyValue = "GetActivitiesForObject". create ttContext. assign ttContext.propertyName = "applicationId" ttContext.propertyValue = "fin". create ttContext. assign ttContext.propertyName = "entity" ttContext.propertyValue = "1000". create ttContext. assign ttContext.propertyName = "userName" ttContext.propertyValue = "mfg". create ttContext. assign ttContext.propertyName = "password" ttContext.propertyValue = "". /* Create input dataset */ create dataset vhInputDS. vhInputDS:read-xmlschema("file", "xml/database.getactivitiesforobject.i.xsd", ?). vhParameter = vhInputDS:get-buffer-handle("tParameterI"). vhParameter:buffer-create(). assign vhParameter::iiObjectId = <parameter value> vhParameter::icUserLogin = <parameter value> vhParameter::iiRoleId = <parameter value>. /* Connect the AppServer */ create server vhServer. vhServer:connect("-URL <appserver-url>"). if not vhServer:connected() then do: message "Could not connect AppServer" view-as alert-box error title "Error". return. end. /* Run */ assign vhContextDS = dataset dsContext:handle. run program/rpcrequestservice.p on vhServer (input-output dataset-handle vhContextDS by-reference, output dataset-handle vhExceptionDS, input dataset-handle vhInputDS by-reference, input-output dataset-handle vhInputOutputDS by-reference, output dataset-handle vhOutputDS). /* Handle output however you want, in this example, we dump it to xml */ if valid-handle(vhExceptionDS) then vhExceptionDS:write-xml("file", "Exceptions.xml", true). if valid-handle(vhOutputDS) then vhOutputDS:write-xml("file", "Output.xml", true). /* Cleanup */ vhServer:disconnect(). assign vhServer = ?. if valid-handle(vhInputDS) then delete object vhInputDS. if valid-handle(vhOutputDS) then delete object vhOutputDS. if valid-handle(vhExceptionDS) then delete object vhExceptionDS.