Hot answers tagged

32

You are using ExecuteOrDelayUntilScriptLoaded wrong, you should use the function name, not execute it. Like this: jQuery(document).ready(function() { ExecuteOrDelayUntilScriptLoaded(myfunction, "sp.js"); }); Note that i removed the "()" from myfunction. Now it should work as expected


19

You can try using below code. Since its OnPrem, we first need to get the login name of user and pass it to the get_effectiveBasePermissions method. To ensure that user has edit permission, we will check the SP.PermissionKind.editListItems enum. SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () { getCurrentUserPermission(); }); function ...


13

Using your SP.Web object, you can get the parent information (SP.WebInformation). Using its ID, you can then, via the site collection, get the parent web object. var context = new SP.ClientContext.get_current(); var web = context.get_web(); var parentInfo = web.get_parentWeb(); var parentWeb = context.get_site().openWebById(...


12

Document ready event gets fired when the DOM get loaded. This doesn't necessarily guarantee that the JS files required for SharePoint JSOM is already loaded. The best way is SP.SOD.executeFunc('sp.js', 'SP.ClientContext', readyFunction); function readyFunction() { Function1(); Function2(); Function3(); }


12

Check out this excellent article where the performance of both is tested: Deep Dive – REST and CSOM Comparison I tested a series of pretty common operations in both REST and CSOM: Creating Lists (10) Creating List Items (100 per List, for a total of 1000) Reading List Items by ID Querying for List Items (retrieving 50 per List) Deleting List ...


11

Use ctx to get current list/library info. For Name or Title, It is ctx.ListTitle PS: No callback needed Following information can be retrieved from ctx about current list/library in SharePoint 2010. [ "listBaseType", "listTemplate", "listName", "view", "listUrlDir", "HttpPath", "HttpRoot", "serverUrl", "imagesPath", "PortalUrl", "...


11

ctx is a global variable. It belongs in the list view pages. var ctx = SP.ClientContext.get_current(); So if you use above line in any list view pages, it will cause an issue. The value of ctx will be overridden by SP.ClientContext.get_current();. You will not get any info from ctx after above line. In SharePoint 2013, it works and widely using in CSR. ...


11

Using Client Object Model will help in this case: var oList; function getListTitleById() { var clientContext = SP.ClientContext.get_current(); oList = clientContext.get_web().get_lists().getById(__ID of the list__); clientContext.load(oList,"Title"); clientContext.executeQueryAsync( Function.createDelegate(this, this....


10

You can use the below rest call as well.: Replace guid with your list guid. $.ajax({ url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists(guid 'b778bbec-dd69-4a6c-9437-c73972c36292')", method: "GET", headers: { "Accept": "application/json; odata=verbose" }, success: function (data) { console.log("List Title ...


10

Can you not use _spPageContextInfo? It has the current user ID built in: _spPageContextInfo.userId https://social.technet.microsoft.com/wiki/contents/articles/29766.sharepoint-understanding-the-sppagecontextinfo-object.aspx


9

Here is the code you are looking for: var ctx = new SP.ClientContext.get_current(); var web = context.get_web(); var ob = new SP.BasePermissions(); ob.set(SP.PermissionKind.manageWeb) ob.set(SP.PermissionKind.managePermissions) var per = web.doesUserHavePermissions(ob) ctx.executeQueryAsync( function(){ alert(per.get_value()); // If this ...


8

var context = new SP.ClientContext.get_current(); var list = context.get_web().get_lists().getByTitle("ListName"); var cQuery = new SP.CamlQuery(); var camlXML = "<View><Query><Where><Eq><FieldRef Name='Author' LookupId='True'/><Value Type='Lookup'>" + _spPageContextInfo.userId + "</Value></Eq></...


8

CSOM For O365 This creates a permission level inherited from the Full Control level, and can be changed to your desirable permission level. namespace Console.Office365 { using Microsoft.SharePoint.Client; using Microsoft.SharePoint.Client.Taxonomy; using Newtonsoft.Json.Linq; using OfficeDevPnP.Core.Entities; using System; ...


7

One very common workaround I see is that you use an authenticated user to pull the Request that you need, then write it to a document library that allows anonymous access. Because most SP does not accept .json as a file type, just save it as response.txt Then, in your public site, anonymously read from that document library: $.ajax({ url: "/documents/...


7

The Author column is of LookUp Type. Here is the complete list. var ctx = new SP.ClientContext.get_current(); var list = ctx.get_web().get_lists().getByTitle("Vacation Replacement"); var query = new SP.CamlQuery(); var specifier = "<Where><Eq><FieldRef Name='Author' LookupId='True'/><Value Type='Lookup'><UserID/></Value>&...


7

To access information in the host web using the Javascript Object Model you need to use an SP.AppContextSite object in conjunction with your SP.ClientContext I see you're using TypeScript, which is awesome, so I'll post my answer with both TypeScript and the working Javascript; my comments will have some additional information and you can paste the JS ...


7

You need to load Id of the definition before creating subscription. Also subscriptionService.publishSubscriptionForList needs guid object instead of just GUID string. When we create List workflow using designer it sets few more properties RestrictTOScope and RestrictsToType. While creating definition using code those properties are not configured hence ...


7

Load DefaultNewFormUrl property of the list. Example: clientContext.load(list, 'DefaultNewFormUrl'); Then retrieve it in the success method: var newUrl = list.get_defaultNewFormUrl();


7

You can read/write to web property bag using JavaScript object model. Example of reading the custom property: //wait until client object model dependencies are loaded before executing our code ExecuteOrDelayUntilScriptLoaded(getWebProperties, "sp.js"); var webProperties; function getWebProperties() { var clientContext = new SP.ClientContext....


7

Hyperlink is a object. You can get its property by following For description listItem.get_item("{column internal name}").get_description() For Url listItem.get_item("{column internal name}").get_url()


7

You can change the icon using the following small jQuery code $( document).ready(function() { $('.ms-siteactions-imgspan > img').attr('src','url_Of_your_image'); });


7

The problem is that you are using the method getDay(). That method will give you the day of the week in this case 3. You should be using the method getDate(). var dt = new Date(dtTest.getFullYear(), dtTest.getMonth(), dtTest.getDate()); -Hope it helps.


7

Get the root site url as shown below: var siteUrl = _spPageContextInfo.siteAbsoluteUrl; Get client context using that url as shown below: var context = new SP.ClientContext(siteUrl); list = context.get_web().get_lists().getByTitle(listName); Hope this will help you!


7

If I am not wrong, you want to group the list item with the column ids as displayed in the below image: In order to achieve this, please follow the following link: https://piyushksingh.com/2016/11/21/retrieve-grouped-listitems-sharepoint/ So in this link, both CSOM and JSOM code snippets are available.


6

Yes you should get the site's TimeZone first and then convert your DateTime accordingly. function getTimeZoneAndServerDateTime() { var context = SP.ClientContext.get_current(); var web = context.get_web(); var timeZone = web.get_regionalSettings().get_timeZone(); context.load(timeZone); context.executeQueryAsync( function ...


6

An alternative to using the get_parentWeb is using the _spPageContextInfo object for urls and only needs one execute: if(_spPageContextInfo.siteServerRelativeUrl != _spPageContextInfo.webServerRelativeUrl) { var parentWebUrl = _spPageContextInfo.webServerRelativeUrl.split("/").slice(0,-1).join("/"); var ctx = new SP.ClientContext(parentWebUrl); var ...


6

You could consider the following solution: retrieve files collection via SharePoint JSOM API utilize getBinaryContent(path, callback) from JSZipUtils to load file content by file url generate zip file Example loadFiles("Documents/2013", function(files) { var zip = new JSZip(); zipFiles(zip,files,0,function(content){ ...


6

You seem to pass 3 parameters to you method, that only expects 2, and seem to have mixed up the order of them. function startWorkflow(itemID, subID) So you should first pass the itemID, the integet of the list item And then the subscription id, the GUID of the workflow subscription.


6

This could help var context = new SP.ClientContext.get_current(); var web = context.get_web(); var parentInfo = web.get_parentWeb(); var parentWeb = context.get_site().openWebById(parentInfo.get_id()); context.load(parentInfo); context.load(parentWeb);


6

In SharePoint, I assumed that Column type is "Choice field". Below is the code for get all choices from that choice field: $.ajax({ url: "Site URL"+"/_api/web/lists/GetByTitle('List Name')/fields?$filter=EntityPropertyName eq 'Choice Field Name'", type: "GET", headers: { "accept": "application/json;odata=verbose", ...


Only top voted, non community-wiki answers of a minimum length are eligible