locked
insert data to logged user RRS feed

  • Question

  • Whenever a New Data screen or add eidt screen is opened, I would like to populate the current user into a field, similar to populating the current date, so I could insert information related to current user.

    Wednesday, March 4, 2015 2:10 AM

Answers

  • Hi,

    You could try to create a web service to get current user in server project. Then in the client side, you could use javascript or ajax to invoke this service you just created.

    You could add a ashx as service like:

    public void ProcessRequest(HttpContext context)
            {
                using (var serverContext = ServerApplicationContext.CreateContext())
                {
                    context.Response.ContentType = "text/plain";
                    context.Response.Write(serverContext.Application.User.Name);
                }
            }

    In the html client you could using below code to access the service:

    function CallGetUserName(operation) {
        $.ajax({
            type: 'post',
            data: {},
            url: '../web/GetUserName.ashx',
            success: operation.code(function AjaxSuccess(AjaxResult) {
                operation.complete(AjaxResult);
            })
        });
    }

    Besides, thread below could also give you some help:

    https://social.msdn.microsoft.com/Forums/en-US/ac35ddcc-2dee-4235-a50d-a9c2d964bc19/working-with-the-current-user-in-a-new-data-screen-c?forum=lightswitch

    • Marked as answer by 00dull Friday, March 6, 2015 5:24 AM
    Thursday, March 5, 2015 2:27 AM

All replies

  • Hello,

    when you create a new database you can check the create/modify property. It's located under the Property of the database. Then you get this Information automatically.
    Sorry, the Picture is in German.Hope this helps

    Kind Regards
    Thomas

    Wednesday, March 4, 2015 8:04 AM
  • I don't know if it is in database,how can I get it in html client??,I want to show the user in several pages.

    how could I achieve this . I am using HTML client.



    • Edited by 00dull Thursday, March 5, 2015 2:05 AM
    Thursday, March 5, 2015 2:03 AM
  • Hi,

    You could try to create a web service to get current user in server project. Then in the client side, you could use javascript or ajax to invoke this service you just created.

    You could add a ashx as service like:

    public void ProcessRequest(HttpContext context)
            {
                using (var serverContext = ServerApplicationContext.CreateContext())
                {
                    context.Response.ContentType = "text/plain";
                    context.Response.Write(serverContext.Application.User.Name);
                }
            }

    In the html client you could using below code to access the service:

    function CallGetUserName(operation) {
        $.ajax({
            type: 'post',
            data: {},
            url: '../web/GetUserName.ashx',
            success: operation.code(function AjaxSuccess(AjaxResult) {
                operation.complete(AjaxResult);
            })
        });
    }

    Besides, thread below could also give you some help:

    https://social.msdn.microsoft.com/Forums/en-US/ac35ddcc-2dee-4235-a50d-a9c2d964bc19/working-with-the-current-user-in-a-new-data-screen-c?forum=lightswitch

    • Marked as answer by 00dull Friday, March 6, 2015 5:24 AM
    Thursday, March 5, 2015 2:27 AM