Using the 'ContainsCurrentUser' in the Javascript editor of a Group page
Hello again,
I'm wondering if I can run a check on a specific User-defined Group page to see if the current user's name is the same as that included in a field called 'Name08'. I've added the script below to the Javascript for Edit and New forms, and have tested the logic of the 'hide' by testing it against a different field altogether and that works fine. However using either the CurrentUserName element or ContainsCurrentUser in the 'IF' statement seems to kill everything. I've set the elements o f the 'else' to be the 'hide' option and still nothing happens.
What I'm looking to do is to hide part of a table if the person's name isn't included in the Name08 field. the code I'm using is:-
if(ContainsCurrentUser([Name08])) {
$('.Table').show();
} else {
$('.Table').hide();
}
Can anyone please advise how I'm going wrong?
Thanks in advance. Alan C.
I'm wondering if I can run a check on a specific User-defined Group page to see if the current user's name is the same as that included in a field called 'Name08'. I've added the script below to the Javascript for Edit and New forms, and have tested the logic of the 'hide' by testing it against a different field altogether and that works fine. However using either the CurrentUserName element or ContainsCurrentUser in the 'IF' statement seems to kill everything. I've set the elements o f the 'else' to be the 'hide' option and still nothing happens.
What I'm looking to do is to hide part of a table if the person's name isn't included in the Name08 field. the code I'm using is:-
if(ContainsCurrentUser([Name08])) {
$('.Table').show();
} else {
$('.Table').hide();
}
Can anyone please advise how I'm going wrong?
Thanks in advance. Alan C.
Hi,
The people picker I'm using (called in Name08 in the system) is a field created in the SharePoint list and appended onto the relevant Group forms as normal. It is a multi-selection option but only allows people and not groups. In order to test things further I have added a second People picker to the list which is a single name field and completed tests against that as well.
I'm not certain what I would be looking for in the FormsDesigner side of things to identify the rendering mode, however I do see under the 'Field' tab for the column/field in FD the word User next to Type - is this what you are referring to ?
Thanks for your assistance, Alan C.
The people picker I'm using (called in Name08 in the system) is a field created in the SharePoint list and appended onto the relevant Group forms as normal. It is a multi-selection option but only allows people and not groups. In order to test things further I have added a second People picker to the list which is a single name field and completed tests against that as well.
I'm not certain what I would be looking for in the FormsDesigner side of things to identify the rendering mode, however I do see under the 'Field' tab for the column/field in FD the word User next to Type - is this what you are referring to ?
Thanks for your assistance, Alan C.
Hi Rostislav,
I've looked at the two 'live' and one development instances of Forms Designer and don't see in the Layout section the 'Render' element you are referring to (see copy of element here ) -
I've just made certain by changing the field type from single choice to multi and also groups as well then looking in the Forms Designer view of the field and Render just isn't visible - sorry!
Alan C.
I've looked at the two 'live' and one development instances of Forms Designer and don't see in the Layout section the 'Render' element you are referring to (see copy of element here ) -
I've just made certain by changing the field type from single choice to multi and also groups as well then looking in the Forms Designer view of the field and Render just isn't visible - sorry!
Alan C.
Try the code below. Make sure 'Name08' is the Internal Name of the field.
Oh, and this code is for when you're on the edit or new pages. Will you need this for the view page also?
Code: Select all
SP.SOD.executeOrDelayUntilScriptLoaded((function () {
var ctx = new SP.ClientContext.get_current();
var web = ctx.get_web();
ctx.load(web);
var user = web.get_currentUser();
user.retrieve();
ctx.executeQueryAsync(
function () {
var dic = fd.field('Name08').value().dictionaryEntries;
var found = false;
for (var i = 0; i < dic.length; i++) {
if (dic[i].AccountName == user.get_loginName()){
found = true;
}
}
if (found) {
$('.Table').show();
}
else {
$('.Table').hide();
}
});
}), "SP.js");
Excellent!! (Once I'd remembered to remove all the bits of script I'd used to test things!!)
Currently I'm not allowing visibility of the table in 'read' mode so that isn't an immediate need, however I can image it will be useful for another thing I'm building. If you can get that as well for the display side working that would be great.
Thanks again for this - very helpful and it saves me from doubling up the 9 stages I'm managing currently.
Alan C.
Currently I'm not allowing visibility of the table in 'read' mode so that isn't an immediate need, however I can image it will be useful for another thing I'm building. If you can get that as well for the display side working that would be great.
Thanks again for this - very helpful and it saves me from doubling up the 9 stages I'm managing currently.
Alan C.
-
- Information
-
Who is online
Users browsing this forum: No registered users and 9 guests