User/group info in Javascript

Discussions about Forms Designer for SharePoint 2010.
Locked
marcwenger
Posts: 17
Joined: Tue Dec 17, 2013

20 Jan 2014

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?

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

21 Jan 2014

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 ... e.14).aspx

http://maulikdhorajia.blogspot.ru/2011/ ... users.html

marcwenger
Posts: 17
Joined: Tue Dec 17, 2013

22 Jan 2014

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

marcwenger
Posts: 17
Joined: Tue Dec 17, 2013

02 Jun 2014

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
Posts: 17
Joined: Tue Dec 17, 2013

02 Jun 2014

in fact what I wanted to do was using java script to get the Author or Editor

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

03 Jun 2014

Hello,

I've described how to get the current user login and prepopulate a field with it in the following post:
http://spform.com/forms-designer- ... point-2010
Could you describe your case in more detail?

marcwenger
Posts: 17
Joined: Tue Dec 17, 2013

03 Jun 2014

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?

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

04 Jun 2014

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

Code: Select all

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
Posts: 17
Joined: Tue Dec 17, 2013

04 Jun 2014

awesome, thanks again!

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 3 guests