project BLF > class BUserRole > method AdditionalUpdates

Description

This method is part of the SetPublicTables flow.
When executed, data in the input class tables (prefix t_s) is validated and found correct, and copied into the class tables (prefix t_o).
This method can be extended to do updates that do not require a validation or that involve running business methods of other business classes. These classes should be started with ADD-TO-TRANSACTION = 'true'. Also make sure to add these classes in method StopExternalInstances.


Parameters


oiReturnStatusoutputinteger


Internal usage


BLF
method BUserRole.ApiSaveUserMembership
method BUserRole.ApiSynchronise
method BUserRole.UpdateUsrRoleFromUserMnt

QadFinancials
method BUserRole.CreateUsrRoleFromRoleCIApproveRole


program code (program/buserrole.p)

<ANCESTOR-CODE>

    /* ====================================================================================== */
    /* Remove-actions;                                                                        */
    /* - Role cannot be removed if there is a WorkObject for it (checked via relations)       */
    /* - Removing a UsrRole; give warning in case there are WorkObjectScopeHolders for it     */
    /*   (WorkObject.RoleID = UsrRole.RoleID and WorkObjectScopeHolder.UsrID = UsrROle.UsrID) */
    /* - Removing a UsrRole; delete the WorkObjectScopeHolders for it                         */
    /*   (WorkObject.RoleID = UsrRole.RoleID and WorkObjectScopeHolder.UsrID = UsrROle.UsrID) */
    /* ====================================================================================== */
    assign vcRowIDListWorkObjectScopeHolde = "":U.
    for each tUsrRole where 
             tUsrRole.tc_Status = "D":U:
        <Q-4 run WorkObjectScopeHolderByUsrRole (all)  (Read)  (NoCache)  (input ?, (CompanyId) 
                                         input tUsrRole.Usr_ID, (UsrID) 
                                         input tUsrRole.Role_ID, (RoleID)
                                         output dataset tqWorkObjectScopeHolderByUsrRole) in BWorkObject >        
        if not can-find (first tqWorkObjectScopeHolderByUsrRole)
        then next.
        /* ======= */
        /* Warning */
        /* ======= */
        assign vcMessage = trim(substitute(#T-2'Are you sure you want to remove the linked user role (&1/&2) while there are still task responsibilities for it?':255(550)T-2#,(if tUsrRole.tcUsrLogin = ? then "?":U else tUsrRole.tcUsrLogin),(if tUsrRole.tcRoleName  = ? then "?":U else tUsrRole.tcRoleName))) + chr(10) + 
                           trim(#T-3'If so, then these related task responsibilities will also be removed.':255(551)T-3#).
        if oiReturnStatus >= 0
        then assign oiReturnStatus = 1.
        <M-5 run SetMessage (input  vcMessage (icMessage), 
                     input  '':U (icArguments), 
                     input  '':U (icFieldName), 
                     input  '':U (icFieldValue), 
                     input  'W':U (icType), 
                     input  3 (iiSeverity), 
                     input  tUsrRole.tc_Rowid (icRowid), 
                     input  'BLF-241':U (icFcMsgNumber), 
                     input  '':U (icFcExplanation), 
                     input  '':U (icFcIdentification), 
                     input  '':U (icFcContext), 
                     output viFcReturnSuper (oiReturnStatus)) in BUserRole>        
        /* ======================= */
        /* Hold a list with Rowids */
        /* ======================= */
        for each tqWorkObjectScopeHolderByUsrRole :
            assign vcRowIDListWorkObjectScopeHolde = vcRowIDListWorkObjectScopeHolde + chr(2) + tqWorkObjectScopeHolderByUsrRole.tc_rowid.
        end. /* for each tqWorkObject... */
    end. /* for each tUsrRole where */ 
    /* =================================================================================================== */
    /* Interactions with BWorkObject; note that this component is already referenced by the ancestor-code. */
    /* That is the reason that this code is placed AFTER the ancestor-code                                 */
    /* We use viBWorkObjectID to check if the component is already started (<> zero when already started)  */
    /* As BWordObject is handled by the ancestor-code and that is fully handled by the transaction, wo do  */ 
    /* not use StopExternalInstances to make sure that the instance is started each validation-run.        */
    /* =================================================================================================== */
    if vcRowIDListWorkObjectScopeHolde <> "":U
    then do :
        assign vcRowIDListWorkObjectScopeHolde = substring(vcRowIDListWorkObjectScopeHolde,2,-1,"CHARACTER":U).
        <I-11 {bFcAddToTransaction
             &CLASS           = "BWorkObject"}>
        <M-8 run DeleteWorkObjectScopeHolders (input  vcRowIDListWorkObjectScopeHolde (icRowIDListWorkObjectScopeHolder), 
                                       output viFcReturnSuper (oiReturnStatus)) in BWorkObject>        
        if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
        then assign oiReturnStatus = viFcReturnSuper.
        if oiReturnStatus < 0
        then do :
             <I-9 {bFcCloseAndStopInstance
            &CLASS           = "BWorkObject"}>            
            Return.
        end. /* if oiReturnStatus < 0 */
        else do :
             <I-10 {bFcCloseInstance
            &CLASS           = "BWorkObject"}>            
        end. /* if oiReturnStatus >= 0 */
    end. /* if vcRowIDListWorkObjectScopeHolder = "":U */

/* ================================================================= */
/* When deleting a Usr - Role - Company reference also delete all    */
/* related violations.                                               */
/* This cannot be done with a cascaded delete in the data model as   */
/* this delete must also trigger a create in the SODLog table.       */
/* ================================================================= */
<Q-21 assign vlFcQueryRecordsAvailable = SystSODActive (NoCache)  () in BSystem >
if vlFcQueryRecordsAvailable
then do:
    if can-find (first tUsrRole where tUsrRole.tc_Status = "D")
    or can-find (first tUsrRoleCompany where tUsrRoleCompany.tc_Status = "D")
    then do:
        <I-12 {bFcAddToTransaction
             &CLASS           = "BSODViolationRule2"}>
    
        for each tUsrRole where tUsrRole.tc_Status = "D",
            each tUsrRoleCompany where tUsrRoleCompany.tc_ParentRowid = tUsrRole.tc_Rowid:
            <M-13 run DeleteByUserRoleCompanyCategory
               (input  tUsrRoleCompany.Usr_ID (iiUsrID), 
                input  tUsrRoleCompany.Role_ID (iiRoleID), 
                input  0 (iiDomainID), 
                input  tUsrRoleCompany.Company_ID (iiCompanyID), 
                input  0 (iiSODCategory1ID), 
                input  0 (iiSODCategory2ID), 
                output viFcReturnSuper (oiReturnStatus)) in BSODViolationRule2>
            if viFcReturnSuper = -4
            then viFcReturnSuper = 0.
            else vlDeletesDone = yes.
            if viFcReturnSuper <> 0
            then oiReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0
            then do:
                <M-14 run StopExternalInstances  (output viFcReturnSuper (oiReturnStatus)) in BUserRole>
                return.
            end.
        end.
    
        for each tUsrRole where tUsrRole.tc_Status <> "D",
            each tUsrRoleCompany where
                 tUsrRoleCompany.tc_ParentRowid = tUsrRole.tc_Rowid and
                 tUsrRoleCompany.tc_Status = "D":
            <M-19 run DeleteByUserRoleCompanyCategory
               (input  tUsrRoleCompany.Usr_ID (iiUsrID), 
                input  tUsrRoleCompany.Role_ID (iiRoleID), 
                input  0 (iiDomainID), 
                input  tUsrRoleCompany.Company_ID (iiCompanyID), 
                input  0 (iiSODCategory1ID), 
                input  0 (iiSODCategory2ID), 
                output viFcReturnSuper (oiReturnStatus)) in BSODViolationRule2>
            if viFcReturnSuper = -4
            then viFcReturnSuper = 0.
            else vlDeletesDone = yes.
            if viFcReturnSuper <> 0
            then oiReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0
            then do:
                <M-20 run StopExternalInstances  (output viFcReturnSuper (oiReturnStatus)) in BUserRole>
                return.
            end.
        end.
    
        if vlDeletesDone
        then do:
            <M-15 run DeleteFinish  (output viFcReturnSuper (oiReturnStatus)) in BSODViolationRule2>
            if viFcReturnSuper <> 0
            then oiReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0
            then do:
                <M-16 run StopExternalInstances  (output viFcReturnSuper (oiReturnStatus)) in BUserRole>
                return.
            end.
            <I-17 {bFcCloseInstance
                 &CLASS           = "BSODViolationRule2"}>
        end.
        else do:
            <I-18 {bFcCloseAndStopInstance
                 &CLASS           = "BSODViolationRule2"}>
        end.
    end.
end.