How To Set Target Audience For A Coloumn In Sharepoint 2010
-
Monday, June 04, 2012 9:21 AM
Hi Friends ,
I am Sidhanta Tripathy. I have a Library named libr. In that library there is a column called Approved. Approved columns has a check box. It takes only two values i.e. Yes or No. But my objective is that only a specific group spsadmin (group in the permission label) can check it and other can not check it or it should not be visible to the other group except spsadmin.
Please guide me to solve this problem preferably without coding.
With Thanks
Sidhanta Tripathy
- Edited by Sidhanta Monday, June 04, 2012 9:22 AM
All Replies
-
Monday, June 04, 2012 9:41 AM
There is no permissions or Audience Targeting at column level. This can be done through code only.
Thanks, Neha Navale
-
Monday, June 04, 2012 9:46 AM
Hi Neha ,
Thanks for your valuable suggestion. But we are instructed not to use code. But we can use Sharepoint designer.
With Thanks
Sidhanta Tripathy
- Edited by Sidhanta Monday, June 04, 2012 9:47 AM
-
Monday, June 04, 2012 10:00 AM
You can use ECMA Script to check user in particular group and show hide the column using JavaScript
Thanks, Neha Navale
- Marked As Answer by Entan MingMicrosoft Contingent Staff, Moderator Friday, June 15, 2012 1:42 AM
-
Tuesday, July 03, 2012 9:22 AM
You can use ECMA Script to check user in particular group and show hide the column using JavaScript
Thanks, Neha Navale
Hi Neha,
I have the exact same problem as Sidhanta - however I am allowed to use code.
Could you please link to the right ECMA Script that would solve this issue?
Thanks alot. :)
/H
/hobbes
-
Tuesday, July 03, 2012 1:26 PM
<script type="text/javascript"> _spBodyOnLoadFunctionNames.push(onPageLoad()); function onPageLoad() { ExecuteOrDelayUntilScriptLoaded(checkUser, "sp.js") } var adminUsers; var vCurrUserName; function checkUser() { var currentContext = new SP.ClientContext(); vCurrUserName= currentContext.get_web().get_currentUser(); currentContext.load(vCurrUserName); var groupCollection = currentContext.get_web().get_siteGroups(); var _group = groupCollection.getById(10); // ID of the Group adminUsers = _group.get_users(); currentContext.load(adminUsers); currentContext.executeQueryAsync(Function.createDelegate(this, this.checkUserSuccess), Function.createDelegate(this, this.checkUserFailure)); } function checkUserSuccess() { var vIsAdmin=false; var listEnumerator = adminUsers.getEnumerator(); while (listEnumerator.moveNext()) { var item = listEnumerator.get_current(); if(vCurrUserName.get_loginName() == item.get_loginName()) { vIsAdmin =true; break; } } if(vIsAdmin) { alert(vIsAdmin) //Write code to show checkbox column if(document.getElementById('CheckBoxColID') != null) { document.getElementById('CheckBoxColID').style.display = "block"; } } else { //Write code to show checkbox column if(document.getElementById('CheckBoxColID') != null) { document.getElementById('CheckBoxColID').style.display = "none"; } } } function checkUserFailure() { //Failed to get user //Write code to show checkbox column if(document.getElementById('CheckBoxColID') != null) { document.getElementById('CheckBoxColID').style.display = "none"; } } </script>Try this script to check user is in particular group, if user is member of required group, show the checkbox column, if not then hide it.
In order to make this script work, you will have to pass Group ID at this line
var _group = groupCollection.getById(10); // ID of the Group
And the check box column ID at
document.getElementById('CheckBoxColID')
Thanks, Neha Navale
-
Tuesday, July 03, 2012 2:39 PM
Hi Neha,
I just tested it with a Contect Editor Webpart in my list. However it did not produce the expected result for the user I tested with (he was not in the group I defined in the script).
But I'm in doubt wheater the group name and the CheckBoxColID should include spaces or not? Fx the CheckBoxColID is 'Godkendt af HR BP' - should it be 'GodkendtafHRBP'?
Thanks. :)
/H
/hobbes
-
Wednesday, July 04, 2012 4:41 AM
To know the ID of checkbox, press F12, it will open the developer tool.
Click on the arrow and select the checkbox. You will see the HTML of the checkbox.
Thanks, Neha Navale
-
Wednesday, July 04, 2012 5:00 AM
Hi ,
Can it be possible without code. Sharepoint Designer is allowed.
With Thanks
Sidhanta Tripathy
- Edited by Sidhanta Wednesday, July 04, 2012 5:00 AM
-
Wednesday, July 04, 2012 5:05 AM
It is possible to add the script in the page using SharePoint Designer
Thanks, Neha Navale
-
Wednesday, July 04, 2012 5:08 AM
Hi Neha,
Thanks for your suggestion. Please explain me how it can be done and where it needs to be implement?
With Thanks
Sidhanta Tripathy
- Edited by Sidhanta Wednesday, July 04, 2012 5:08 AM
-
Wednesday, July 04, 2012 6:33 AM
In SharePoint Designer, click on All Files in the Navigation section.
Select the Library, go to Forms folder
Select the page (Instead of modifying the default page, its better to create copy and modify it)
Add the script as it is in the page, after this line
<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
Thanks, Neha Navale
-
Wednesday, July 04, 2012 7:27 AM
Hi Neha,
which script needs to be added after this line
<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
With Thanks
Sidhanta Tripathy
- Edited by Sidhanta Wednesday, July 04, 2012 7:27 AM
-
Wednesday, July 04, 2012 7:31 AM
<script type="text/javascript"> _spBodyOnLoadFunctionNames.push(onPageLoad()); function onPageLoad() { ExecuteOrDelayUntilScriptLoaded(checkUser, "sp.js") } var adminUsers; var vCurrUserName; function checkUser() { var currentContext = new SP.ClientContext(); vCurrUserName= currentContext.get_web().get_currentUser(); currentContext.load(vCurrUserName); var groupCollection = currentContext.get_web().get_siteGroups(); var _group = groupCollection.getById(10); // ID of the Group adminUsers = _group.get_users(); currentContext.load(adminUsers); currentContext.executeQueryAsync(Function.createDelegate(this, this.checkUserSuccess), Function.createDelegate(this, this.checkUserFailure)); } function checkUserSuccess() { var vIsAdmin=false; var listEnumerator = adminUsers.getEnumerator(); while (listEnumerator.moveNext()) { var item = listEnumerator.get_current(); if(vCurrUserName.get_loginName() == item.get_loginName()) { vIsAdmin =true; break; } } if(vIsAdmin) { alert(vIsAdmin) //Write code to show checkbox column if(document.getElementById('CheckBoxColID') != null) { document.getElementById('CheckBoxColID').style.display = "block"; } } else { //Write code to show checkbox column if(document.getElementById('CheckBoxColID') != null) { document.getElementById('CheckBoxColID').style.display = "none"; } } } function checkUserFailure() { //Failed to get user //Write code to show checkbox column if(document.getElementById('CheckBoxColID') != null) { document.getElementById('CheckBoxColID').style.display = "none"; } } </script>
Try this script to check user is in particular group, if user is member of required group, show the checkbox column, if not then hide it.
In order to make this script work, you will have to pass Group ID at this line
var _group = groupCollection.getById(10); // ID of the Group
And the check box column ID at
document.getElementById('CheckBoxColID')
Thanks, Neha Navale
- Marked As Answer by Sidhanta Thursday, July 05, 2012 4:04 AM
-
Thursday, July 05, 2012 4:06 AM
Hi Neha ,
Thanks for your solution.
With Thanks
Sidhanta Tripathy
- Edited by Sidhanta Thursday, July 05, 2012 4:06 AM
-
Friday, July 06, 2012 9:05 AM
Hi Neha,
Closer to a solution I think, but still struggeling a bit. Here's what I've changed and tested:
1. Found the right ID of my checkbox "360 Grader Vurdering?"
2. Inserted the ID into the code
3. Inserted the ID of the Group who should see the column "TDP Education Group"
4. Added a test user to two group; "TDP Education Group" & "Test Group"
5. Send the link to the page with the list to my test user
6. He is able to see the list and the column
7. Removed him from "TDP Education Group"
8. He is still able to see the columnCan you spot where the mistake is? :)
<script type="text/javascript"> _spBodyOnLoadFunctionNames.push(onPageLoad()); function onPageLoad() { ExecuteOrDelayUntilScriptLoaded(checkUser, "sp.js") } var adminUsers; var vCurrUserName; function checkUser() { var currentContext = new SP.ClientContext(); vCurrUserName= currentContext.get_web().get_currentUser(); currentContext.load(vCurrUserName); var groupCollection = currentContext.get_web().get_siteGroups(); var _group = groupCollection.getById(10); // TDP Education Group adminUsers = _group.get_users(); currentContext.load(adminUsers); currentContext.executeQueryAsync(Function.createDelegate(this, this.checkUserSuccess), Function.createDelegate(this, this.checkUserFailure)); } function checkUserSuccess() { var vIsAdmin=false; var listEnumerator = adminUsers.getEnumerator(); while (listEnumerator.moveNext()) { var item = listEnumerator.get_current(); if(vCurrUserName.get_loginName() == item.get_loginName()) { vIsAdmin =true; break; } } if(vIsAdmin) { alert(vIsAdmin) //Write code to show checkbox column if(document.getElementById('ctl00_m_g_a2320044_580a_448f_bb83_a86ec9288d23_ctl00_ctl04_ctl12_ctl00_ctl00_ctl04_ctl00_ctl00_BooleanField') != null) { document.getElementById('ctl00_m_g_a2320044_580a_448f_bb83_a86ec9288d23_ctl00_ctl04_ctl12_ctl00_ctl00_ctl04_ctl00_ctl00_BooleanField').style.display = "block"; } } else { //Write code to show checkbox column if(document.getElementById('ctl00_m_g_a2320044_580a_448f_bb83_a86ec9288d23_ctl00_ctl04_ctl12_ctl00_ctl00_ctl04_ctl00_ctl00_BooleanField') != null) { document.getElementById('ctl00_m_g_a2320044_580a_448f_bb83_a86ec9288d23_ctl00_ctl04_ctl12_ctl00_ctl00_ctl04_ctl00_ctl00_BooleanField').style.display = "none"; } } } function checkUserFailure() { //Failed to get user //Write code to show checkbox column if(document.getElementById('ctl00_m_g_a2320044_580a_448f_bb83_a86ec9288d23_ctl00_ctl04_ctl12_ctl00_ctl00_ctl04_ctl00_ctl00_BooleanField') != null) { document.getElementById('ctl00_m_g_a2320044_580a_448f_bb83_a86ec9288d23_ctl00_ctl04_ctl12_ctl00_ctl00_ctl04_ctl00_ctl00_BooleanField').style.display = "none"; } } </script>Thanks again
/H/hobbes
-
Friday, July 06, 2012 2:13 PM
I tried running the above script, its working.
Can you cross check the Group ID for "TDP Education Group" is 10?
You can debug the script by adding
debugger; in checkuser function as shown below
function checkUser() { debugger; var currentContext = new SP.ClientContext();When u run the code, Visual Studio pop up will appear.
click yes to debug
Thanks, Neha Navale
-
Friday, July 06, 2012 2:31 PM
Hi Neha,
Thanks again - I updated the group ID (should have been 218 :)) and removed myself from the group 'TDP Education Group' thinking that should make the check box column hidden. That didn't happen unfortunately. No bugs either.. Any mistake in the way I'm testing?
I hope I haven't made a fundamental error - the script should be added in a 'Content Editor Webpart' in 'Source Editor' on the same page is the list, right?
/H
/hobbes
-
Friday, July 06, 2012 2:41 PM
Content Editor Web Part should be on the page, from which you want to hide the field.
Did you tried debugging it? Or you can add alerts, to check, if the conditions are satisfied.
Thanks, Neha Navale

