Retrieve company name a user is working on

iqbalmadiqbalmad Member Posts: 179
hi

Is there any way i can know which Company a user is working on??

thankx

Comments

  • ErictPErictP Member Posts: 164
    From the help:
    COMPANYNAME (Database)
    Use this function to return the current company name.

    Name := COMPANYNAME
  • iqbalmadiqbalmad Member Posts: 179
    wat if i have several companies???
  • Revolution1210Revolution1210 Member Posts: 161
    You could use the User Time Register, with maybe a few tweaks to get exactly what you want.
    Ian

    www.NextEqualZero.com
    A technical eye on Dynamics NAV
  • iqbalmadiqbalmad Member Posts: 179
    have u ever done these tweaks??
  • kapamaroukapamarou Member Posts: 1,152
    iqbalmad wrote:
    Is there any way i can know which Company a user is working on??

    If you mean what company the user opened then that's what COMPANYNAME does...

    Am I missing something here :-k
  • DenSterDenSter Member Posts: 8,304
    iqbalmad wrote:
    wat if i have several companies???
    You can only be logged into one company at a time.
  • matttraxmatttrax Member Posts: 2,309
    Even if you have two clients open, each creates its own session. Each session is logged in to a specific company. So there's no way to be logged into multiple companies at the same time.

    As the others said, COMPANYNAME is what you're after.
  • iqbalmadiqbalmad Member Posts: 179
    guys,

    i think you are not understanding me..

    Problem: I have 3 users working on DatabaseX

    - Jack (working on company A)
    - Terry (working on company B)
    - Natasha (working on company C)

    I have created a form linked with Session table.

    How do i use COMPANYNAME to know who is working on which company.??
  • DenSterDenSter Member Posts: 8,304
    You can't, the session table is a linked to a view on SQL Server. SQL Server doesn't know which company you're logged into.

    By the way, COMPANYNAME is not used for that purpose. It returns the company name of the current session, for the user that is currently logged in.
  • iqbalmadiqbalmad Member Posts: 179
    so, as a result, we can't do what i am trying to do?????
  • MBergerMBerger Member Posts: 413
    i haven't tried it out, but maybe you could log which company a user is in from the CompanyOpen() trigger in CU 1 ?
  • headley27headley27 Member Posts: 188
    edited 2009-02-26
    I am sure that you could do something like this:

    Create a table with UserID, LoginTime, LogoutTime (add a date field(s) if you feel this is necessary).
    Or as Revolution1210 said...tweak the User Time Register.

    Record the UserID, LoginTime when Logging In (CodeUnit 1 > CompanyOpen)
    Record the UserID, LogoutTime when Logging Out (CodeUnit 1 > CompanyClose)

    This table will exist for each of the 3 companies but create a view in SQL Server that looks at all companies via a Union Query.

    The SQL Query would simply be 3 Select statements (1 per company) for all LogoutTime Values = '1/1/1753' (this is equal to 0D in Navision in my version of SQL, not sure what it would be for your installation/locale), tied together via Union statements.

    Something like this:

    SELECT 'Company A' AS Company, UserID, LoginTime
    FROM dbo.[CompanyA$NewTable]
    WHERE ([LogoutTime] = CONVERT(DATETIME, '1753-01-01 00:00:00', 102))
    UNION
    SELECT 'Company B' AS Company, UserID, LoginTime
    FROM dbo.[CompanyB$NewTable]
    WHERE ([LogoutTime] = CONVERT(DATETIME, '1753-01-01 00:00:00', 102))
    UNION
    SELECT 'Company C' AS Company, UserID, LoginTime
    FROM dbo.[CompanyC$NewTable]
    WHERE ([LogoutTime] = CONVERT(DATETIME, '1753-01-01 00:00:00', 102))

    Your results would look something like:
    CompanyA Jack 10:03 AM
    CompanyB Terry 09:20 AM
    CompanyC Natasha 08:47 AM

    Link your form to the results of the new SQL Server View < I've never linked to a view before but I think this is possible.
    If not, there are other ways to pump the information back into Navision (i.e. SQL Stored Procedures).

    *****edit ****

    I hope this helps.
  • ufukufuk Member Posts: 514
    MBerger wrote:
    i haven't tried it out, but maybe you could log which company a user is in from the CompanyOpen() trigger in CU 1 ?

    I've had tried, it worked well. I've used CompanyOpen and CompanyClose triggers and updated a field like CompanyName in User table.
    Ufuk Asci
    Pargesoft
  • MBergerMBerger Member Posts: 413
    headley27 wrote:
    I am sure that you could do something like this:

    ..long story with SQL views etc...
    Or you just uncheck the "DataPerCompany" property of the table :)
  • headley27headley27 Member Posts: 188
    MBerger wrote:
    Or you just uncheck the "DataPerCompany" property of the table :)
    No way............ ](*,)

    Well that's bloody easy.

    I typed that long drawn out post, but at least it's not for nothing.....I learned something.

    Good to know. Thanks MBerger =D>
Sign In or Register to comment.