Posts

Showing posts from 2018

CRUD Operations on SharePoint List using JavaScript Object Model(JSOM)

JavaScript Object Model Create Item Add one record into ProductsCategory list using below code. //Get the Site var context = new SP.ClientContex( "Your Site URL" ); // Get the Web var web = context.get_web(); // Get the list based on the Title var list = web.get_lists().getByTitle( "ProductCategory" ); //Object for creating Item in the List var listCreationInformation = new SP.ListItemCreationInformation(); var listItem = list.addItem(listCreationInformation); listItem.set_item( "Title" , $( "#CategoryId" ).val()); listItem.set_item( "CategoryName" , $( "#CategoryName" ).val()); listItem.update(); //Update the List Item ctx.load(listItem); //Execute the batch Asynchronously ctx.executeQueryAsync( Function .createDelegate( this , success), Function .createDelegate( this , fail) ); The above code perform the following operations.  To add a new item in the list, the SP.Li

CRUD Operations on SharePoint List using Client Side Object Model(CSOM)

Client Side Object Model Create Item Add one record into  StudentsInfo  list using below code. /Get the site string siteUrl = "SiteURL" ; ClientContext clientContext = new ClientContext(siteUrl); // Get the List List oList = clientContext.Web.Lists.GetByTitle( "StudentsInfo" ); ListItemCreationInformation listCreationInformation = new ListItemCreationInformation(); ListItem oListItem = oList.AddItem(listCreationInformation); oListItem[ "Title" ] = "Mr" ; oListItem[ "StudentName" ] = "Gopi Avala" ; oListItem.Update(); clientContext.ExecuteQuery(); Update Item   Edit the record from  StudentsInfo  list whose ID=1 using below code.  //Get the site string siteUrl = "SiteURL" ; ClientContext clientContext = new ClientContext(siteUrl); // Get the List List oList = clientContext.Web.Lists.GetByTitle( "StudentsInfo" ); ListItem oListItem = oList.GetItemById( 1 ); oListItem[ "Tit

Checking the User Groups in SharePoint using REST API.

Getting the Login Users Groups from SharePoint Site //The below line will used to get the user groups from the getUserPermissions Method var permissionResults = getUserPermissions(_spPageContextInfo.webAbsoluteUrl, _spPageContextInfo.userId); permissionResults.done( function ( groups ) { $( ".menu-item-text:contains('Admin')" ).parent().parent().parent().hide(); var groupInfo = jQuery.grep(groups, function ( group, index ) { //return (group.Title == "GlobalScore Admins"); if (group.Title == "Site Full Control Admins" || group.Title == "Site Contribute Admins" ) { alert( "User is available in Admin Groups" ); } else alert( "User is not Admin..." ); }); }); //Getting the Login User SharePoint Group Details function getUserPermissions ( webUrl, userId ) { var deferred = new jQuery.Deferred(); jQuery.ajax({ url : webUrl + "/_api/web/GetUserById(" + userId + ")/Gr

Rest API to check User is available in SharePoint Group or not

Checking the the User is available in Specified Grou p //To check whether user is present in current group or not var isUserInGroup = isMemberofGroup ("GroupName", currentLoginUser); isUserInGroup.done( function ( results ) { if (results[ 0 ] != undefined ) { console .log( 'User is Present in current AssignedTo Group' ); userPresentInGroup = true ; //Check whether current item Activity Status as Active then show forms otherwise don't display form } else { console .log( 'User is Not present in current AssignedTo Group' ); } }); //Find user is member within group function isMemberofGroup ( groupName, userId ) { var deferred = new jQuery.Deferred(); var endpointUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/sitegroups/getByName('" + groupName + "')/Users?$filter=Id eq " + userId; jQuery.ajax({ url : endpointUrl, type : "GET" , headers : { "accept"