Hi Guys,
Thanks for visiting our blog.
In Share Point we have If condition "If this user is member of this share point group" We can use this condition to check any user belongs to particular group or not.
Scenario:
Check user belongs to a SharePoint Group and Hide some controls in New/Edit Forms on SharePoint Custom List.
Solution:
The
following Script which will help you in checking if the current logged
in SharePoint user belongs to a SharePoint user group and based on it
hide some controls in New/Edit forms on Custom List.
Step 1: Navigate to your SharePoint 2013 site.
Step 2: From this page select Site Actions | Edit Page:
Edit
the page, go to the "Insert" tab in the Ribbon and click the "Web Part"
option. In the "Web Parts" picker area, go to the "Media and Content"
category, select the "Script Editor" Web Part and press the "Add
button".
Step 3: Once the Web Part is
inserted into the page, you will see an "EDIT SNIPPET" link; click it.
You can insert the HTML and/or JavaScript as in the following:
Script
<script src="/sites/JohnHancock/JS/jquery-1.4.2.min.js"></script><script type="text/javascript">
ExecuteOrDelayUntilScriptLoaded(disableControls,
"sp.js");
var clientContext = null;
var web = null;
var users ;
var oList;
var oListNew;
function disableControls()
{
clientContext = new
SP.ClientContext();
var groupCollection =
clientContext.get_web().get_siteGroups();
var group = groupCollection.getById(4);//the SharePoint usergroup
users =
group.get_users();
clientContext.load(group);
clientContext.load(users);
currentUser =
clientContext.get_web().get_currentUser();
clientContext.load(currentUser);
clientContext.executeQueryAsync(Function.createDelegate(this,
this.onQuerySucceeded), Function.createDelegate(this,
this.onQueryFailed));
RefreshCommandUI();
}
function onQuerySucceeded()
{
if(this.users.get_count() >0)
{
var UserExistInGroup = false;
for(var i=0; i < users.get_count(); i++)
{
//alert(users.itemAt(i).get_loginName());
//alert(this.currentUser.get_loginName());
if(users.itemAt(i).get_loginName() == this.currentUser.get_loginName())
{
UserExistInGroup
= true;
break;
}
}
}
if (UserExistInGroup)
{
$('nobr:contains("Approver")').closest('tr').show();
}
else
{
$('nobr:contains("Approver")').closest('tr').hide();
}
}
function onQueryFailed(sender, args)
{
}
</script>
This is how we use to hide /unhide the columns in SharePoint Out of box forms.
Related Post
SharePoint 2010
- List view render using JSLink with Fabric UI
- Delete Quick Links using Powershell
- delete/Add Top Navigation Links using Powershell
- PowerShell::Get Content Database Size in SharePoint
- PowerShell :: Delete All List Items
- Basics: Difference between Synchronous Events and Asynchronous Events in SharePoint
- Remove-SPSite 0x80070003 - Forcely delete Site Collection that cannot be deleted
- This operation can be performed only on a computer that is joined to a server farm by users who have permissions in SQL Server to read from the configuration database. To connect this server to the server farm, use the SharePoint Products Configuration Wizard, located on the Start menu in Microsoft SharePoint 2010 Products.
- Restore-SPSite: The operation that you are attempting to perform cannot be completed successfully.
- Get List Field Type using ECMA Script in SP Hosted Apps
- SharePoint Interview Questions and Answers..
- What are Event Receivers and How to Create Sample event Receivers and attach to List/ Doc Library ?
- Export SharePoint Search Crawl log to CSV File.
- Create Content Type using ECMA Script
- Get List Content Types using ECMA Script
- SharePoint Modal Dailoge to Open Page
- SPDataSource in SharePoint.
- Capacity planning and Sizing in SharePoint 2010
- Enable 'Save site as Template' in Publishing Sites by using SharePoint Designer
- Read Enhanced Rich Text Values in SharePoint
- What is Web part life Cycle in SharePoint 2013 and SharePoint 2010
- What is the Content Type for Custom List in SharePoint 2013, SharePoint 2010
- What is calculated column in SharePoint 2013 ,2010
- Create Meetings by using Exchange Server API
SharePoint 2013
- List view render using JSLink with Fabric UI
- Delete Quick Links using Powershell
- delete/Add Top Navigation Links using Powershell
- Get CheckedOut Files from SharePoint 2013 and MOSS2007
- PowerShell::Get Content Database Size in SharePoint
- PowerShell :: Delete All List Items
- Powershell :: Apply Master Page to all sub sites under site collection
- Internet Explorer cannot display this feed - while accessing REST URL in SharePoint
- SharePoint Installation: The tool was unable to install application server role web server (IIS) role SharePoint 2013.
- Basics: Difference between Synchronous Events and Asynchronous Events in SharePoint
- Remove-SPSite 0x80070003 - Forcely delete Site Collection that cannot be deleted
- This operation can be performed only on a computer that is joined to a server farm by users who have permissions in SQL Server to read from the configuration database. To connect this server to the server farm, use the SharePoint Products Configuration Wizard, located on the Start menu in Microsoft SharePoint 2010 Products.
- Restore-SPSite: The operation that you are attempting to perform cannot be completed successfully.
- Migrate Multiple site(sub sites) using MetaLogix and change the Template in Target
- Issue:The date file "C:\ProgramData\Metalogix\EnvironmentSettings.xml" contains invalid data.Values in that file reset to defaults
- Get List Field Type using ECMA Script in SP Hosted Apps
- SharePoint Interview Questions and Answers..
- Issues:SharePoint Foundation 2013 Prerequisites installation(off line) on Windows Server2012 R2
- Get Choice Field Type Values using ECMA Script
- Something Went wrong error message while deploying App in SharePoint 2013
- The Server was unable to save the form at this time. Please try again.
- Get the Items inside the Folder in document Library in SharePoint 2013 using REST API
- SharePoint Client Browser for SharePoint Online and SharePoint On-Premises
- What is Managed meta data service in SharePoint 2010, 2013 and How to Configure it?
- Deprecated features in SharePoint 2013
0 comments:
Post a Comment