Store a backslash in a string

msmits
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?
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?
0
Comments
-
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 '\?'0
-
What do you do with LoggedInAs?
You can store Domain\Username in a text-field, global or local. :-k
Tino Ruijs
Microsoft Dynamics NAV specialist0 -
When I use \\ in stead of \, I get two carriage returns, so that is not the solution.0
-
LoggedInAs is a String(30). I want to search in table 2000000053 - Windows Access Control to check if someone has a specific role.0
-
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 own0 -
So if I'm right, there's no way to store a backslash in string global or something?0
-
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 specialist0 -
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()0 -
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.0
-
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 specialist0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions