Store a backslash in a string

msmitsmsmits Member Posts: 9
Hi,

I try to make a string with the Login-id of an user. I can use USERID, but then I miss the Domain-name, so I came up to the following:

LoggedInAs := (environ('USERDOMAIN') + '\' + USERID) ;

But when I the string is formatted as:

Domain
Username

in stead of

Domain\Username

I know I can use %1 when I show this in a message, but that doesn't seem to work when I try to store it in a global.

Has anyone an idea how I can store a backslash in a string?

Comments

  • matttraxmatttrax Member Posts: 2,309
    I think if you do \\ it will do as you are expecting. Same thing for other reserved characters (if there are any in C/AL, I can't remember off the top of my head). So if ? was reserved and you wanted to store that in a string you would do '\?'
  • tinoruijstinoruijs Member Posts: 1,226
    What do you do with LoggedInAs?
    You can store Domain\Username in a text-field, global or local. :-k

    Tino Ruijs
    Microsoft Dynamics NAV specialist
  • msmitsmsmits Member Posts: 9
    When I use \\ in stead of \, I get two carriage returns, so that is not the solution.
  • msmitsmsmits Member Posts: 9
    LoggedInAs is a String(30). I want to search in table 2000000053 - Windows Access Control to check if someone has a specific role.
  • matttraxmatttrax Member Posts: 2,309
    The way we do that is to forget about the domain. USERID only returns the username. So you have to parse out the domain from the Windows Access Control using STRPOS and COPYSTR then compare it to USERID.

    Maybe there is a better way, but I haven't seen one. I can provide you the function if you need it, but it's more fun building it on your own :)
  • msmitsmsmits Member Posts: 9
    edited 2008-05-20
    So if I'm right, there's no way to store a backslash in string global or something?
  • tinoruijstinoruijs Member Posts: 1,226
    msmits wrote:
    So if I'm right, there's no way to store a backslash in string global or something?

    There is a way.
    The way you described shoud work.
    LoggedInAs := (environ('USERDOMAIN') + '\' + USERID) ;

    If you would show LoggedInAs on a form you would see Domain\Username. :)

    Tino Ruijs
    Microsoft Dynamics NAV specialist
  • msmitsmsmits Member Posts: 9
    I changed the code into

    LoggedInAs := STRSUBSTNO('%1\%2',ENVIRON('USERDOMAIN'),USERID);

    and that seems to work.

    @ tinoruijs: You're right, the carriage return is only shown when I show the value with message()
  • DenSterDenSter Member Posts: 8,305
    I bet that the value in the field is exactly what you need, but that you are trying to verify it by displaying the value in a message, and that will always interpret the '\' as a return. Open the table from the object designer to verify the value, I bet you don't have to make any changes.
  • tinoruijstinoruijs Member Posts: 1,226
    msmits wrote:
    I changed the code into

    LoggedInAs := STRSUBSTNO('%1\%2',ENVIRON('USERDOMAIN'),USERID);

    and that seems to work.

    @ tinoruijs: You're right, the carriage return is only shown when I show the value with message()

    Like Daniel said: LoggedInAs := (environ('USERDOMAIN') + '\' + USERID) ; was already working. :)

    Tino Ruijs
    Microsoft Dynamics NAV specialist
Sign In or Register to comment.