User/group info in Javascript

rss

Posted by marcwenger - Jan 20 ’14 at 05:06

Without using the Group Editor (so javascript editor only), can I get the logged in User Information and User's Group information?

 

Or, if I have to use the Group Editor, can javascript functions be called in the user-defined roles?

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 6 years 2 months 24 days
    #1 by Dmitry Kozlov Jan 21 ’14 at 06:21

    Hello,

    You can use Groups functionality and JavaScript together. For example, you can define unique JavaScript code for the form which is designed for the specific Group. Another option is to obtain SharePoint groups the current user belongs to via JavaScript but this approach requires deep knowledge in JavaScript and CSOM:

    http://msdn.microsoft.com/en-us/library/office/hh185012(v=office.14).aspx

    http://maulikdhorajia.blogspot.ru/2011/11/sharepoint-2010-get-current-users.html

  • marcwenger
    Member
    Member for: 5 years 11 months 25 days
    #2 by marcwenger Jan 22 ’14 at 06:31

    Yes, very good idea.  This appears to work (combining groups with javascript)

  • marcwenger
    Member
    Member for: 5 years 11 months 25 days
    #3 by marcwenger Jun 2 ’14 at 03:05

    Hello.  I also want to obtain the currently logged in user's name.  Do I need to import libraries to do this?  Can SharePoint javascript be directly inputted into the Form Designer javascript window?

  • marcwenger
    Member
    Member for: 5 years 11 months 25 days
    #4 by marcwenger Jun 2 ’14 at 05:31

    [#3]: in fact what I wanted to do was using java script to get the Author or Editor

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 6 years 2 months 24 days
    #5 by Dmitry Kozlov Jun 3 ’14 at 07:00

    [#4]: Hello,

    I've described how to get the current user login and prepopulate a field with it in the following post:

    http://formsdesigner.blogspot.com/2013/03/how-to-create-dynamic-forms-with-forms.html

    Could you describe your case in more detail?

  • marcwenger
    Member
    Member for: 5 years 11 months 25 days
    #6 by marcwenger Jun 3 ’14 at 11:17

    Hello, your blog article comes close, and I think will suffice for my needs - thanks!

    What I was referring to was on the form, in the button fields we have the text "Created at [Created] by [Author]
    Last modified at [Modified] by [Editor]".  How do I in javascript extract the Editor and Author fields?

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 6 years 2 months 24 days
    #7 by Dmitry Kozlov Jun 4 ’14 at 04:47

    [#6]: Here is a short sample for you. Place the following code into JS-editor of Forms Designer:

    SP.SOD.executeOrDelayUntilScriptLoaded((function () { 
    	var ctx = new SP.ClientContext.get_current();
    	var list = ctx.get_web().get_lists().getById(_spPageContextInfo.pageListId);
    	var item = list.getItemById(parseInt(GetUrlKeyValue('ID')));
    	ctx.load(item);
    	ctx.executeQueryAsync(function() {
    		alert('Author: ' +
    			item.get_item('Author').get_lookupId() + 
    			' - ' +
    			item.get_item('Author').get_lookupValue() +
    			'\nEditor: ' +
    			item.get_item('Editor').get_lookupId() + 
    			' - ' +
    			item.get_item('Editor').get_lookupValue());
    	});
    }), "SP.js");
    
  • marcwenger
    Member
    Member for: 5 years 11 months 25 days
    #8 by marcwenger Jun 4 ’14 at 10:54

    [#7]: awesome, thanks again!

Displaying 1 to 8 of 8 messages