Tag Info

Hot answers tagged

3

Using SharePoint 2010 JSOM i would suggest the following approach to retrieve list item attachments: determine whether List Item contains attachments or not via ListItem.Attachments property in case if list List Item contains attachments, submit a second request to retrieve attachment files Example function ...


3

The code you are using is used to create a simple text file. But, a docx file is not a simple text file. It is a series of XML files inside a zip container with a .docx extension, also known as OpenXML. You need to write the code to create a file in the OpenXML or find and use a library that supports JavaScript. Note that if you create a .txt file, change ...


3

If you don't want to use the GUID, you'll have to make an extra call and get the vti_listname property from the list folder. The folder you can get by url using the getFolderByServerRelativeUrl on the SP.Web object. Example: var clientContext = SP.ClientContext.get_current(); var web = clientContext.get_web(); var folder = ...


3

The following example demonstrates how to return web sites sorted by last modified date: function getWebs(success,error) { var ctx = SP.ClientContext.get_current(); var web = ctx.get_web(); var webs = web.getSubwebsForCurrentUser(null); ctx.load(webs); ctx.executeQueryAsync( function(){ var result = []; ...


3

Since SP.Taxonomy.Term exposes CustomProperties property you could replace the line: taxonomyTerm.get_objectData().get_properties().CustomProperties; with this one: taxonomyTerm.get_customProperties() In order to optimize the request, you could specify explicitly what properties to retrieve for SP.Taxonomy.Term object via SP.ClientContext.load method, ...


3

One thing you can do is use SP.List.getItems(query) to query the 'Department' list for the item with the Title value you want. Once you get the list item, you can get its ID. (Keep in mind that the getItems(query) method will return a list item collection, even though that collection may only contain one item.) Your CAML query would look something like ...


3

Based on your question, i understand that you want to get ID of Department item which is referenced in Article list. Correct me if i am wrong. To get ID of lookup list item, include following in you code(Assuming field name of lookup field from Department is "Department" in article list : var childIdField = listItem["Department"] as FieldLookupValue; if ...


2

This should be it: html = html + "< a href='" + this.LinkingUrl + "' target='_blank' >" + this.Name + "</a>"


2

SharePoint often loads things asynchronous. When your code runs, the content of the page may be not there. This explains why sometimes it works and sometimes nothing happens. Please use the provided array _spBodyOnLoadFunctionNames: function onloadScript() { // Place the content of your anonymous function here } // Run the function if SharePoint DOM ...


2

The FeatureId 00BFEA71-52D4-45B3-B544-B1C71B620109 is used for Custom lists. You need to check the FeatureId of your custom template. To determine FeatureId property, you could save your list as a template, then go to List Template Gallery page (/_catalogs/lt/Forms/AllItems.aspx) and find the Feature Id value of the corresponding. list. see the answer by ...


2

You need to use getSubwebsForCurrentUser. It will only give those webs on which user has access. There is no sense in populating a menu with name of a site to which user doesn't have access. Change var webs = clientContext.get_web().get_webs(); to var webs = clientContext.get_web().getSubwebsForCurrentUser(null);


2

This line var clientContext = SP.ClientContext('/groupcompanies'); is incorrect, you need to create a new context, like this: var clientContext = new SP.ClientContext('/groupcompanies'); (Notice the new keyword). Also make sure that /groupcompanies is a valid server relative path to a web.


2

The item with the biggest ID is the latest created item. function compare(a,b) { if (a.id < b.id) return -1; if (a.id > b.id) return 1; return 0; } arr.sort(compare); var latestItem = arr[arr.length - 1]; You can also compare the dates created in the Compare fuction and it will give the same result. function compare2(a,b) { var ...


2

If you want to have js and css files copied to SharePoint after editing the ts and less files then you can use the Visual Studio Extension SPFastDeploy to do that. https://visualstudiogallery.msdn.microsoft.com/9e03d0f5-f931-4125-a5d1-7c1529554fbd


2

This could be done with SP.WorkManagement.js , if I understands you correctly. Example code: RegisterSod('SP.WorkManagement.js', '/_layouts/15/SP.WorkManagement.js'); SP.SOD.loadMultiple(['sp.js', 'SP.WorkManagement.js'], function() { var context = new SP.ClientContext.get_current(); var userSessionManager = new ...


2

The following REST endpoint demonstrates how to retrieve List resource with Fields and Items properties: /_api/web/lists/getbytitle('<list title>')?$expand=items,fields Example var endpointUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('Documents')?$expand=items,fields"; getJson(endpointUrl) .done(function(data) { var ...


2

You could use the something like const string scriptKey = "jQuery"; if( !Page.ClientScript.IsClientScriptIncludeRegistered( Page.GetType(), scriptKey ) ) { Page.ClientScript.RegisterClientScriptInclude( Page.GetType(), scriptKey, ResolveClientUrl("~/js/jquery.min.js" ) ); } The key to making this work is that you need to include the same key ...


2

Ok, thanks for all the help everyone. It was a good insight into how to go about doing what I wanted. The closest way I could get to 'almost' work was Francoise Becker's idea using SPServices jQuery library, however I think ive discovered that in the DISPFORM.aspx, the code behind is different to other pages as I couldnt get the code to run when the ...


2

Your speculation is correct, the example provided in the question is intended for creating a wiki page and not enterprise wiki publishing page. Since you mentioned in your question JavaScript Object Model (JSOM), the below example demonstrates how to create enterprise wiki page via JSOM in SharePoint 2013. How to create enterprise wiki page using ...


2

Use _spPageContextInfo in your JavaScript. Usage: var url = _spPageContextInfo.webServerRelativeUrl; alert(url); See others here: http://blah.winsmarts.com/2013-2-_sppagecontextinfo_is_your_new_best_friend.aspx


1

Try to look at this answer: Answer to - SP.ClientContext is always “undefined” in JSLink functions Relatively to Your "How to correctly load SP JS resources" question - saw answer here, but cannot google it right now. The answer was that - the most correctly way to load JS snippet on masterpage is to use user control, technique is described here: Adding ...


1

REST /_api/Web/SiteUsers JSOM var ctx = SP.ClientContext.get_current(); var users = ctx.get_web().get_siteUsers(); ctx.load(users); ctx.executeQueryAsync(function() { var userArray = []; var e = users.getEnumerator(); while (e.moveNext()) { userArray.push(e.get_current()); } console.log(userArray); });


1

The ViewFieldCollection has a MoveFieldTo method you can call. The first argument "Id" and the second argument would be an Int32 representing the index (position) where you want the field to appear. https://msdn.microsoft.com/en-us/library/office/ee659514(v=office.14).aspx


1

You can use the REST/JSOM API to log your own usage to show up in SharePoint usage analytics. For example the REST endpoint looks like this: "/_api/Microsoft.SharePoint.Administration.SPAnalyticsUsageService/logevent" You can look at the full code example on doing this from JavaScript here: ...


1

I figured it out finally. A Modal Dialog cannot be closed from an async method. To fix the problem I wrote this piece of code: var IsQueryFinished = false; //those two variables you should change in your async method var ErrorOccured = false; function waitAndCloseDialog() { if (IsQueryFinished && !ErrorOccured) { ...


1

There is nothing in the SharePoint REST API which allows you to create a file using a template. You will have to create new file (empty) or with at least one page. Then set the metadata including the contentTypeId. The following link shows how to do this without creating more than one version if you have versioning on. You can adjust the code to include the ...


1

You can use jQuery (or even plain JavaScript) to get the attribute from the generated for the wev part. The only thing you'd need is somethint that allows you to identify this Web Part even from within the main container. If you own the code for the WP, you can add a custom div with and ID or a class (or data-something), get that using jQuery and then ...


1

I'm not sure if I understand what you want, but I think you are looking for the g_ctxDict object. It holds all the "ctx" objects for all your list webparts on the page. for(var prop in g_ctxDict) { console.log(g_ctxDict[prop].listName) }


1

No. You would be violating Same-Origin Policy since SharePoint does not expose services through CORS or JSONP. You would have to use another approach, such as proxy, auto hosted app or sandboxed solution (deprecated). However if your point is simply to use JavaScript as a language then you access SharePoint through node.js, perhaps with module such as ...


1

You can add a script editor webpart to the home page and add following script. This script checks if user belongs Members group and then redirects it to some other page. You can enhance it to check if user belongs to other groups. <script type="text/javascript"> function IsCurrentUserMemberOfGroup(groupName, OnComplete) { var currentContext = ...



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