Alpha Video Training
Results 1 to 15 of 15

Thread: set label with current login username without writing too much of a code after login in ux lable

  1. #1
    Member
    Real Name
    Amit lohogaonkar
    Join Date
    Mar 2017
    Location
    NJ
    Posts
    428

    Default set label with current login username without writing too much of a code after login in ux lable

    set label with current login username without writing too much of a code after login in ux label. Need to know best possible way in AA web application. I have out of box login page where I do not see any code that I can write and after that redirect to UX where I need to set this label with current username.
    Last edited by amitloh; 09-12-2017 at 06:14 PM.

  2. #2
    Member
    Real Name
    Amit lohogaonkar
    Join Date
    Mar 2017
    Location
    NJ
    Posts
    428

    Default Re: set label with current login username without writing too much of a code after login in ux lable

    I tried to set default value of lable-
    https://www.alphasoftware.com/alphaf...User-in-XBasic

    2. As Mike responded, you can dim the result into a variable if that's what you want but you don't necessarily have to. For instance you could have a textbox on a control and simply set it's default value to:
    Code:
    = Context.Security.CurrentUser

  3. #3
    Member
    Real Name
    Amit lohogaonkar
    Join Date
    Mar 2017
    Location
    NJ
    Posts
    428

    Default Re: set label with current login username without writing too much of a code after login in ux lable

    I tried ondialoginitilize in UX

    e.control.label1 = "Jones" but does not work.

  4. #4
    "Certified" Alphaholic
    Real Name
    Govindan Gandhi
    Join Date
    Aug 2008
    Location
    New York, NY
    Posts
    4,294

    Default Re: set label with current login username without writing too much of a code after login in ux lable

    e.control.control_name will get you the content for the control.
    if you want to change the label itself to the current user then you will need to do that with
    document.getElementById('your_label_id').innerHTML = Context.Security.CurrentUser; ( a5ws_getCurrentUser() may also be used)
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    ggandhi344@gmail.com
    Skype:ggandhi344@gmail.com
    1 914 924 5171

  5. #5
    "Certified" Alphaholic iRadiate's Avatar
    Real Name
    Stephen
    Join Date
    Jan 2011
    Location
    London, ON, Canada
    Posts
    1,660

    Default Re: set label with current login username without writing too much of a code after login in ux lable

    I use something like this in an xbasic function

    e.control.Label = "Current Logged-In User = " + Context.Security.CurrentUser

    You might also try your code in the onLogin event instead of the onDialogInitialize. e.username is available at that point.
    Alpha Anywhere v12.4.6.1.3 Build 6232-5386 IIS v10.0 on Windows Server 2019 Std in Hyper-V

  6. #6
    Member
    Real Name
    Amit lohogaonkar
    Join Date
    Mar 2017
    Location
    NJ
    Posts
    428

    Default Re: set label with current login username without writing too much of a code after login in ux lable

    Thanks Gandhi and Stephen. I have out of box login control and I do not see any event for that.
    Gandhi-
    document.getElementById('your_label_id').innerHTML = Context.Security.CurrentUser; ( a5ws_getCurrentUser() may also be used)
    In which event or section shall I use this code on my initial UX after OOB login control let user login? is it document.ready js?

  7. #7
    "Certified" Alphaholic
    Real Name
    Govindan Gandhi
    Join Date
    Aug 2008
    Location
    New York, NY
    Posts
    4,294

    Default Re: set label with current login username without writing too much of a code after login in ux lable

    once you are logged in then the user name is available everywhere you want using either context.security.currentuser or a5ws_getCurrentuser() ( for me it is the latter)
    you add this to the serverside onDialogExecute event of the ux/dialog concerned.
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    ggandhi344@gmail.com
    Skype:ggandhi344@gmail.com
    1 914 924 5171

  8. #8
    Member
    Real Name
    Amit lohogaonkar
    Join Date
    Mar 2017
    Location
    NJ
    Posts
    428

    Default Re: set label with current login username without writing too much of a code after login in ux lable

    Thanks Gandhi.

  9. #9
    Member
    Real Name
    Amit lohogaonkar
    Join Date
    Mar 2017
    Location
    NJ
    Posts
    428

    Default Re: set label with current login username without writing too much of a code after login in ux lable

    Hi Gandhi,

    I am not getting set label metod on diaglogexecute. I have label called label1

    I have below sample on diaglogexecute which lets me execute js and state variable-
    function onDialogExecute as v (e as p)
    'Request - The Request object. Includes Request.Variables, which should be used instead of the older e.rv construct
    'Session - The Session object. Should be used instead of the older e.session construct
    'Inside e:
    'e.tmpl = Component definition
    'e.rtc = Runtime calculations - you can use this to store data to be passed to other server side events (Note: the 'rtc' object cannot be used to persist state information - i.e. you can't set a value in rtc and then read that value in a subsequent callback. To persist state info see e._state).
    'e.arguments = SQL::Arguments object with values for each of the arguments defined in this component. To read a value from arguments: e.arguments.find("argumentName").data

    'To specify any javascript that you want to execute set the e.javascript property. For example:
    'e.javascript = "alert('hello');"

    'You can set 'state' variables in this event. The value of any state variables will be available in all subsequent ajax callbacks.
    'To set a state variable:
    'e._state.myvar1 = "value1"
    'e._state.myvar2 = "value2"

    'To read the value of a 'state' variable that was previously set:
    'e._state.myvar1


    end function

  10. #10
    Member
    Real Name
    Amit lohogaonkar
    Join Date
    Mar 2017
    Location
    NJ
    Posts
    428

    Default Re: set label with current login username without writing too much of a code after login in ux lable

    e.control.Label = "Current Logged-In User = " + Context.Security.CurrentUser

    You might also try your code in the onLogin event instead of the onDialogInitialize

    This works for my first ux after login. But I have another ux getting loaded as well. I do not get this on my second ux.

  11. #11
    "Certified" Alphaholic
    Real Name
    Govindan Gandhi
    Join Date
    Aug 2008
    Location
    New York, NY
    Posts
    4,294

    Default Re: set label with current login username without writing too much of a code after login in ux lable

    dialog.execute runs every time the dialog is brought up including the first time, however the dialog initialize will run only when the dialog is run first time. ( dialog execute fires before initialize event)
    the way to do is
    dim user as c
    user = a5ws_getCurrrentUser() or context.security.currentuser
    dim cmd as c
    cmd = "document.getElementById("label1").innerHTML=" + user + ";"
    e.javascript = cmd

    or simply
    e.javascript = "document.getElementById("label1").innerHTML=" + user + ";"

    note: i am just writing the code out of my head, later on i will test this for you.
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    ggandhi344@gmail.com
    Skype:ggandhi344@gmail.com
    1 914 924 5171

  12. #12
    Member
    Real Name
    Amit lohogaonkar
    Join Date
    Mar 2017
    Location
    NJ
    Posts
    428

    Default Re: set label with current login username without writing too much of a code after login in ux lable

    e.javascript = "alert('hello');"

    e.javascript = "document.getElementById('SAMPLEUDASHBOAR.LBL.R1.LABEL1').innerHTML='hello';"
    above works but when I do below it does not give unexpected token. Almost close

    'e.javascript = "document.getElementById('SAMPLEUDASHBOAR.LBL.R1.LABEL1').innerHTML= " + context.security.currentuser +";"

  13. #13
    Member
    Real Name
    Amit lohogaonkar
    Join Date
    Mar 2017
    Location
    NJ
    Posts
    428

    Default Re: set label with current login username without writing too much of a code after login in ux lable

    works!! thanks Gandhi.

    e.javascript = "document.getElementById('SAMPLEUDASHBOAR.LBL.R1.LABEL1').innerHTML='" + context.security.currentuser +"';"

  14. #14
    "Certified" Alphaholic iRadiate's Avatar
    Real Name
    Stephen
    Join Date
    Jan 2011
    Location
    London, ON, Canada
    Posts
    1,660

    Default Re: set label with current login username without writing too much of a code after login in ux lable

    Good stuff. Ghandi, your ideas are always great!

    The way I do this is to use an intermediate a5w page where you can set the login user as a session variable
    Code:
    session.UserID = a5ws_getcurrentuser()
    Then redirect to the logged in page and you can use the session variable anywhere you like in your application.
    Code:
    response.redirect("home.a5w")
    Alpha Anywhere v12.4.6.1.3 Build 6232-5386 IIS v10.0 on Windows Server 2019 Std in Hyper-V

  15. #15
    Member
    Real Name
    Amit lohogaonkar
    Join Date
    Mar 2017
    Location
    NJ
    Posts
    428

    Default Re: set label with current login username without writing too much of a code after login in ux lable

    thanks Stephen.

Similar Threads

  1. Scriot Error when start new UX Login or open UX login Component
    By code23 in forum Mobile & Browser Applications
    Replies: 4
    Last Post: 04-07-2017, 12:16 AM
  2. calling UserName from parent login component UX issue
    By jrodder in forum Mobile & Browser Applications
    Replies: 12
    Last Post: 09-12-2016, 06:35 PM
  3. Trigger browser to recognize and save password and username for login component
    By rnoguera in forum Mobile & Browser Applications
    Replies: 10
    Last Post: 05-05-2016, 06:36 AM
  4. Just want to capture login username to be able to use in grid query
    By clankford in forum Mobile & Browser Applications
    Replies: 7
    Last Post: 08-17-2015, 11:41 PM
  5. Username empty in login
    By howardmeyer in forum Web Application Server v7
    Replies: 2
    Last Post: 08-31-2007, 10:38 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •