Posts

Sitecore custom publish agent from specific node and at a specific time

Hi all, As you all know, scheduled publishing will not run automatically unless you enable PublishAgent task in Sitecore config. By default, all items that are in publish queue will get published when this task triggers. This includes all items in the final workflow state and all items that don't have workflows. Sometimes this is not what you want. Maybe you don't enable workflow on media items and you don't want the items to go live when they are not ready. The workaround is to create your own PublishAgent task. Looking at the one provided, we can easily extend the code to insert the RootItem to the PublishOptions (this only works with Full or Smart publish mode however): You will notice that on the Run method I check whether the server time is around the time I set in the parameter (thanks to this post for the code). This will enable us to run the task near the specific time we set (e.g. midnight). In the config patch, just add this to enable the custom agent...

Sitecore keep or preserve url when 404 page not found

In some cases we don't want to redirect the users to a 404 page only because the users typed in the url wrongly. In this case what we want is to show the 404 content but keep or preserve the url. This way they can correct the url without having to type it in from scratch. The way to do this in Sitecore is to execute some code before the OOTB RedirectOnItemNotFound code. Create a config patch: And that's it. HTH, Andreas

Sitecore analytics trigger goal and add visitor tag

Hi, In order to achieve personalisation, sometimes triggering goal programmatically is necessary. The analytics API also provides a way to add tag to visitors. This is useful to differentiate between member types. Then the presentation components can be personalised based on the goal or the visitor tags. There you go. HTH, Andreas

Sitecore workflow email get original or submitting user email

Sitecore Workflow User warning: Today I did thorough testing on Workflow email. If you use the Workflow ContentHistory to get the submitting user like this as found on the web: http://blogs.perficient.com/digitaltransformation/2012/03/26/customizing-sitecore-workflow-emails/ It's a partial solution. It only works the first time approval is requested. Once the item is rejected, the last item in the history will be the approver (and not the submitter!). Using Statistics.UpdatedBy is more accurate since it will always be the user who edits the item. As to get the approver - this is not available as last history item nor the Statistics.UpdatedBy - just use the approver distribution email in the to field. HTH, Andreas

Sitecore remove previous versions on duplicating or copying item

Hi all, When duplicating or copying an item in Sitecore, all the versions are copied to the new item as well. Sometimes this is unwanted behaviour, especially when the first version of the item was not part of the workflow. When you publish the item, the latest published state would be published (i.e. the non-workflow version) A simple trick is to remove the previous versions of the item when duplicating or copying item. This is done by intercepting the uiCopyItems and uiDuplicateItem. Note that for uiDuplicateItem, the Sitecore.Buckets.config aborts the pipeline before the original duplicate pipeline. To avoid this, we make sure our custom pipeline is triggered first before the bucket config. Custom config patch: Sitecore.buckets.config: Then we have a Sitecore extension helper to remove the previous versions: DuplicateItem class: CopyItem class: And that's it. Note that I applied this to Sitecore 7.2 Update 5 HTH, Andreas

SharePoint 2013 User Profile Sync disabled user

Hi All, Just want to share a nice post that provides a trick with applying exclusion filter for disabled user accounts. If you add the filter after the first full profile sync, your filter won't work with Incremental sync unless you do Full sync. There is a trick to make Incremental sync picks up the changes, which is toggling (Enabling and Disabling) the user in AD and then run the Incremental sync. This should save you time if the number of disabled users is not that many and this won't clear any user-entered changes on existing user profile data. HTH, Andreas

SharePoint Infopath 2013 Publish as Content Type duplicate site column mistake!

