project BLF > class BUserRole > method UpdateUsrRoleFromUserMnt

Description

Update UsrRole, run in BUsr : AddUpd
Used to delete UsrRoleDomain record if UsrDomain gets deleted, same for UsrRoleCompany.


Parameters


tUsrDomainUpdateinputtemp-table
tUsrCompanyUpdateinputtemp-table
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program7/buserrole.p)

If oiReturnStatus = 0
Then Assign oiReturnStatus = -98.

/* Return if no changed data is available */
if not can-find (first tUsrDomainUpdate where 
                       tUsrDomainUpdate.tc_Status = "D":U) And
   not can-find (first tUsrCompanyUpdate where 
                       tUsrCompanyUpdate.tc_Status = "D":U)
then Do:
    Assign oiReturnStatus = 0.
    return.                
End.
       
/* First load the required userroles  */ 
Assign vcFreeform = 'For Each UsrRole Where ':U
       vcLoadUserIDs = "". 

For Each tUsrDomainUpdate Where
         tUsrDomainUpdate.tc_Status = "D":U:
    If Lookup(String(tUsrDomainUpdate.Usr_ID),vcLoadUserIDs) = 0
    Then Do:
        Assign vcLoadUserIDs = vcLoadUserIDs + "," + String(tUsrDomainUpdate.Usr_ID).
        If vcFreeform = 'For Each UsrRole Where ':U
        Then Assign vcFreeform = vcFreeform + 'UsrRole.Usr_ID = ':U + String(tUsrDomainUpdate.Usr_ID).
        Else Assign vcFreeform = vcFreeform + ' Or UsrRole.Usr_ID = ':U + String(tUsrDomainUpdate.Usr_ID).
    End. /*If Lookup(String(tUsrDomainUpdate.Usr_ID),vcLoadUserIDs) = 0*/
End. /*For Each tUsrDomainUpdate Where*/

For Each tUsrCompanyUpdate Where
         tUsrCompanyUpdate.tc_Status = "D":U:
    If Lookup(String(tUsrCompanyUpdate.Usr_ID),vcLoadUserIDs) = 0
    Then Do:
        Assign vcLoadUserIDs = vcLoadUserIDs + "," + String(tUsrCompanyUpdate.Usr_ID).
        If vcFreeform = 'For Each UsrRole Where ':U
        Then Assign vcFreeform = vcFreeform + 'UsrRole.Usr_ID = ':U + String(tUsrCompanyUpdate.Usr_ID).
        Else Assign vcFreeform = vcFreeform + ' Or UsrRole.Usr_ID = ':U + String(tUsrCompanyUpdate.Usr_ID).
    End. /*If Lookup(String(tUsrCompanyUpdate.Usr_ID),vcLoadUserIDs) = 0*/
End. /*For Each tUsrCompanyUpdate Where*/

    
<M-10 run DataLoad
   (input  '' (icRowids), 
    input  '' (icPkeys), 
    input  '' (icObjectIds), 
    input  vcFreeForm (icFreeform), 
    input  False (ilKeepPrevious), 
    output viFcReturnSuper (oiReturnStatus)) in BUserRole>    
if viFcReturnSuper <> 0 And viFcReturnSuper <> -4
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 And viFcReturnSuper <> -4
then return.

If viFcReturnSuper = -4
Then Do:
    Assign oiReturnStatus = 0.
    Return.
End.

<Q-20 run CompanyByDomainActive
   (Start) in BCompany >
For Each tUsrDomainUpdate Where
         tUsrDomainUpdate.tc_Status = "D":U:
    For Each tUsrRoleDomain Where
             tUsrRoleDomain.Domain_ID = tUsrDomainUpdate.Domain_ID:
        Assign tUsrRoleDomain.tc_Status = 'D':U.
    End. /*For Each tUsrRoleDomain Where*/

    <Q-19 run CompanyByDomainActive (all) (Read) (NoCache)
       (input ?, (CompanyId)
        input tUsrDomainUpdate.Domain_ID, (DomainId)
        input ?, (CompanyIsActive)
        output dataset tqCompanyByDomainActive) in BCompany >

    For Each tqCompanyByDomainActive:
        For Each tUsrRoleCompany Where
                 tUsrRoleCompany.Company_ID = tqCompanyByDomainActive.tiCompany_ID:
            Assign tUsrRoleCompany.tc_Status = 'D':U.
        End. /*For Each tUsrRoleCompany Where*/
    End. /*For Each tqCompanyByDomainActive:*/
End. /*For Each tUsrDomainUpdate:*/
<Q-21 run CompanyByDomainActive
   (Stop) in BCompany >

For Each tUsrCompanyUpdate Where
         tUsrCompanyUpdate.tc_Status = "D":U:
    For Each tUsrRoleCompany Where
             tUsrRoleCompany.Company_ID = tUsrCompanyUpdate.Company_ID:
        Assign tUsrRoleCompany.tc_Status = 'D':U.
    End. /*For Each tUsrRoleCompany Where*/
End. /*For Each tUsrCompanyUpdate:*/    

For Each tUsrRole:
    If Not Can-find(First tUsrRoleDomain Where
                          tUsrRoleDomain.tc_ParentRowid = tUsrRole.tc_Rowid And
                          tUsrRoleDomain.tc_Status <> 'D':U)
    Then Do:
        Assign tUsrRole.tc_Status = 'D':U.
        For Each tUsrRoleDomain Where
                 tUsrRoleDomain.tc_ParentRowid = tUsrRole.tc_Rowid:
            Assign tUsrRoleDomain.tc_Status = ''.
        End.
        For Each tUsrRoleCompany Where
                 tUsrRoleCompany.tc_ParentRowid = tUsrRole.tc_Rowid:
            Assign tUsrRoleCompany.tc_Status = ''.
        End.
    End. /*If Not Can-find(First tUsrRoleDomain Where*/
End. /*For Each tUsrRole:*/
    
   
<M-14 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BUserRole>    
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 
then return.
        
Assign vlNeedsUpdateMfgUserDomain = False.
<M-15 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BUserRole>
Assign vlNeedsUpdateMfgUserDomain = True.
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 
then return.

<M-16 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BUserRole>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 
then return.

If oiReturnStatus = -98
Then Assign oiReturnStatus = 0.