Showing posts with label ECMA Script. Show all posts
Tuesday, December 16, 2014
How to Hide Controls in SharePoint New Form Based on User using ECMA Script.
Posted by
Santhosh,
on
2:13 AM
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.
Wednesday, November 26, 2014
Working with the ECMAScript Client Object Model (JSOM) in SharePoint 2013,2010
Posted by
Santhosh,
on
11:27 PM
Thanks for visiting to my blog .
Today am going to explain about ECMAScript Client Object Model (JSOM) in SharePoint 2013,2010
ECMAScript :
ECMAScript is a java script based client side scripting language which is now supported in SharePoint 2010 and can be used to access Client Object Model.
Background
One of the coolest features of SharePoint 2010 and 2013 as well. You might already know that if we have to talk to SharePoint 2007 and don’t want to write the server side code then we call SharePoint Web Services. Now with SharePoint 2010 we can use Client Object Model to talk to SharePoint and the option of web services is still there. Once a wise man said, two options are always better than one.
- SharePoint Client Managed Object Model is a SharePoint API that runs on the client side.
- It converts the API calls made by the application, into XML request and sends it to the SharePoint server. On the server, the XML request is handled by a service called Client.svc where it translates the XML request in to appropriate Object Model calls (SharePoint Server Object Model) and gets the results.
- After getting the results, Client.svc translates them into JavaScript Object Notation (JSON) and sends back to the Client Managed Object Model. On the client side the JSON response is translated into ECMAScript objects for ECMAScript.
This is just a breif description of our ECMA Script . In our next articles we will see the examples of ECMAScript.
Subscribe to:
Posts
(
Atom
)