Sunday, December 18, 2016

Install Node.js without admin rights

Hi Folks,
This is a copy paste version of one of the blogs which helped me.Giving due to credit to him.Just wanted a copy of the same with some minor updates.Below is the link for reference

Step 1: Get Node.exe
First you will need to download the Windows Binary. You can get it from Node.js download page or http://nodejs.org/dist/latest/. For x64, you will have to download from the appropriate folder. Move the executable to a local folder.
Step 2: Get NPM
NPM (Node Package Manager) is the package manager for Node.js and you will need this for your development. You can download NPM from https://github.com/npm/npm/releases and extract the zip file to a local folder.
Step 3: Copy the extracted files in a folder
Copy npm.cmd from extracted folder \npm\bin to the folder where node.exe resides
Now move the extracted npm files in a folder named "node_modules\npm" in the same folder where node.exe resides.
Such that the structure become like this
node (Folder)
|--------- node.exe
|-------- npm.cmd
|--------- node_modules (Folder, copied from the extracted zip) 
               |----- npm
                         |---- bin (extracted files)
                            ..... (extracted files)

Step 4: Configure the environment PATH variable.
You need to set up the PATH variable so that you can call node from anywhere in the system.
set PATH=%PATH%;D:\path-to-your-node;D:\path-to-your-npm
Mostly likely, the usual way of setting environment variables may not be accessible or not sufficient for you. instead you might want to hit Win + R (Open the Run dialog) and execute this:
rundll32 sysdm.cpl,EditEnvironmentVariables
This command will provide you with Environment Variables dialog box. You will be able to add/modify the PATH variable for the current user.
Step 4: Testing your Node.js installation
Quick way to test your Node.js installation is to get the version of Node.js that you are running by running the following command:
node --version

Extra: Setting up NPM to work behind a proxy
Apart from the hurdle of not having admin rights, one common issue is working behind the corporate proxy. Fire up your command line and type in the following:
npm config set proxy http://proxy:port
npm config set https-proxy https://proxy:port
If you need to specify the credentials, then use the following syntax:
npm config set proxy http://username:password@proxy:port
npm config set https-proxy https://username:password@proxy:port


Thursday, October 27, 2016

Creating custom events for a control in HTML

Hi All,

Sometimes we need to create a custom event for a control which we can use it to get the context of the control.Below is a quick method using jQuery to do that.

In the below example i have created an init method for input tag.

This method can be simply trigger using  
$(<SELECTOR>).trigger("<METHODNAME>")


Example



 <input id="txtName" class="news" init="initializeSection1" />

    <input id="txtName" class="news" init="initializeSection2" />

    <script>
        $(document).ready(function () {

            $(".news").bind("init", function (e, data, val) {
                var initializeFunctionName = $(this).attr("init");
                window[initializeFunctionName](e, data, val);
            });

            $(".news").trigger("init");

        });

        function initializeSection1(e, data, val) {

            alert("I called initializeSection1");
            var parentObj = $(e.currentTarget).parent()
        }


        function initializeSection2(e, data, val) {

            alert("I called initializeSection2");
            var parentObj = $(e.currentTarget).parent()
        }

    </script>

Tuesday, October 18, 2016

SharePoint 2016, 2013 , 2010 , 2007 Create list item with existing ID

Hey Guys,

Now i was in a really tricky scenario where a master record had been deleted by someone which was referenced using code in numerous places. Changing the code would be a nightmare.
Now the easiest solution which will come to everyones mind is to add the list item with those possible values again. But it would not retain the ID value which was used in the code.Let me give you an example to clarify the problem statement

PROBLEM STATEMENT
There is a “status” master list with the following values and the third list item is deleted.
We want the 3rd list item with ID=3 to be restored even when it is deleted from recycle bin as in the code the ID column is used to reference the status.

Status
ID
Approved
1
Rejected
2
Review
3
In Draft
4

SOLUTION:
Now usually the answers would be

  1.   Restore it from recycle bin (almost 3 months have passed and it has been deleted from recycle bin as well)
  2.   Delete the list and recreate the list with fresh entries (Break referential integrity of lists where the column from this list is looked up i.e lookup )
  3. It cannot be done.ID is auto increment column (Sad to head but its true)

