SharePoint REST API to get Discussion List Questions and Replies separately

To get the list of questions from a SP 2013+ Distribution list using OOTB REST API:

_api/lists/getByTitle(‘listname‘)/items?$filter=ContentType eq ‘Discussion’


/_api/lists/getByTitle(‘listname‘)/items?$filter=FSObjType eq 1

To get the list of replies from a SP 2013+ Distribution list, using OOTB REST API:

_api/lists/getByTitle(‘listname‘)/items?$filter=ContentType eq ‘Message’


/_api/lists/getByTitle(‘listname‘)/items?$filter=FSObjType eq 0

To get the list of Discussions with the replies count from a SP 2013+ Distribution list, using OOTB REST API:

/_api/lists/getByTitle(‘listname‘)/items?$select=ID,Title,Body,Folder/ItemCount &$expand=Folder/ItemCount &$filter=ContentType eq ‘Discussion’

Microsoft.SharePoint.SPException: Schema version of backup 15.0.xxxx.xxxx does not match current schema version 15.0.yyyy.yyyy

Microsoft.SharePoint.SPException: Schema version of backup 15.0.xxxx.xxxx does not match current schema version 15.0.yyyy.yyyy

A common error that you might face while doing site collection backups and restore is the following error:

Could not deserialize site from E:\SiteCollection1.bak . Microsoft.SharePoint.SPException: Schema version of backup 15.0.4641.1000 does not match current schema version 15.0.4719.1000     at Microsoft.SharePoint.SPSite.Restore(String filename, Boolean isADMode, Boolean& readOnlyMode, Boolean& hadWriteLock)

Note: You can capture this error in your ULS logs or use ULSViewer, when you run the Restore-SPSite command through SharePoint Management Console


#1: CU Update– The best & recommended fix is to ensure that you match the SharePoint Configuration Database versions to match both the environments (Goto Central Admin –> System Settings –> Manage Servers in this Farm)

In the same page, double check that you do not see any “Upgrade Required” mentioned against any of those servers. If it is mentioned there, please ensure that you run the SP Config Wizard before you proceed.

Once things look good, and you have compared the versions, download the latest KB from Microsoft and install them to match the SharePoint Configuration Database Schema versions. Perform all server remediation & CU (Cumulative Updates) installations. Remember to run the Configuration Wizards for each CU.

#2: Using STSADM – This is a pretty interesting workaround. But sometimes I feel “Old is Gold”. Power up your SP Management Console and try to perform the restore operation using the good old STSADM command line. At times, when the new powershell commands fails, stsadm has always worked for me. [[Touchwood]]

stsadm –o restore –url “site url” -filename “backup filename

#3: DB Restore – Content Database Backup and restore. You might want to check in Central Admin (View All Site Collections –> Select the Site Collection and check the Content DB on which it is installed on) about which all site collections will get affected if you restore a particular Content DB.

#4: Editing Backup File – This is one of those quick and untidy fixes you could possibly try. There are few caveats to keep in mind before you try this fix:

  • Ensure that the backup file size is smaller (preferably less than 500MB), else you might need a good editor (Visual Studio 2013 would crash beyond 500MB)
  • Keep note of the version number of the SharePoint Configuration Database Schema of the server to which you wish to restore the backup
  • Ensure that there are no major version differences in between the environment version. You can analyze this by going through the release notes of the higher version and see if there are no DB schema changes. Security updates/minor patches should be fine. But if you see any major DB schema changes in the release notes, please avoid this fix.
  • Success of this approach is not guaranteed. You may or may not crash the site collection that you will be restoring the backup to or may even corrupt the backup
  • Please take a backup of the backup file

The fix is pretty straightforward. You can open the backup file in Visual Studio or any Disassembler softwares and change the version number mentioned in the beginning of the file to that of the SharePoint Configuration Database Schema of your restoring environment. Those who have cracked software’s in the golden days could use one of their handy tools to edit the file as well.

