project BLF > class BUserRole > method SetPublicTables

Description

Updates the contents of the class dataset.
When requested, the input data will be validated first, and the class dataset will only be updated when the input data is correct.
When no validation is requested, the input data is written to the class dataset unconditionally, but this data cannot be written to the database (method DataSave will return an error). The data can only be saved as a draft instance.


Parameters


il_Validateinputlogicalvalidate input data
BUserRoleinputdatasetclass dataset
oiReturnStatusoutputintegererror status


program code (program/buserrole.p)

    for each t_sUsrRole:
        if t_sUsrRole.tc_Status = "D":U
        then do:
            run gipr_Delete_sUsrRoleCompany (input t_sUsrRole.tc_Rowid).
            run gipr_Delete_sUsrRoleDomain (input t_sUsrRole.tc_Rowid).
            run gipr_Delete_sUsrRoleScope (input t_sUsrRole.tc_Rowid).
        end.
        find first tFcRowidConvert where
                   tFcRowidConvert.tcFcOldRowid = t_sUsrRole.tc_Rowid and
                   tFcRowidConvert.tlFcOk       no-error.
        if available tFcRowidConvert
        then assign t_sUsrRole.tc_Rowid = tFcRowidConvert.tcFcNewRowid.
    end.

    for each t_oUsrRole where
        not can-find (t_sUsrRole where t_sUsrRole.tc_Rowid = t_oUsrRole.tc_Rowid):
        create t_sUsrRole.
        raw-transfer t_oUsrRole to t_sUsrRole.
    end.

    for each t_sUsrRoleCompany:
        find first tFcRowidConvert where
                   tFcRowidConvert.tcFcOldRowid = t_sUsrRoleCompany.tc_ParentRowid and
                   tFcRowidConvert.tlFcOk       no-error.
        if available tFcRowidConvert
        then assign t_sUsrRoleCompany.tc_ParentRowid = tFcRowidConvert.tcFcNewRowid.
        find first tFcRowidConvert where
                   tFcRowidConvert.tcFcOldRowid = t_sUsrRoleCompany.tc_Rowid and
                   tFcRowidConvert.tlFcOk       no-error.
        if available tFcRowidConvert
        then assign t_sUsrRoleCompany.tc_Rowid = tFcRowidConvert.tcFcNewRowid.
    end.

    for each t_oUsrRoleCompany where
        not can-find (t_sUsrRoleCompany where t_sUsrRoleCompany.tc_Rowid = t_oUsrRoleCompany.tc_Rowid) and
        not can-find (t_sUsrRole where t_sUsrRole.tc_Rowid = t_oUsrRoleCompany.tc_ParentRowid and t_sUsrRole.tc_Status = "D":U):
        create t_sUsrRoleCompany.
        raw-transfer t_oUsrRoleCompany to t_sUsrRoleCompany.
    end.

    for each t_sUsrRoleDomain:
        find first tFcRowidConvert where
                   tFcRowidConvert.tcFcOldRowid = t_sUsrRoleDomain.tc_ParentRowid and
                   tFcRowidConvert.tlFcOk       no-error.
        if available tFcRowidConvert
        then assign t_sUsrRoleDomain.tc_ParentRowid = tFcRowidConvert.tcFcNewRowid.
        find first tFcRowidConvert where
                   tFcRowidConvert.tcFcOldRowid = t_sUsrRoleDomain.tc_Rowid and
                   tFcRowidConvert.tlFcOk       no-error.
        if available tFcRowidConvert
        then assign t_sUsrRoleDomain.tc_Rowid = tFcRowidConvert.tcFcNewRowid.
    end.

    for each t_oUsrRoleDomain where
        not can-find (t_sUsrRoleDomain where t_sUsrRoleDomain.tc_Rowid = t_oUsrRoleDomain.tc_Rowid) and
        not can-find (t_sUsrRole where t_sUsrRole.tc_Rowid = t_oUsrRoleDomain.tc_ParentRowid and t_sUsrRole.tc_Status = "D":U):
        create t_sUsrRoleDomain.
        raw-transfer t_oUsrRoleDomain to t_sUsrRoleDomain.
    end.

    for each t_sUsrRoleScope:
        find first tFcRowidConvert where
                   tFcRowidConvert.tcFcOldRowid = t_sUsrRoleScope.tc_ParentRowid and
                   tFcRowidConvert.tlFcOk       no-error.
        if available tFcRowidConvert
        then assign t_sUsrRoleScope.tc_ParentRowid = tFcRowidConvert.tcFcNewRowid.
        find first tFcRowidConvert where
                   tFcRowidConvert.tcFcOldRowid = t_sUsrRoleScope.tc_Rowid and
                   tFcRowidConvert.tlFcOk       no-error.
        if available tFcRowidConvert
        then assign t_sUsrRoleScope.tc_Rowid = tFcRowidConvert.tcFcNewRowid.
    end.

    for each t_oUsrRoleScope where
        not can-find (t_sUsrRoleScope where t_sUsrRoleScope.tc_Rowid = t_oUsrRoleScope.tc_Rowid) and
        not can-find (t_sUsrRole where t_sUsrRole.tc_Rowid = t_oUsrRoleScope.tc_ParentRowid and t_sUsrRole.tc_Status = "D":U):
        create t_sUsrRoleScope.
        raw-transfer t_oUsrRoleScope to t_sUsrRoleScope.
    end.

    if il_Validate
    then do:
        { includes/bfcrun.i
          &procedure  = "CheckValidationExceptionList"
          &parameters = "input true, output vl_validate" }
    end.

    if vl_Validate
    then do:
        { includes/bfcrun.i
          &procedure  = "gipr_CompleteSTables" }
        { includes/bfcrun.i
          &procedure  = "ValidateComponent"
          &parameters = "output oiReturnStatus" }
    end.

    if oiReturnStatus >= 0
    then do:
        { includes/bfcrun.i
          &procedure  = "gipr_SetTables"
          &parameters = "output viFcReturnSuper" }
        if viFcReturnSuper <> 0
        then assign oiReturnStatus = viFcReturnSuper.
    end.

    if  il_Validate
    and oiReturnStatus >= 0
    then do:
        { includes/bfcrun.i
          &procedure  = "AdditionalUpdates"
          &parameters = "output viFcReturnSuper" }
        if viFcReturnSuper <> 0
        then assign oiReturnStatus = viFcReturnSuper.
    end.

    if oiReturnStatus >= 0
    then assign vlFcDataValidated = il_Validate.