Friday 15 December 2017

SharePoint 2013: Start Workflow with JavaScript Client Object Model

I have a request to start workflow using client side code. Below is the code that fix my issue:

Code sample:

<button type="button" onclick="Startworkflow(); return false;">Start Workflow</button>

<script src=""></script>


function Startworkflow()

{ LoadScripts(); }

function LoadScripts(){

 SP.SOD.executeFunc("sp.js", "SP.ClientContext" , function(){

  SP.SOD.registerSod('sp.workflowservices.js', SP.Utilities.Utility.getLayoutsPageUrl('sp.workflowservices.js'));

  SP.SOD.executeFunc('sp.workflowservices.js', "SP.WorkflowServices.WorkflowServicesManager", StartWorkflow);



//Subscription id - Workflow subscription id

//list item id for which to start workflow. If site workflow, then send null for itemId

function StartWorkflow() {

   var subscriptionId = "f5fa7d47-52c0-48af-9728-acfad55731d2";

   var itemId = "";

   var ctx = SP.ClientContext.get_current();

   var web = ctx.get_web();

   var wfManager = new SP.WorkflowServices.WorkflowServicesManager(ctx, web);

   var subscription = wfManager.getWorkflowSubscriptionService().getSubscription(subscriptionId);

   ctx.load(subscription, 'PropertyDefinitions');


       function (sender, args) {

           var params= new Object();

           //Find initiation data to be passed to workflow.

           var formData = subscription.get_propertyDefinitions()["FormData"];

           if (formData != null && formData != 'undefined' && formData != "") {

               var assocParams = formData.split(";#");

               for (var i = 0; i < assocParams.length; i++) {

                   params[assocParams[i]] = subscription.get_propertyDefinitions()[assocParams[i]];



           if (itemId) {

               wfManager.getWorkflowInstanceService().startWorkflowOnListItem(subscription, itemId, params);


           else {

               wfManager.getWorkflowInstanceService().startWorkflow(subscription, params);



               function (sender, args) {

                   console.log("workflow start successfully");


               function (sender, args) {
                   alert('Failed to run workflow');




       function (sender, args) {         

           alert('Failed to run workflow');




As I have a site workflow, I am passing "itemId" parameter value null. You can pass your item id there.


Wednesday 29 November 2017

Hide Social Media share button in Power BI embed code

Recently I was having a task for creating Power BI chart and embedding it in SharePoint. So It is easily available in google. But the tricky part is when you embed it in SharePoint as iframe, it will show share button at bottom of it. Our client do not want that.

Here is the bottom of iframe:

So what is solution:

We add a new div tag and append our iframe within that with little css touch. Below is code for same:

Code sample:

.iframebox{width:100%; float:left;position:relative; overflow:hidden}
    width: calc(100% - 40px);
background: #eaeaea; 
    /*background: #eaeaea;*/
    height: 31px;
    display: block;
    position: absolute;
    bottom: 5px;
     z-index: 9999999999;
    position: absolute;
    left: 0;
    bottom: 41px;
    height: 1px;
    background: rgb(36, 65, 153);
    z-index: 999999999999999999;
    width: 100%;
.ms-dlgContent {z-index: 99999999999 !important;}

<div class="iframebox">
<!--   Iframe code goes here -->
   <div class="blueborder">&nbsp;</div>
   <div class="iframefooter">


Happy coding.

Saturday 28 October 2017

How to get Site details in SharePoint Online?

These days, Microsoft is obsoleting code based solution from Office 365.  And these leads us to use JavaScript Object Model / Client Side Object Model to get data and add them in to content editor / script editor webpart to display data.

In this blog we will try to get current site title, web tile and any intermediate web title using CSOM. You can go deep down if you have further requirement for these objects.

Here is the basic function to get site details:

Sample code:

var currSiteTitle; // site collection details
var currWebTitle; // get sub site details
var parentWebTitle; // get any intermediate site details

$(document).ready(function() {
    SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function() {

function getWebTitle() {

        var context = new SP.ClientContext.get_current();
        var site = context.get_site();
        var web = context.get_web();
        var parentInfo = web.get_parentWeb();  
        context.executeQueryAsync(function() {

                console.log("Intermediate site value: " + parentInfo.get_title());

                currSiteTitle = site.get_title();
                currWebTitle = web.get_title();
                parentWebTitle = parentInfo.get_title();
            function(sender, args) {

Original Source:

Tuesday 3 October 2017

QueryString-error-The name request does not exist in the current context

After a long time, I was working on .net project. Basically I forget all basic things and on of them was how to use Query String. So here is blog for those who face issue same as me when user querystring and get error :

The name request does not exist in the current context

Below was code I was using:

if (!String.IsNullOrWhiteSpace(Convert.ToString(Request.QueryString["Source"])))


Solution is very easy. First, you need to add below reference in your code:

using System.Web;

This will allow you to use "HttpContext.Current" in your code. So your final solution should look like below:

if (HttpContext.Current != null && !String.IsNullOrWhiteSpace(Convert.ToString(HttpContext.Current.Request.QueryString["Source"])))

Monday 11 September 2017

Cannot Read Property 'Showmodaldialog' of undefined

While working with SharePoint / JavaScript modal pop up you might encounter error "cannot read property 'showmodaldialog' of undefined". Here is simple solution for that.

Code Sample:

function OpenDocsDialog(url1) {
    var options = {
        url: url1,
        dialogReturnValueCallback: myDialogCallback
        SP.UI.ModalDialog.showModalDialog(options);  // this line gives error.

Solution :  We need to load "sp.js" file before calling above code. You can load "sp.js" file with below code sample:

ExecuteOrDelayUntilScriptLoaded(function () { //code }, "sp.js")

Full solutionExample :

function OpenDocsDialog(url1) {
    var options = {
        url: url1,
        dialogReturnValueCallback: myDialogCallback

    ExecuteOrDelayUntilScriptLoaded(function () {
    }, "sp.js")

Wednesday 12 July 2017

Activate Dynamics 365 in Office 365

Recently I have a POC task in Dynamics 365. And I spent some time as I din't know how to activate it. Follow below steps to activate dynamics 365:

  • Create Office 365 account (It must be E5 instance. E3 instance do not provide this functionality).
  • Once set up you will be able to see dynamics 365 installed.

  • But you can't start diging it out directly. There is bit configuration you need to add for activating it.
  • First click on admin icon to open admin center.

  • Now click on users.

  • In this you will see our user. select it.

  • In panel, click edit button on "Product licence".

  • Enable the Dynamics 365. Click save.


  • Now you will be able to see dynamics 365 in admin center. Click on it to open Dynamics365.

  • Select your required template. Click on complete set up.

  • Once setup, you will see Dynamics 365 Administration center.

Monday 19 June 2017

0x8007000d the data is invalid when chaging a file name.

Recently I have downloaded a file which was a song. I was trying to update few property of it when I encountered below error:

0x8007000d the data is invalid


I googled this issus and found below blog:

It contains the solution. so why i need to write this blog? Because it is microsoft blog which may be not understandable to all or you need to do some extra steps your self in google to achieve it.

Below are the steps:

  • First we need to download a free software. You ca download it from below URL:
  • Once download, install it in your machine.
  • Open the tool. And click on file menu. and then click on change directory.
  • Select your source location.
  • It will show all files in right side pane.
  • Now as per the blog, we need to update ID3 version 2.4 to version 2.3. But when you select your file and check property pane in left side, you can see that tag property is not there.
  • Don't worry. Just click save and you will see the version is changed to 2.3.
  • Once this is done, you can update your settings in the tool as well as outside of the tool.
Hope this helps.