So, last option would be to change the code L
This would result in enormous effort of code changing.
But wait if even you face similar scenario and have lesser amount of records (say 10-15 records) which have to be recovered then there is a savior
SITE MANAGER
Follow below steps to recover your item

  1. Create a replica of the list where the item is to be recovered
  2. Add all the items in the order required.
  3.   Navigate to site manager using below url
  4. http://<web level url>/_layouts/sitemanager.aspx
  5. Select the replica list in left navigation then list items will appear in right pane.
  6. Select the list item from replica list and select Actions >> Copy

  7.  Then in the copy dialog select the original list where the item was deleted.
  8.   Done


Note: This method can be used only when the item is deleted from recycle bin as well.If the item of same is present in recycle then it would not recreate with same ID.

Tuesday, September 27, 2016

Angular JS Table with Paging , GroupBy and Search

Some of the common syntax which are most often used while working on Angular js












Application Name :
ID Application Name
{{row.TowerValue}}
{{childRow.Id}} {{childRow.ApplicationName}}

Get Workflow History using Workflow.asmx SharePoint 2010

Sometimes we need to display workflow history based on the item id of the list item.

Below is the code which will help you to get that.

<!--
Outcome
Userid
Date Occured
Duration
Description
-->
<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices-2014.02.min.js"></script>