Hi all, I have been enjoying my SP journey without InfoPath until two weeks ago when I was asked to help my colleague with Infopath form enhancement. Looking into how it was deployed to SP online, I noticed quickly it was published as a Content Type. So we did some enhancements, and once it's all done it's time to publish! What I wasn't aware of is that if the Form Template wasn't obtained from the deployed site, the promoted fields information will be set to 'Create new site column' instead of updating existing content type. After the form is published, it creates duplicate promoted site columns which are a nightmare to clean up! Not to mention that some site columns are read-only and cannot be deleted through UI. Luckily, I found that we can use SP JS to do the clean up of all duplicate fields. We just have to be careful to only delete the duplicate ones (marked by '_1' appended to existing field name, or '_12' and '_123...

SharePoint 2013 ​ zero width spacing characters.

Hi, Just want to let you know that to clean SharePoint html from the Rich Text Editor that has all annoying &#8203 characters, it is better to use this lovely script . Using standard jquery such as: jQuery('#s4-bodyContainer').html(jQuery('#s4-bodyContainer').html() .replace(/\u200B/g,'') ); can lead to unintended behaviour in certain scenarios, especially when some of the content is generated asynchronously as that script will replace the html before it's generated. This happened to me when I used the Search Result Webpart . HTH, Andreas

SharePoint 2013 contentclass STS_ListItem_850 not working anymore - no search results returned

Hi all, We just noticed in our lower environments after patching to SP1 + May 2015 CU, that our search returns no result. We have a Result Source with this filter: contentclass=STS_ListItem_850 and that is the culprit. Removing that filter returns all results. So I'm curious what the actual value is returned. Lucky we can check quickly with Search REST api. Running: http://mysite.com/_api/search/query?Querytext='page'&RowLimit='10'&SelectProperties='Title, ListID, contentclass' I see that the value is now So I changed STS_ListItem_850 to STS_ListItem_PublishingPages and now it works correctly again. HTH, Andreas

SharePoint 2013 How to exclude specific pages from search results

Hi all, Just want to share you a tip on how to exclude certain pages from your search results. e.g. test or obsolete pages that have been published but you want it to be hidden. The answer is to use a query rule. 1. Go to Site Settings -> Search Query Rules 2. Select the Result Source that you use, and add New Query Rule 3. Give it a name, and Remove Condition so the rule applies to all queries 4. click Change ranked results by changing the query. Again choose the appropriate source and here you can add filter on the properties. in my case I use the page Title: {searchTerms} -Title:"my page test" -Title:"Obsolete page to be hidden" 5. You can then test your queries for immediate change. Your changes will appear after a few seconds as SharePoint has suggested. HTH, Andreas

SharePoint 2013 - Cannot edit document properties after Visual Studio uninstall

Hi all, Yesterday after I uninstalled my VS2012 (since I have VS2013 installed) , I found that I could not edit document properties with this message: The server was unable to save the form at this time. Please try again. I then looked at the SP log file: ... Error when processing types in server stub DLL Microsoft.SharePoint.Client.ServerRuntime, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Data.Edm, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Data.OData, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 ... seems like the WCF Odata Services got uninstalled as well. The solution is to reinstall it: http://www.microsoft.com/en-AU/download/details.aspx?id=29306 and then restart your server. HTH, Andreas

SharePoint 2013 ignore code from search crawl or load balancer probes

Hi all, Sometimes when your homepage has a control or a webpart that access external site (e.g. wordpress blog), it will create unnecessary traffic when the page is touched by a search crawl or load balancer probes. If your probes are checking every few minutes it can create massive unwanted traffic that can increase your internet cost. The solution is to check the UserAgent of your request header to see where the request is coming from, and skip your code if it's coming from either of them. HTH, Andreas

SharePoint asp.net button only fires once - not firing the second time after reportviewer export

Hello, Just a quick one - I have a button click that generates a report pdf in the code behind. The problem is that it only fires once. This issue only happens in SharePoint. Turns out that you need to set the variable  _spFormOnSubmitCalled = false so that you can trigger the postback again (call this on OnClientClick attribute of the button) HTH, Andreas

Underscore js easy javascript object hierarchical filtering

Hi, Just want to share something that in my opinion is really a useful helper library, and that is underscore.js When combined with knockout, you can achieve easy filtering through its helper functions. Let's say we have an object structure like this: Company A   - Boss A       - Supervisor A           - Employee A           - Employee B           - Employee C       - Supervisor B           - Employee C           - Employee D   - Boss B       - Supervisor C           - Employee A           - Employee C Company B    etc.. and after you are getting the all records, you want to provide some filtering based on the Boss, Supervisor or Employee. (to make it simple I just use dropdowns) Using underscore, I can grab the list of uniq...

SharePoint 2013 Open with Explorer error We're having a problem opening this location in File Explorer.

Hi all, Just want to let you know about this annoying issue. UPDATE: apparently putting Http Deny Verbs OPTIONS and PROPFIND (to avoid anonymous office document prompt) was the cause!  I have SP2013 on premise. The 'Open with Explorer' was working on my dev environment before (when I populated some content before promoting to other environments). It is working in SYT but fails in UAT with this error. This only happen on one web application , the other web applications in UAT are fine. When it fails, you cannot also map the drive or open the location in Windows Explorer using UNC path as it will complain that the Network path was not found. The funny thing is when I tried it on my Dev site again it stopped working with the same error (no idea since when). I have looked at all the troubleshooting steps (WebDav etc.) and couldn't find out the cause. Also did server reboot with no luck. I restored my site collection backup to the same site and the issue persists. ...

Secure Store Service to store credentials - work with anonymous

Hi All, Just want to share something. Following my colleague's  post  , there is one more way on where to store settings, which is probably the preferred way. We have been using config list in SharePoint that only Site Collection Admin can access. The problem is that they are stored as clear text and SharePoint doesn't provide Password field type OOTB. Since the password requirement has changed, only infrastructure team can add/modify the password and they don't want us to know what the password is. As we want to avoid web.config modification, Secure Store Service application is the rescue! and it turns out to be pretty straightforward as well. Having created your Secure Store Service application and added the credentials in, I only had to create a helper class to retrieve my settings. I didn't end up using the code in that post as I want to simply grab all my key-value pair: Then you can just call that function and you will get your dictionary :) Hope th...

