Page 1 of 1
User/group info in Javascript
Posted: 20 Jan 2014
by marcwenger
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?
Re: User/group info in Javascript
Posted: 21 Jan 2014
by Dmitry Kozlov
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
Re: User/group info in Javascript
Posted: 22 Jan 2014
by marcwenger
Yes, very good idea. This appears to work (combining groups with javascript)
Re: User/group info in Javascript
Posted: 02 Jun 2014
by marcwenger
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?
Re: User/group info in Javascript
Posted: 02 Jun 2014
by marcwenger
in fact what I wanted to do was using java script to get the Author or Editor
Re: User/group info in Javascript
Posted: 03 Jun 2014
by Dmitry Kozlov
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?
Re: User/group info in Javascript
Posted: 03 Jun 2014
by marcwenger
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?
Re: User/group info in Javascript
Posted: 04 Jun 2014
by Dmitry Kozlov
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");
Re: User/group info in Javascript
Posted: 04 Jun 2014
by marcwenger
awesome, thanks again!