tCIApproveRole | output | temp-table | Temp-table that returns all CI-Approve-roles that exist. Extra flag to define if the role already existed or was newly created. |
oiReturnStatus | output | integer | Return status of the method. |
/* ============================ */ /* Assign default return status */ /* ============================ */ assign oiReturnStatus = -98. /* =============== */ /* Initialisations */ /* =============== */ empty temp-table tCIApproveRole. Empty temp-table tExternUsrRole. <M-6 run ClearData (output viFcReturnSuper (oiReturnStatus)) in BRole> /* ====================================== */ /* Check if this functionality is enabled */ /* ====================================== */ <Q-17 run SystemPropertyByAll (all) (Read) (NoCache) (output dataset tqSystemPropertyByAll) in BSystemProperty > if not can-find (first tqSystemPropertyByAll where tqSystemPropertyByAll.tlSysPropertyIsSpecCIApprove = true) then do: assign oiReturnStatus = 0. return. end. /* ======================================= */ /* Find the Approve activity for BCInvoice */ /* ======================================= */ <Q-1 run BusActivityByActCompDefault (all) (Read) (NoCache) (input 'Approve':U, (BusActitvityCode) input 'BCInvoice':U, (BusComponentCode) input ?, (BusActiivtyIsDefault) input true, (BusActivytIsActive) output dataset tqBusActivityByActCompDefault) in BBusinessComponent > find tqBusActivityByActCompDefault where tqBusActivityByActCompDefault.tcBusActivityCode = 'Approve':U and tqBusActivityByActCompDefault.tcBusComponentCode = 'BCInvoice':U and tqBusActivityByActCompDefault.tlBusActivityIsActive = true no-lock no-error. if not available tqBusActivityByActCompDefault then do: assign vcMessage = trim(substitute(#T-18'The &1 activity cannot be found for component &2.':200(3645)T-18#, trim('Approve':U), trim('BCInvoice':U))) oiReturnStatus = -3. <M-2 run SetMessage (input vcMessage (icMessage), input '':U (icArguments), input '':U (icFieldName), input '':U (icFieldValue), input 'S':U (icType), input 1 (iiSeverity), input '':U (icRowid), input 'QADFIN-2001':U (icFcMsgNumber), input '' (icFcExplanation), input '' (icFcIdentification), input '' (icFcContext), output viFcReturnSuper (oiReturnStatus)) in BRole> return. end. <Q-15 run RolePrim (Start) in BRole > /* ========================================= */ /* Find all Users that can use this activity */ /* ========================================= */ <Q-3 run UsrRoleByBusActivity (all) (Read) (NoCache) (input true, (RoleIsActive) input true, (UsrIsActive) input tqBusActivityByActCompDefault.tiBusActivity_ID, (BusActivityId) output dataset tqUsrRoleByBusActivity) in BRole > for each tqUsrRoleByBusActivity where tqUsrRoleByBusActivity.tiBusActivity_ID = tqBusActivityByActCompDefault.tiBusActivity_ID and tqUsrRoleByBusActivity.tlRoleIsActive = true and tqUsrRoleByBusActivity.tlUsrIsActive = true and substring(tqUsrRoleByBusActivity.tcRoleName, 1, 4,"CHARACTER":U) <> 'SIA-':U: /* Check if this user was already processed */ find tCIApproveRole where tCIApproveRole.tcRoleName = substring('SIA-':U + trim(tqUsrRoleByBusActivity.tcUsrLogin), 1, 20,"CHARACTER":U) no-lock no-error. if available tCIApproveRole then next. else do: create tCIApproveRole. assign tCIApproveRole.tcRoleName = substring('SIA-':U + trim(tqUsrRoleByBusActivity.tcUsrLogin), 1, 20,"CHARACTER":U). end. /* Check if the role already exists */ <Q-4 assign vlFcQueryRecordsAvailable = RolePrim (Cache) (input 0, (RoleID) input tCIApproveRole.tcRoleName, (RoleName)) in BRole > if vlFcQueryRecordsAvailable = true then do: assign tCIApproveRole.tlRoleCreated = false. next. end. else assign tCIApproveRole.tlRoleCreated = true. /* Create Role, UsrRole and RoleBusActivity */ <M-5 run AddDetailLine (input 'Role':U (icTable), input '':U (icParentRowid), output viFcReturnSuper (oiReturnStatus)) in BRole> if viFcReturnSuper <> 0 then do: assign vcMessage = trim(substitute(#T-19'Cannot create a record for table &1.':200(3646)T-19#, trim('Role':U) )) oiReturnStatus = -3. <M-9 run SetMessage (input vcMessage (icMessage), input '':U (icArguments), input '':U (icFieldName), input '':U (icFieldValue), input 'S':U (icType), input 1 (iiSeverity), input '':U (icRowid), input 'QADFIN-2005':U (icFcMsgNumber), input '' (icFcExplanation), input '' (icFcIdentification), input '' (icFcContext), output viFcReturnSuper (oiReturnStatus)) in BRole> return. end. assign tRole.RoleName = tCIApproveRole.tcRoleName tRole.RoleIsActive = true tRole.RoleDescription = substring(trim(substitute(#T-20'SI Approval for &1':22(3647)T-20#, trim(tqUsrRoleByBusActivity.tcUsrLogin))), 1, 40,"CHARACTER":U). Create tExternUsrRole. Assign tExternUsrRole.tcUsrLogin = tqUsrRoleByBusActivity.tcUsrLogin tExternUsrRole.tcRoleName = tCIApproveRole.tcRoleName tExternUsrRole.UsrRoleIsDefaultRole = false. <M-8 run AddDetailLine (input 'RoleResource':U (icTable), input tRole.tc_Rowid (icParentRowid), output viFcReturnSuper (oiReturnStatus)) in BRole> if viFcReturnSuper <> 0 then do: assign vcMessage = trim(substitute(#T-22'Cannot create a record for table &1.':200(3646)T-22#, trim('RoleBusActivity':U) )) oiReturnStatus = -3. <M-11 run SetMessage (input vcMessage (icMessage), input '':U (icArguments), input '':U (icFieldName), input '':U (icFieldValue), input 'S':U (icType), input 1 (iiSeverity), input '':U (icRowid), input 'QADFIN-2004':U (icFcMsgNumber), input '' (icFcExplanation), input '' (icFcIdentification), input '' (icFcContext), output viFcReturnSuper (oiReturnStatus)) in BRole> return. end. assign tRoleResource.RoleResourceIsDefault = false tRoleResource.Resource_ID = tqBusActivityByActCompDefault.tiResource_ID. end. /* for each tqUsrRoleByBusActivity where ... */ <Q-16 run RolePrim (Stop) in BRole > If viBUserRoleID = 0 Or viBUserRoleID = ? Then Do: <I-23 {bFcStartAndOpenInstance &ADD-TO-TRANSACTION = "True" &CLASS = "BUserRole"}> End. Else Do: <I-24 {bFcOpenInstance &CLASS = "BUserRole"}> End. <M-25 run CreateUsrRoleFromRoleCIApproveRole (input tExternUsrRole (tExtUsrRole), output viReturnUserRole (oiReturnStatus)) in BUserRole> <I-26 {bFcCloseInstance &CLASS = "BUserRole"}> if viReturnUserRole < 0 or (viReturnUserRole > 0 and oiReturnStatus = 0) then assign oiReturnStatus = viReturnUserRole. if viReturnUserRole < 0 then do : <I-27 {bFcStopInstance &CLASS = "BUserRole"}> Return. end. /* if viUsrRoleReturn < 0 */ /* =========== */ /* Validate BC */ /* =========== */ <M-12 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BRole> if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus >= 0) then assign oiReturnStatus = viFcReturnSuper. if oiReturnStatus < 0 and oiReturnStatus <> -98 then return. /* ================== */ /* Additional Updates */ /* ================== */ <M-13 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BRole> if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus >= 0) then assign oiReturnStatus = viFcReturnSuper. if oiReturnStatus < 0 and oiReturnStatus <> -98 then return. /* ======== */ /* DataSave */ /* ======== */ <M-14 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BRole> if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus >= 0) then assign oiReturnStatus = viFcReturnSuper. if oiReturnStatus < 0 and oiReturnStatus <> -98 then return. assign oiReturnStatus = 0.
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 = "BRole". create ttContext. assign ttContext.propertyName = "methodName" ttContext.propertyValue = "ApiCreateCIApproveRole". 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 = "". /* 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.