SharePoint repair WFE IIS Site Missing Virtual Directories

Hello, When you have multiserver environment, your web application provisioning can go wrong due to many reasons (app pool timeout etc.) and as a result you can get one WFE works while the other does not. In my case, some of OOTB virtual directories like _login and _windows were missing on one of my WFE. I don't want to recreate my web application from scratch - and luckily SharePoint provides Provision() and ProvisionGlobally() method. We ran Provision() on the failed WFE and it fixed all our IIS sites (default and internet zone) in one go. To do this just open powershell on the WFE: You can remove the IIS site completely in WFE IIS manager and Provision() will recreate the IIS site for you. Hope this helps, Andreas

Creating Web Template and WebProvisioned Receiver Walkthrough

Hi, As part of my migration project from MOSS 2007 to SP2013, I realised there was a site template I had to create. Reading up on web template and site definition, I decided to go with creating web template as this is much easier. Turns out that to get things glued up together (site columns, content types, lists, etc.) is not as straightforward as it seems as we need the right code. I have listed the final code here so if you are to go and create a new web template things will be easier (I hope) :) It's good to read this article as well re. Web Template Creating Site Columns and Content Types Creating these programmatically will allow you to have more control and will be able to upgrade these in the future. So in the 'Branding' feature, I create these with the help from this article  and extend the helper methods to cater for the publishing html fields: The Utility helper class: Creating Web Property Bag Next we will create property bag for our new site (...

SharePoint 2013 Search Results webpart Change Query (QueryBuilder) button not working

Hi everyone, I got this problem on my sites where 'Change Query' button on the Search Results webpart refreshes the page instead of showing the modal window. Looking at the console window it seems that it can't read property 'QueryBuilder'. Turns out after some investigation, it is because I had an html tag with name="Search" and it didn't like it. I changed the name tag to something else and it starts working again. HTH, Andreas

SharePoint 2013 Running workflow programmatically StartWorkflow error FAILED hr detected (hr = 0x8102008a)

Hello, Just want to share something in regards to starting workflow using the Workflow Manager in code. I have built a SPD reusable workflow for a content type. I then add this workflow to my list in my site. As I want to be able to trigger this workflow anonymously , I have to run the workflow using WorkflowManager instead of the standard auto start from UI (Otherwise the workflow will be created but will not run) Originally I used the ItemAdded event receiver, then use this piece of code: StartWorkflow function: But my workflows only get triggered for some records (intermittently). When I run the debugging, I can see that a weird error is thrown: An exception of type 'Microsoft.SharePoint.SPException' occurred in Microsoft.SharePoint.dll but was not handled in user code FAILED hr detected (hr = 0x8102008a) in the log : COMException: 0x8102008a Looking around for solution I couldn't find the answer. After some trials and errors, I noticed that...