Editing the version number part of the backup file manually.

Save the file and then try out the “Restore-SPSite” command this time. If things look good, you might succeed in restoring the backup without the version mismatch error…:)

Note: If your file size is in the range of GBs, as in case of one of my backups (2GB), try to split the large file into small 100MB files using file splitting tools like  GSplit tool –> Then edit the First split file in Notepad++/Visual Studio –> Change the schema version number –> Reunite the files using combining tools like GUnite (comes with the GSplit tool itself) and then use the reunited backup file in the STSADM restore command. Use this approach only when you are in a state where Desperate times calls for desperate measures…:X

Once again! Use the Fix #4 with caution and only under extreme cases.

Having multiple JSLink based webparts on the same page, overrides all the other templates in SP 2013


Create a dashboard page in SP 2013, displaying just 3 lists in 3 different views using Js Link capability. The 3 lists are:

  1. Accordion: A list containing title and description which will be displayed on the dashboard with an accordion functionality with title being the accordion item heading and description being the accordion item body.
  2. Menu: A list containing entries that can be used to construct a mega menu or a navigation menu.
  3. Alert: A list containing entries whose Body contents are lengthy and hence have to be trimmed down and ellipsis (…) added to the lengthy ones

The dashboard page was created and all the 3 list view webparts were added to it. All of them were given 3 different JsLink with different namespaces and method names. Each js had their template methods that rendered the list in the desired views and functionalities. ex. the accordion template method just returned “<h2>{Title}</h2><p>{Description}</p>” and an OnPostRender jQuery script to toggle them on <h2> click.


Loaded the Alert list first on the fresh page–> No issue; trimming the body content worked perfectly


Loaded the Accordion list next –> No issue; slide up and down of the accordion worked perfectly

Loaded the Menu list next –> Boom! The accordion lost its Js Link functionality and started behaving like the menu displaying items using the template defined for the Menu list.


Attached below are the 3 JsLink files used:

AlertsAccordion | Menu

Feel free to test it out…

