Tag Info

New answers tagged

0

The parameter count for getPeerUrl() is wrong. According to the documentation (even if it is ambiguous) you must pass the current URL (server relative) and variation label too. Check the JS function signature SP.Publishing.Variations.getPeerUrl, it takes 3 parameters. Update: Try this jQuery.getScript("_layouts/15/sp.publishing.js",null) var ...


0

Maybe you can simply take a look to the getPeerUrl() method in the SP.Publishing.Variations namespace: https://msdn.microsoft.com/en-us/library/office/jj954403.aspx Try this jQuery.getScript("_layouts/15/sp.publishing.js",null) var clientContext = SP.ClientContext.get_current(); var peerUrl = SP.Publishing.Variations.getPeerUrl(clientContext, ...


0

I have corrected your code and here you go $(document).ready(function() { ExecuteOrDelayUntilScriptLoaded(GetDesc, "sp.js"); }); function GetDesc() { context = new SP.ClientContext.get_current(); web = context.get_web(); siteURL=$(location).attr('href'); var titleName=document.title; var mListName= "TestList"; ...


1

Updating a list item in JSOM should be as simple as this: function updateListItem(itemId) { var clientContext = new SP.ClientContext(siteUrl); var oList = clientContext.get_web().get_lists().getByTitle('My List'); this.oListItem = oList.getItemById(itemId); oListItem.set_item('MyField', 'My Updated Field Value'); oListItem.update(); ...


0

I had the same issue in my environment. The following DIDN'T work: - Put script in "Style Library" - use (d) tag - CTRL+F5 - InPrivate The only thing that finally worked --> turn off caching on your network infrastructure devices! When the caching on our NetScaler was turned off --> everything worked like a charm.


0

NO need of "context.load(mList);" simply loading the ListItemCollection will bring the item collection. During itration process is going on you cannot make any changes into the item. Hence updation action should be seperated from itration process calling loop.


1

I have used below JavaScript function to get login name of current logged in user. While working on this code, it was noticed that get_loginName() function brought i:0#.w|DomainName\asad. So I have used string manipulation to get the desired one i.e. DomainName\asad function getCurrentUser() { try { var clientContext = new ...


1

You can also add your scripts in the following section too. <SharePoint:DelegateControl runat="server" ControlId="AdditionalPageHead" AllowMultipleControls="true"/>


0

While you do not know how high the content will be after setting the width you will need two calls. By the way: the CSS you provided where do you put it in? the AppWeb oder the host Web? it should go to the host web because there the styling takes place. another waay is to use a greater default width value. instead of 300 so that the margin will not be to ...


1

In your custom page layout first add path to .js file (put path to src="") and then code. <script src="jquery-1.8.3.min.js">//<![CDATA[ //]]> </script> <script>//<![CDATA[ $(document).ready(function(){ //some code }); //]]> </script> <!--MS:<Publishing:EditModePanel ...


0

http://www.learningsharepoint.com/2012/09/22/get-count-of-distinct-values-in-a-column-of-sharepoint-list-with-javascript-client-object-model/ It will count the total number of distinct values in the column of a list. This is what i wanted to do, we just need to replace the listname and columnname in the code with the actual list name and column name. ...


0

I was able to get it working. I found the SP.JS file in the Layout folder of Sharepoint. With this I was able to Google about Sharepoint s REST API with OData at https://msdn.microsoft.com/en-us/library/office/fp142385.aspx and about OData Query parameters at http://www.odata.org/documentation/odata-version-2-0/uri-conventions/#SelectSystemQueryOption . This ...


1

Considering you are not interested in the whole document library VS mapped folder discussion, I believe that the main reason for placing branding elements (aka CSS) in the "Styles" mapped folder, instead of the parent, "Layouts" is mainly when you want to use the Themable engine. Whether you want to host your resources in a site or directly reference them ...


0

The answer, as always, is it depends. The first thing to consider is scope. Where are these files going to be used? If they are going to be used farm-wide then it makes most sense to deploy them to the _layouts folder. If they need to be visible at the site collection level then style library or site assets makes sense. You also need to consider whether ...


0

To me, it depends on what you are doing. If you are deploying a branding feature, then I would deploy it to the file system. This way you don't have hundreds of copies of your CSS and JS files lingering around. One place, easier to update should changes be necessary. If the feature is site or site collection scoped, than I tend to do the style library or an ...


5

I guess you could always use a site collection token in your URL. ~sitecollection URLs and tokens in SharePoint 2013 If that don't work out for you, this blog post has a lot of great examples when working with masterpages and references. Use Site Url in SharePoint Update Try using a scriptlink instead. I'm unsure if encoding is needed thought. Try to ...


1

You can use REST API along with CAML query. First create a CAML query that returns all item where Status equals Approved. <Query> <Where> <Eq> <FieldRef Name="Status" /> <Value Type="Text">Approved</Value> </Eq> </Where> </Query> Now use REST query using ajax. On Success method get the count of ...


2

If you use file system then during system backup those files will not get backed up. This is the same case with system migration. All files in file system needs to be moved separately. On the other hand if you use libraries then those files will be placed in the content database and will be included in backup as well as system upgrade etc. If you place ...


0

I provided code to use jQuery FullCalendar for a previous issue: Fetching items from sharepoint list and attaching in Fullcalendar with JSOM Let me know if you need help with that code. I updated the code to strip out most of the fullcalendar stuff so you can use this code for just about any calendar that accepts a JSON array. You just need to modify ...


1

Parameter names in JavaScript are case-sensitive. According to MSDN, it's dialogReturnValueCallback.


0

You have some qualitative question there - hard to give a definitive answer. The first place I would start is going back and being sure you really understand what the requirements are in full. You need both the technical and business requirements, and should understand what they are using this form for. Then you can help them understand the benefits of ...


3

Since I have to load the userprofile script, I had to use: SP.SOD.executeFunc('userprofile', 'SP.UserProfiles.PeopleManager', function() { var clientContext = new SP.ClientContext.get_current(); var personProperties = new SP.UserProfiles.PeopleManager(clientContext).getMyProperties(); clientContext.load(personProperties); ...


6

Getting only the current user won't be enough to get user profile properties. You need to use the PeopleManager as well. Your code should look something like this: var context = SP.ClientContext.get_current() var web = context.get_web(); var user = web.get_currentUser(); var peopleManager = new SP.UserProfiles.PeopleManager(context); var personProperties = ...


0

I'm not 100% percent sure, but it seems that you need to update the list item and not the file. From the pictures above, it looks like you need to use this post url: $ajax({ url: https://examplecustomer.sharepoint.com/sites/examplesite/_api/web/lists/getByTitle('Dokumenter')/items(19)", type: "POST", data: "{ '__metadata': { 'type': ...


2

First I am assuming that you're using SharePoint 2013. I would suggest you to use SharePoint's Client Side Rendering Framework. I would suggest this blog to understand how to apply CSR. The code which you can write to modify column names is as below (I am currently modifying "Title"): (function () { function preTaskFormRenderer(renderCtx) { ...


0

You need to run a crawl and have to add your custom property in the managed metedata properties settings in the display template to get the data


-1

You can do this with javascript and JSRequest. The ID should be passed in via the URL, (ie. 'DispForme.aspx?Id=11'), then use the below code to retrieve the '11'.. JSRequest.EnsureSetup(); var itemId = JSRequest.QueryString["ID"];


0

There's no need to make a request to the server when the userid is already loaded in browser. You can use: _spPageContextInfo.userId available in SharePoint 2013 and Online (wave 16).


0

Today i finally found a way to to remove button/group/tab from Ribbon by text "Id" via JavaScript. You probably hear about Ribbon.TrimById method. There is no "out-of-box" js analog of it. But from reverse-engineering of core.js I created this: <script type="text/javascript"> ExecuteOrDelayUntilScriptLoaded(function () { var original_f = ...


1

The Search Result web part has a set of pre-loaded display templates. So that is the reason you see templates get loaded that aren't necessary. The list of pre-loaded templates is the following: "~sitecollection/_catalogs/masterpage/Display Templates/Search/Group_Default.js", "~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_Default.js", ...


0

If you really want to create a document set using Javascript, JSOM/CSOM could be your option. Here is the sample with JSOM: How to create a Document Set in SharePoint 2013 using JavaScript Client Side Object Model. When you are using listdata.svc make sure, that it uses not field InternalName, but some interesting value similar to display name without ...


1

The following example demonstrates how to create Document Set and set its properties: function createFolder(webUrl,listName,folderOptions) { var folderPayload = folderOptions; folderPayload['Title'] = folderOptions.Url.split('/').pop(); folderPayload['Path'] = folderOptions.Url.split('/').slice(0, -1).join('/'); //Create Folder ...


0

Apparently Context Matters!! No, I had made a blunder in my code that I did not notice before. I was trying to update items on a parent site from a subsite. Not sure why, but I moved all my code to the parent site and it worked as expected! Lesson Learned! Will have to add this to my blog as it is really cool!! SP.ClientContext.get_current() is different ...


1

I presume you want this in a View. CSR - Client Side Rendering (SP2013/Online only) On SP2013 you can use CSR - Client side Rendering to change how a Column is displayed (on both Views and Forms) The context will then get you the iid: var iid = GenerateIIDForListItem( inCtx , listItem ); Besides a lot more scaffolding code than this one line, this ...


0

You can use the Dom/debug in the browser(press F12) then find the 'name =" "' atribute of the column. Then use that name with Spservcies. For my example I trigger my wf by updating a column then returning a workflow status colmn value: function CopyStrategyDocuments(StrategyDocID, StrategyDocLocation){ $().SPServices({ ...


1

Stefan, you need to register callbacks so that SharePoint will call them at appropriate times. In this case while saving the item. formCtx.registerGetValueCallback(formCtx.fieldName, function () { }) In the above function you got to return your fieldvalue so that sharepoint will pick it while saving the item. Please let me know if you have any ...


0

@Yayati had a very helpful response, but I had to use "item.get_item('ID')" instead of item.ID in order to get it working for me. Here's my code: function getUserInfo(AccountName) { var clientContext = new SP.ClientContext.get_current(); var userInfoList = clientContext.get_web().get_siteUserInfoList(); var query = new SP.CamlQuery(); ...


0

You can use Getlist method of the Web object MSDN Link.


1

Refer updated code. olist.update(); ctx.load(olist); Is update to below this.oListItem.update(); ctx.load(this.oListItem); So the update function looks like below. function dooperation(retvalue){ var ctx = new SP.ClientContext(url); var olist = ctx.get_web().get_lists().getByTitle('userlist'); var ...


0

You should load your added item in your code before executeQueryAync call: this.oListItem.set_item('Title',retvalue['Title'] ); this.oListItem.update(); ctx.load(this.oListItem);


0

You should not call executeQueryAsync method in loop as it will generate multiple async calls and execution will get messed up in deciding which onrecieveAllListItemsSucceeded method to execute. That is reason most of the time we get error The collection has not been initialized. It has not been requested or the request has not been executed. It may need to ...


1

You can get check the link for getting user info(ID, First Name, Last Name, Email, Username, Name) by User login Name. http://sharepoint.stackexchange.com/a/146788/40602 Use following way to set people or group field in javascript var user = User_ID + ';#' + User_Name; listItem.set_item(fieldName, users); listItem.update();


0

ExecuteOrDelayUntilScriptLoaded(init,'sp.js'); var currentUser; function init(){ this.clientContext = new SP.ClientContext.get_current(); this.oWeb = clientContext.get_web(); currentUser = this.oWeb.get_currentUser(); this.clientContext.load(currentUser); ...


1

There is only one masterpage gallery for the site collection, and that is at the root, so you have an invalid reference. It should be: <script src="/_catalogs/masterpage/scripts/bootstrap/bootstrap.min.js" type="text/javascript"></script>


2

This option is available if you have Publishing enabled on your site, and does not require any JavaScript. Go to Site Settings, find the Navigation link under Look and Feel. Select one of the Structural Navigation options (or if the parent is using Structural Navigation, you can select to use the same as parent). Towards the bottom will be a section ...


0

You can give it a try using REST query as below: <script src='http://code.jquery.com/jquery-1.11.3.min.js'></script> <script> var xmlString; try { //REST Query to get the display form url jQuery.ajax( { url: "http://<URL>/_api/Web/Lists(guid'<GUID>')/Views(guid'<GUID>')", ...


1

If you want to do things based on the current user's permissions here's your solution: var ctx = new SP.ClientContext.get_current(); var web = ctx.get_web(); ctx.load(web, 'EffectiveBasePermissions'); ctx.executeQueryAsync( function () { var permissions = web.get_effectiveBasePermissions(); ...


0

I just found out the other way of getting current user info function getCurrentUserEmail(){ var clientContext = new SP.ClientContext.get_current(); this.website = clientContext.get_web(); this.currentUser = website.get_currentUser(); clientContext.load(currentUser); clientContext.executeQueryAsync(Function.createDelegate(this, ...


1

I'm using the Chart.js, jquery-1.8.3.min.js and my custom .js to display a list in bar, pie, polar and much more. Please take a look here: http://www.chartjs.org/docs/ The custom .js for pie, doughnut and polararea looks in my case like this: // Declare the variables. var sitesProductSalesChart = sitesProductSalesChart || {}; // Array with colors for the ...


1

Use window.onbeforeunload in edit mode to perform all your operations. Here is how you check edit/display mode window.onbeforeunload = function (e) { var message = "Your confirmation message goes here.", e = e || window.event; // For IE and Firefox if (e) { e.returnValue = message; } // For Safari return ...



Top 50 recent answers are included