Wednesday, March 22, 2017

Creating & Deploying SharePoint Workflow Custom Activities to SharePoint Online

Creating the Workflow Custom Activity

In your project select new item and add a custom SharePoint workflow activity as below:


A custom activity comprise of three components. they are the Elements.xml, the actions4 file and the xaml file which contain the flow of the activity.


Depending on your implementation the input and output parameters in your custom activity may vary. You need to edit the actions4 file accordingly. In the custom activity I'm creating there are three input parameters. Therefore I change the actions4 file as shown below. Basically you neeed to add the RuleDesigner and the parameters section to the file.

<Action Name="GetBuildingDetailsActivity" ClassName="CustomActivites.GetBuildingDetailsActivity" Category="Custom" AppliesTo="all">
  <RuleDesigner Sentence="Create a new lease record for the given %1 and records the %2, %3, %4 ">
    <FieldBind Field="buildingId" Text="Building ID" Id="1" />
    <FieldBind Field="buildingAddress" Text="Address" Id="2" />
    <FieldBind Field="buildingPhone" Text="Phone" Id="3" />
    <FieldBind Field="buildingManager" Text="Building Manager" Id="4" />
  </RuleDesigner>
  <Parameters>
    <Parameter Type="System.String, mscorlib" Direction="In" Name="buildingId" />
    <Parameter Type="System.String, mscorlib" Direction="Out" Name="buildingAddress" />
    <Parameter Type="System.String, mscorlib" Direction="Out" Name="buildingPhone" />
    <Parameter Type="System.String, mscorlib" Direction="Out" Name="buildingManager" />
  </Parameter>
</Action>

Afterwards, edit the xaml file according to the logic you need to implement. Here note that i have created several In and Out arguments of string type.



Deploying the Custom Activities to SharePoint Online

First create the WSP. In my case I published the WSP to a local folder location.


Then upload it to the SharePoint Solutions catalog which in under the "Web Designer Galleries" section

Activate the solution
















Now we can launch the SharePoint Designer and configure the created Workflow Custom Activity to a workflow.

SharePoint Designer Configuration

  • Launch SharePoint Designer
  • Open the SharePoint site
  • Under the "Workflows" select the type of workflow you need to create. In my case I'm choosing a list workflow. So I choose the list/library which I need the workflow to get deployed as well.
  • When the workflow is generated, click on the "Stage" section which you need to add the custom activity, then select the custom activity you created.


Here, I need to point out few things.

1) My Custom Activity was packaged within a feature. Therefore I have to activate the feature in order to get the custom activities listed down in SharePoint Designer as follows:


2) Initially when the Custom Activity is added you will get the argument names supplied. You need to configure them according to the columns in your list/library. The initial view is as below:

3) Also make it a point to add a ending transition by adding a go to

A final cut of the workflow will look something similar to the below image. In this workflow I have also added another custom activity which I created separately. The custom activities will run in a sequential manner during the workflow run.

In my list the Building Id is provided from the "Title" column. Hence, the argument is changed to reflect that. Also notice the, Go to which is added to end the workflow.

 Save and Publish the workflow you created to the SharePoint list/library.
Now is when the fun begins. You can go to the list/library and test run your workflow and see how it goes !!

Additionally, you can navigate to the list/library item and check on all the workflows associated with the item. You can see stage of the workflow and how it has proceeded so far, provided that you have done the logging (write to history actions) properly. One such example would be as in the below image




Tuesday, March 21, 2017

Migrate code first solution - Entity Framework

Fire up package manager console
























Type Enable-Migrations









A Migration folder will get created in your solution


Do the code changes you need to do for the entities. In my case I have added a new property as BirthDate to my Student class

Then in the Package Manager Window, type Add-Migration with a custom name which you would like to be referred to on the solution. In the solution explorer window, you would see a new file which has been created now.



Then run the update command to update the DB like below. Your changes will get reflected in the Database