Wednesday, July 20, 2016

Get current web URL in a Nintex workflow

In this article, we will show the steps to get the current web URL in a Nintex workflow on SharePoint custom list.

Step 1: Create a workflow variable say VarCurrentItemWebURL with multiple lines of text type as shown below


Step 2: Add a Regular expression action as shown below


In the Pattern add below line

/Lists/listname/DispForm.aspx.*$

Operation : Replace text

Replacement text :

Input text: {Common:ItemUrl}

Store result in : VarCurrentItemWebURL

Change display name of the SharePoint listview Fields

In this article, we will be changing the display names of fields selected in a list view.

Step 1: Create a list view in a page with some fields.

Step 2 : Edit the page, then add a Script editor web part in the page.

Step 3: Insert the below code in it

<script src="/SP2013/SiteAssets/Script/jquery-2.1.4.min.js" type="text/javascript"></script>

<script type="text/javascript">

_spBodyOnLoadFunctionNames.push("ChangeColumnName");

function ChangeColumnName() {

$('[ID="diidSort0LinkTitle"]').html("Employee ID");
$('[ID="diidSort0First_x0020_Name"]').html("First Name");
$('[ID="diidSort0Family_x0020_Name"]').html("Surname");
$('[ID="diidSort0Contact_x0020_Number"]').html("Token Number");
$('[ID="diidSort0ADID"]').html("User ID");

}

</script>

Below is the desired result




Friday, December 11, 2015

Bind SharePoint list datetime field values using ECMAScript

In this post, I will show how to bind the SharePoint list datetime field values using ECMAScript

Desired Output:

We can use the below script to get the desired output as shown above

<script type="text/javascript" src="~/SiteAssets/jquery-1.8.0.min.js"></script>

<script type="text/javascript">
    $(document).ready(function () {
            ExecuteOrDelayUntilScriptLoaded(retrieveListItems, "sp.js");
    });

        function retrieveListItems() {

        //Get the current context 
          var clientContext = new SP.ClientContext.get_current();

          var oList = clientContext.get_web().get_lists().getByTitle('TeamTasks');
          //Query
          var camlQuery = new SP.CamlQuery();

          camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name="Status" /><Value Type="Choice">In Progress</Value></Eq></Where></Query></View>');

          this.collListItem = oList.getItems(camlQuery);

          clientContext.load(collListItem);

          clientContext.executeQueryAsync(Function.createDelegate(thisthis.onQuerySucceeded), Function.createDelegate(thisthis.onQueryFailed));

    }

    function onQuerySucceeded(sender, args) {

        var innerhtml = "<table><tr><th><td>Task Name</td><td> Task Due Date</td></th></tr>";

        var MyDate = new Date();

        var listItemEnumerator = collListItem.getEnumerator();

        while (listItemEnumerator.moveNext()) {
            var oListItem = listItemEnumerator.get_current();
            MyDate = oListItem.get_item('DueDate');
            innerhtml += "<tr><th><td>" + oListItem.get_item('Title') + "</td><td>" + MyDate.format('d MMM yyyy') + "</td></th></tr>";
        }
        innerhtml += "</table>";

        PendingTasksdiv.innerHTML = innerhtml;
    }

    function onQueryFailed(sender, args) {
        //alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    }
</script>

<h3>Pending Team Tasks</h3>

<div id="PendingTasksdiv"></div>

Tuesday, November 17, 2015

Display SharePoint 2010 list data using REST and AngularJS

In this post, I’ll show how to display SharePoint 2010 list data using REST and AngularJS. 

Firstly create a list e.g. EmployeeDetails as shown below and add few records


Add the Html form web part with below code

<!--Angular JS file reference-->
<script type="text/javascript" src="/SiteAssets/angular.min.js"></script>

<script type="text/javascript">

var siteURL = "siteURL";
var spApp = angular.module('listmodule', []);

//Service
spApp.service('EmployeeListService', ['$http', '$q', function ($http, $q) {

    //Get the Employees
    this.getEmployees = function (listName) {
        var dfd = $q.defer();
        var completeUrl = siteURL + "_vti_bin/listdata.svc/" + listName + "?$select=";
        completeUrl += 'Id,Title,Technology&$orderby=Id asc';

        $.ajax({
            url: completeUrl,
            type: "GET",
            headers: { "accept": "application/json;odata=verbose" },
            success: function (data) {
                dfd.resolve(data.d.results);
            },
            error: function (xhr) {
                dfd.reject('Error : (' + xhr.status + ') ' + xhr.statusText + ' Message: ' + xhr.responseJSON.error.message.value);
            }
        });

        return dfd.promise;
    }

}]);

//Controller
spApp.controller('EmployeeDetailsController', function ($scope, EmployeeListService) {

    EmployeeListService.getEmployees("EmployeeDetails").then(
        function (result) {
            $scope.listitems = [];
            angular.forEach(result, function (item) {
                var listitem = {
                    ID: item.Id,
                    Title: item.Title,
                    Technology: item.Technology
                }
                $scope.listitems.push(listitem);
            });
            $scope.orderByField = 'ID';
            $scope.reverseSort = false;
        },
        function (reason) {
            $scope.errMessage = reason;
        });
});
</script>
<div ng-app="listmodule">
    <div ng-controller="EmployeeDetailsController">
        <div>
            <table id="tblEmployeeDetailsList">
                        <thead>
                            <tr>
                                <th>
                                    <a href="#" ng-click="orderByField='ID'; reverseSort = !reverseSort">ID <span ng-show="orderByField == 'ID'">
                                        <span ng-show="!reverseSort"></span></span></a>
                                </th>
                                <th>
                                    <a href="#" ng-click="orderByField='Title'; reverseSort = !reverseSort">Employee Name
                                        <span ng-show="orderByField == 'Title'"><span ng-show="!reverseSort"></span></span>
                                    </a>
                                </th>
                                <th>
                                    <a href="#" ng-click="orderByField='Technology'; reverseSort = !reverseSort">Technology
                                        <span ng-show="orderByField == 'Technology'"><span ng-show="!reverseSort"></span>
                                        </span></a>
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr ng-repeat="item in listitems | filter:query | orderBy:orderByField:reverseSort">
                                <td>
                                    {{ item.ID }}
                                </td>
                                <td>
                                    {{ item.Title }}
                                </td>
                                <td>
                                    {{ item.Technology }}
                                </td>
                            </tr>
                        </tbody>
                    </table>
               
        </div>
    </div>
</div>



Result :

Thursday, October 23, 2014

Add Custom Button in list form using jQuery

In this post I will explained how to add custom button in list form using jquery

Method 1:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $("input[value$='Save']").after($('<input id="btncustomsave" class="ms-ButtonHeightWidth" name="btncustomsave" type="button" value="Custom Save" onclick="JSMethod();" />')).hide();
    });

    function JSMethod() {
        alert('Hi');
        $("#ctl00_m_g_44ab3e22_6333_4ab7_80b7_a8c408fc4432_ctl00_toolBarTbl_RightRptControls_ctl00_ctl00_diidIOSaveItem").click();
    }