If the JS Links had different namespaces & methods, why would it overwrite all the other templates on the same page? Could it be by design? By changing the BaseViewID, i could get the Accordion working but the menu then started taking the accordions template behavior…:(

Finally, I ended up having a single Js Link file (added as JS Link to all the webparts on the page) having the same template method, but internally it loaded different templates for each webpart by doing an <if> condition check for the List Name.
ex. if (ctx.ListName==’Accordion’) return “<h2>{Title}</h2>…”; if (ctx.ListName==’Menu’) return ‘<ul><li>{Tite}</li></ul>’; etc…

But somehow you will feel something is not right when you code it. Having a bulky js method with If-else or switch-cases…:(


Paul Hunt (@Cimares) has the solution for this scenario wonderfully detailed out here.This solution works and you can do an IF condition check to load the templates corresponding to each webpart accordingly.

I still wish if i could use independent JS Link files for all the webparts on the dashboard…:(…But, all in all JSLink is wonderful and I am happy to see MS taking the client side route and would love to support them in this direction…:)

Feel free to post your comments or possible alternatives or solutions.

JsLink not working with custom columns in a list


Let’s say we have a list view webpart, with a JsLink URL pointing to a js file (~site/SiteAssets/customrenderer.js). JsLink seems to be working fine when we use the “Title” and “Description” fields to render the list items in a color coded format.

However, when we try to display a custom column created ex. ColorCode, the JsLink seems to be breaking and displaying the List View in the default view.

Possible Causes:

  1. The current view loaded does not have the custom column you created. So edit the List View Webpart and modify the view, by selecting AllItems view or a new view you created. But ensure that this view has the custom column visible. Else it will throw undefined error while executing ctx.currentItem[“ColorCode”] in your Item template method in JsLink file.
  2. JsLink URL should begin with either of the following URL tokens: ~site, ~sitecollection, ~layouts, ~sitecollectionlayouts or ~sitelayouts only. Absolute paths will break the JsLink functionality.
  3. BaseViewID value seems to have an impact on the display. Let’s say you have multiple List Views on the page, then the BaseViewID plays an important role. Ensure that it is unique else the JsLink functionality works on all the other List View webparts you have loaded on the page.
  4. Try debugging & logging options inside your JsLink file. ex. Use console.log(ctx.currentItem) to see what all it is bringing.


Hope this helps!

JSLink SharePoint 2013 troubleshooting

JsLink is a good feature that was introduced in SP 2013 to allow users to bring in more flexibility in Client Side Rendering (CSR). With this you can control how your list data is getting displayed in View, Display, Edit and New forms.

For ex., you can achieve this using JSLink:



You can check the implementation here: JSLink Custom JS Rendering Tutorial


The JS Link was still not working and the list view remained the same.


Check the URL you defined in your JSLink webpart property (under Miscellaneous). You need to define the URL as: ~site/Site Assets/xyz.js” instead of defining the absolute or relative URL of your js file. It should always begin with a given set of URL tokens and then your file path. JsLink URL can begin with either of the following URL tokens: ~site, ~sitecollection, ~layouts, ~sitecollectionlayouts or ~sitelayouts only. Absolute paths will break the JsLink functionality.


MDS (Minimal Download Strategy) strategy having issues. Try using RegisterModuleInit(“{file URL}”, MyJsMethod); to register the JSLink. Check this link.

Also, as a best practice, its recommended to specify the SharePoint CSR filename in the JS Link URL.

ex. The JSLink URL for Tile View in Promoted Links would look like:

sp.ui.tileview.js | ~site/SiteAssets/xyz.js

SharePoint 2013: Log Analytics through javascript

The following code snippet will help you to log the usage analytics into ULS:

//Log Views usage event on URL of catalog item
    window.LogViewsToEventStore = function(url, site)
        SP.SOD.executeFunc(“sp.js”, “SP.ClientContext”, function()
            var spClientContext = SP.ClientContext.get_current();
                    var spWeb = spClientContext.get_web();
                    var spUser = spWeb.get_currentUser();
                    var spScope = “{00000000-0000-0000-0000-000000000000}”;
                    //Event ID = 1 (Views), 2 (
                    SP.Analytics.AnalyticsUsageEntry.logAnalyticsEvent2(spClientContext, 1, url, spScope, site, spUser);spClientContext.executeQueryAsync(null, null);                   
    LogViewsToEventStore(‘Url’, ‘SiteID’);

You can use this in your CSWP or other webparts on client side, with ease.

SharePoint 2013 BCS with WCF data source: Unknown Error occurred. Unable to load one or more of the requested types.

This is a common error that you would have faced, while adding a WCF service endpoint to BCS through SharePoint Designer 2013, connected to Office 365. The complete error would look like this:

Unknown Error occurred. Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

This is an error observed while connecting to a WCF data source through SharePoint Design 2013. Ensure that your WCF service endpoint is working perfectly.


STEP 1: Open the “SPDESIGN.exe.config” file from SharePoint Designer folder ()

STEP 2: Update the file with the following configuration:

<?xml version=”1.0″ ?>
<requiredRuntime version=”v2.0.50727″ />
<supportedRuntime version=”v2.0.50727″ />
<assemblyBinding xmlns=”urn:schemas-microsoft-com:asm.v1″>
<assemblyIdentity name=”Microsoft.BusinessData” publicKeyToken=”71e9bce111e9429c” culture=”neutral” />
<bindingRedirect oldVersion=”″ newVersion=”″/>

STEP 3: Save the file and run SharePoint Designer once again.

STEP 4: Try adding your WCF data source once again. Voila! you should see it work now…:)

The fix is just telling SPD to run BCS on version, if its gets a reference to version I guess our Office 365 online considers SharePoint 2013 version as 16, instead of 15. Forward thinking…quite understandable…:)

Hope this helps!