project BLF > class BUser > method LinkCompanyToDaemonUsers
Description
Link the company to all users that are used in the daemon and also link it to the user that is currently logged on.
Parameters
Internal usage
BLF
program code (program1/buser.p)
If oiReturnStatus = 0
Then Assign oiReturnStatus = -98.
/*find all users linked to a daemon*/
ASSIGN vcFreeForm = ''.
<Q-1 run DaemonLoginInfo (all) (Read) (NoCache)
(input ?, (DaemonName)
output dataset tqDaemonLoginInfo) in BBaseDaemon >
for each tqDaemonLoginInfo where
tqDaemonLoginInfo.tcDaemonLogin <> '':U and
tqDaemonLoginInfo.tcDaemonLogin <> ?
break by tqDaemonLoginInfo.tcDaemonLogin:
if first-of(tqDaemonLoginInfo.tcDaemonLogin)
then do:
<Q-9 assign vlFcQueryRecordsAvailable = UserPrim (NoCache)
(input ?, (UsrId)
input tqDaemonLoginInfo.tcDaemonLogin, (UsrLogin)) in BUser >
if vlFcQueryRecordsAvailable
then do:
If vcFreeForm = ''
Then Assign vcFreeForm = "For each Usr where UsrLogin = '":U + tqDaemonLoginInfo.tcDaemonLogin + "'":U.
Else Assign vcFreeForm = vcFreeForm + " Or UsrLogin = '":U + tqDaemonLoginInfo.tcDaemonLogin + "'":U.
end.
end.
end.
/* Also link the company to the user that is currently logged on */
If vcFreeForm = ''
Then Assign vcFreeForm = "For each Usr where UsrLogin = '":U + vcUserLogin + "'":U.
Else Assign vcFreeForm = vcFreeForm + " Or UsrLogin = '":U + vcUserLogin + "'":U.
If vcFreeForm = ''
Then Do:
Assign oiReturnStatus = 0.
Return.
End.
<M-2 run DataLoad
(input '' (icRowids),
input '' (icPkeys),
input '' (icObjectIds),
input vcFreeForm (icFreeform),
input False (ilKeepPrevious),
output viFcReturnSuper (oiReturnStatus)) in BUser>
If viFcReturnSuper <> 0
Then Assign oiReturnStatus = viFcReturnSuper.
If viFcReturnSuper < 0
Then Return.
For Each tUsr:
for each tLinkCompanyToDaemonUsers:
if tLinkCompanyToDaemonUsers.tcDomainCode = '' or
tLinkCompanyToDaemonUsers.tcDomainCode = ?
then next.
/* first domain linked is also the default domain */
vlDefault = not can-find(first tUsrDomain where tUsrDomain.tc_ParentRowid = tUsr.tc_Rowid).
if not can-find(first tUsrDomain where
tUsrDomain.tcDomainCode = tLinkCompanyToDaemonUsers.tcDomainCode And
tUsrDomain.tc_ParentRowid = tUsr.tc_Rowid )
Then Do:
<M-3 run AddDetailLine
(input 'UsrDomain':U (icTable),
input tUsr.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BUser>
If viFcReturnSuper <> 0
Then Assign oiReturnStatus = viFcReturnSuper.
If viFcReturnSuper < 0
Then Return.
Assign tUsrDomain.tcDomainCode = tLinkCompanyToDaemonUsers.tcDomainCode
tUsrDomain.UsrDomainIsDefault = vlDefault.
End.
if not can-find(first tUsrCompany where
tUsrCompany.tcCompanyCode = tLinkCompanyToDaemonUsers.tcCompanyCode And
tUsrCompany.tc_ParentRowid = tUsr.tc_Rowid )
Then Do:
<M-8 run AddDetailLine
(input 'UsrCompany':U (icTable),
input tUsr.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BUser>
If viFcReturnSuper <> 0
Then Assign oiReturnStatus = viFcReturnSuper.
If viFcReturnSuper < 0
Then Return.
Assign tUsrCompany.tcCompanyCode = tLinkCompanyToDaemonUsers.tcCompanyCode
tUsrCompany.Domain_ID = tLinkCompanyToDaemonUsers.tiDomainId.
End.
End.
End.
<M-5 run ValidateBC
(output viFcReturnSuper (oiReturnStatus)) in BUser>
If viFcReturnSuper <> 0
Then Assign oiReturnStatus = viFcReturnSuper.
If viFcReturnSuper < 0
Then Return.
<M-6 run AdditionalUpdates
(output viFcReturnSuper (oiReturnStatus)) in BUser>
If viFcReturnSuper <> 0
Then Assign oiReturnStatus = viFcReturnSuper.
If viFcReturnSuper < 0
Then Return.
<M-7 run DataSave
(output viFcReturnSuper (oiReturnStatus)) in BUser>
If viFcReturnSuper <> 0
Then Assign oiReturnStatus = viFcReturnSuper.
If viFcReturnSuper < 0
Then Return.
If oiReturnStatus = -98
Then Assign oiReturnStatus = 0.