</script>


Method 2:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#ctl00_m_g_44ab3e22_6333_4ab7_80b7_a8c408fc4432_ctl00_toolBarTbl_RightRptControls_ctl00_ctl00_diidIOSaveItem ").hide();
        var submitHTML = '<td class="ms-separator">&nbsp;</td><td class="ms-toolbar" noWrap=""><input id="btncustomsave" class="ms-ButtonHeightWidth" name="btncustomsave" type="button" value="Custom Save" onclick="JSMethod();" /></td>';
        $(".ms-formtoolbar > tbody > tr").append(submitHTML);
    });

    function JSMethod() {
        alert('Hi');
        $("#ctl00_m_g_44ab3e22_6333_4ab7_80b7_a8c408fc4432_ctl00_toolBarTbl_RightRptControls_ctl00_ctl00_diidIOSaveItem ").click();
    }
</script>

Thursday, September 11, 2014

Find SharePoint 2010 SiteTemplate

In this post I will explained how to find the site template using client side/browser.

Step 1. Browse to any page on the site and view the HTML source code of the page then search for the "SiteTemplateID" in the javascript embedded into the page such as

 var g_wsaSiteTemplateId = 'STS#0';

Step 2. Check the g_wsaSiteTemplateId  value in the site template available in SharePoint  2010 by default from below link


Above siteTemplateId indicate teamsite.


Thursday, December 5, 2013

SharePoint 2010 Designer Workflow Email with embedded image


In this post, I will explain how to embed image in an email content of the SharePoint designer workflow.

1.       Upload image to be embedded in the SharePoint picture library.

2.       Create a new workflow variable with string data type.

3.       Edit workflow and set this newly created variable to HTML i.e. <img src=” http://SiteName/logo.jpg” />

4.       Then edit the email, press “Add or Change Lookup” and use this newly created variable.

5.       Save and Publish workflow

Thursday, November 28, 2013

Unable to open SharePoint 2010 Task form from word and outlook

In this post I will explained one of  the issue I faced after associating SharePoint 2010 OOB approval workflow to SharePoint document library.
After triggering the workflow manually it generates tasks and sends email notification to person whom it is assign. However when the user/person try to open the task form it throws the below error message as shown below