<script>



    $(document).ready(function () {

        ExecuteOrDelayUntilScriptLoaded(getHistory, "sp.js");
    });


    function getHistory() {


        var promoItemID = getParameterByName("promoid");

        getPromotionItem(promoItemID).done(function (historyItem) {


            var itemUrl = window.location.hostname + historyItem.get_item("FileRef");

            getWorklfowData(itemUrl).done(function (workflowInstanceIds) {

                var workflowHistoryData = getWorkflowDataByInstanceIds(workflowInstanceIds);

                generateTable(workflowHistoryData);

            });

        });


    }


    function getWorkflowDataByInstanceIds(workflowInstanceIds) {
        var workflowData = [];


        $(workflowInstanceIds).each(function () {


            var wfInstanceID = this;

            var url = window.location.origin + _spPageContextInfo.webServerRelativeUrl + "/_vti_bin/listdata.svc/EPMAHistory?$filter=WorkflowHistoryParentInstance eq '{" + wfInstanceID + "}'&$top=50&$expand=UserID&$select=UserID/Name,Outcome,UserID,DateOccurred,Duration,Description,ActualDurationDHM"
            $.ajax({
                type: "GET",
                dataType: "json",
                async: false,
                url: url,
                success: function (data) {

                    if (data.d.length > 0) {

                        for (var i = 0; i < data.d.length ; i++) {
                            var result = data.d[i];

                            var workFlowData = {};
                            workFlowData.Outcome = result.Outcome;
                            workFlowData.Userid = result.UserID;
                            workFlowData.DateOccured = Date(result.DateOccurred);
                            workFlowData.Duration = result.ActualDurationDHM;
                            workFlowData.Description = result.Description;
                            workflowData.push(workFlowData);

                            console.log(result.Id);
                        }
                    }

                },
                error: function (jqXHR, exception) {

                    console.log("Error " + jqXHR.responseText);
                }

            });

        });

        return workflowData;

    }


    function getPromotionItem(promoItemID) {
        var d = $.Deferred();

        var clientContext = SP.ClientContext.get_current();
        var promotionList = clientContext.get_web().get_lists().getByTitle('Promotions');


        var camlQuery = new SP.CamlQuery();
        camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name=\'ID\'/>' +
                                                        '<Value Type=\'Number\'>' + promoItemID + '</Value>' +
                                                  '</Eq></Where></Query>' +
                                       '<RowLimit>10</RowLimit></View>');

        var collListItem = promotionList.getItems(camlQuery);

        clientContext.load(collListItem);

        clientContext.executeQueryAsync(function (clientContext) {

            var collEnumerator = collListItem.getEnumerator();
            var historyItem;
            while (collEnumerator.moveNext()) {
                historyItem = collEnumerator.get_current();

            }
            d.resolve(historyItem);

        }, function (sender, args) {

            console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
            d.reject();

        });


        return d.promise();


    }





    function generateTable(historyRecords) {

        var tblHead = "<table><tr>" +
                                    "<td class='ms-vh2'  >Outcome</td>"
                                    + "<td class='ms-vh2' >User ID</td>"
                                    + "<td class='ms-vh2' >Date Occured</td>"
                                    + "<td class='ms-vh2' >Actual Duration</td>"
                                    + "<td class='ms-vh2' >Description</td>"
                            + "</tr>";
        var tblBody = "";
        var tblFooter = "</table>";

        $(historyRecords).each(function () {
            tblBody += "<tr><td class='ms-vb2'>" +
                             + "" + this.Outcome + "</td>"
                             + "<td class='ms-vb2'>" + this.Userid.Name + "</td>"
                              + "<td class='ms-vb2' >" + this.DateOccured + "</td>"
                            + "<td class='ms-vb2'>" + this.Duration + "</td>"
                            + "<td class='ms-vb2'>" + this.Description + "</td>"
+ "</tr>"
            ;



        });

        var tblHTML = tblHead + tblBody + tblFooter;
        $("#dvHistoryView").html(tblHTML);
    }


    function getWorklfowData(itemUrl) {
        var d = $.Deferred();
        var soap = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
        "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
            "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
            "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"> " +
          "<soap:Body> " +
            "<GetWorkflowDataForItem  xmlns=\"http://schemas.microsoft.com/sharepoint/soap/workflow/\">" +
                "<item>" + itemUrl + "</item>" +
            "</GetWorkflowDataForItem> " +
          "</soap:Body>" +
        "</soap:Envelope>";

        $.ajax({
            url: "http://appsapac.sanofi.com/epma/thp/_vti_bin/workflow.asmx",
            beforeSend: function (xhr) {
                xhr.setRequestHeader("SOAPAction",
                    "http://schemas.microsoft.com/sharepoint/soap/workflow/GetWorkflowDataForItem");
            },
            type: "POST",
            dataType: "xml",
            data: soap,
            complete: function (msg) {

                var workflowInstanceIds = getInstanceIDbyResponse(msg.responseXML);
                d.resolve(workflowInstanceIds);

            },
            contentType: "text/xml; charset=utf-8"
        });

        return d.promise();
    }


    function getInstanceIDbyResponse(responseXML) {

        var workflowInstanceIds = [];
        $(responseXML).find("ActiveWorkflowsData > Workflows > Workflow").each(function () {
            var thisStatus = $(this).attr("Status1");

            // Only show workflows which are currently In Progress (Status1 = 2)
            if (thisStatus == "2") {
                var thisTaskListId = $(this).attr("TaskListId");
                var thisTemplateId = $(this).attr("TemplateId");

            }
            var thisInstanceId = $(this).attr("Id");
            workflowInstanceIds.push(thisInstanceId);

        });

        return workflowInstanceIds;


    }



    /*Utility Methods*/

    function getParameterByName(name, url) {
        if (!url) url = window.location.href;
        name = name.replace(/[\[\]]/g, "\\$&");
        var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
            results = regex.exec(url);
        if (!results) return null;
        if (!results[2]) return '';
        return decodeURIComponent(results[2].replace(/\+/g, " "));
    }


</script>


<div id="dvHistoryView">

</div>

Thursday, September 1, 2016

SharePoint 2010 Calculated field value using ID column to generate an auto number

Hi All,

Sometimes we need to use the id column to generate an autogenerate number like INC0000332 etc.

Below formula can be used to create such a column.

=CONCATENATE("SIR-",REPT(0,4-LEN(ID+1)),ID+1)


Note: The item should be saved in order to reflect the value in the column.

Sunday, August 28, 2016

SharePoint 2010 List View Header Count of Rows

Hi All,

Sometimes we need to show the number of rows in the header itself when we have created an accordion on the webpart header.below is the code which helps us display count of the rows.


$(".s4-wpTopTable").each(function(){


var countOfRows=   $(this).find(".ms-listviewtable").find("tr .ms-vb2:first-child").length;


  $(this).find(".ms-WPTitle a span:first-child").append("<b> (" + countOfRows + ")</b>");



});



Edit: ID column is needed in the list view to display the count.Working on it so that this can be eliminated.