Element '{http://www.w3.org/1999/xhtml} div’ is unexpected according to content model of parent element '{http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields} Body’

After doing some research the below solution work for me

1.Go to the Task list which is used to store the workflow task by this approval workflow.
2.Click Task List Settings, and click "Approval Workflow Task (en-US)" content type (may be you used) in Content Types section.
3.Click the "Workflow Task" from Source column.
4.You can find the "Body" column and click it, then click "Edit site column" to change type from "Enhanced rich text" to "Plain text".

Thursday, October 3, 2013

SharePoint 2010 Custom Display Form Comments History not showing

In this post I will explain one of my experience when creating SharePoint custom list display form.

For one list we have version history enabled with one field called “Comments” as multiline with append text enabled.

After creating the custom form the comments will display as

<xsl: select=”@Comments” value-of disable-output-escaping=”yes” />

and comments history was not visible.

After replacing the above line with

<SharePoint:AppendOnlyHistory runat=”server” ControlMode=”Display” FieldName=”Comments” ItemId=”{@ID}”  />
All details are showing perfectly.

Export and Import SharePoint Designer 2010 List Workflow

In this post I will explain how to export and import SharePoint 2010 designer list workflow from one site/list to another using simple approach.

1.      Open SharePoint Designer 2010, Navigate to the workflow section.

2.      Then click on “Export to Visio”. Save the file as CopyListItems.vwi or any suitable name.

3.      Then create a new list with same schema on same site or another site collection.

4.      In SharePoint 2010 there is no direct way to import the previously exported workflow into the newly created list.

5.      Navigate to the newly created list and create list workflow without any workflow steps or empty. Then click on “Save” and “Publish” the newly created workflow say BlankWF.

6.      Then Click on “Export to Visio” and save this BlankWF.vwi or any suitable name.

7.      Rename both vwi files as .zip i.e CopyListItems.zip and BlankWF.zip.

8.      Replace the “workflow.xoml.wfconfig.xml” file from BlankWF.zip into CopyListItems.zip

9.       Remove .zip extension to .vwi and “Import from visio” and select CopyListItems.vwi.

Saturday, August 10, 2013

Apply style to welcome menu text in SharePoint 2010 master page



In this post I will explain the various styles applied to welcome menu text

.s4-trc-container-menu
This class is applied to DIV tag that binds the welcome text

.s4-trc-container-menu {
    float: left! important;
    margin: 12px 3px!important;
}

.ms-SPLink
This class is applied to SPAN tag
.ms-SPLink {
    color: #32B0A4!important;
    font-family: 'Tahoma’, ‘Lucida Grande’, Verdana,Arial,sans-serif! important;
    font-size: 0.8em!important;
}

.s4-trc-container-menu .ms-SPLink
.s4-trc-container .ms-SPLink {
    display: inline!important;
    vertical-align: middle!important;
}
.ms-SpLinkButtonInActive
.ms-SpLinkButtonInActive, .ms-SpLinkButtonActive {
    padding: 1px 1px 1px 3px!important;
}
.ms-HoverCellInActive, .ms-SpLinkButtonInActive {
    background-color: transparent!important;
    border: medium none!important;
    color: #3F3F3F!important;
    margin: 1px!important;
    vertical-align: top!important;
}

.ms-welcomeMenu
.ms-welcomeMenu {
    border: 1px solid transparent!important;
    display: inline-block!important;
    font-family: Verdana,sans-serif!important;
    font-size: 1em!important;
    margin: 0 3px!important;
    padding: 2px 5px 3px!important;
}

.ms-welcomeMenu  a:link
.ms-welcomeMenu  a:link {
Color:#fff!important;
}
.ms-welcomeMenu a:hover
.ms-welcomeMenu  a:hover {
text-decoration:none!important;
}
.ms-viewselector-arrow
.ms-viewselector-arrow {
    vertical-align: middle;
}

Now we will add current login user photo nearby the welcome menu text. In order to do so add the below register tag in the master page

<%@ Register Tagprefix="SPSWC" Namespace="Microsoft.SharePoint.Portal.WebControls" Assembly="Microsoft.SharePoint.Portal, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

Then find the div tag with class “s4-trc-container-menu” and add the below line in next line after this class 

<SPSWC:ProfilePropertyImage PropertyName="PictureUrl" style="float: left; height: 20px;" ShowPlaceholder="true" id="PictureUrlImage" runat="server"/>
text-decoration:nonetext-decoration:nonetext-decoration:nonetext-decoration:none}