Thursday, May 10, 2018

IIS 7.0 and above impotent error messages



200 - OK. The client request has succeeded.
400 - Bad request. The request could not be understood by the server due to malformed syntax. The             client should not repeat the request without modifications.
401 - Access denied.
403 - Forbidden.
404 - Not found.
500 - Internal server error.
501 - Header values specify a configuration that is not implemented.
502 - Web server received an invalid response while acting as a gateway or proxy.
503 - Service unavailable.


Friday, February 10, 2017

Suggestions or Auto populate values in textbox using JQuery and C#(SharePoint 2013)


I have done this on SharePoint application page which is deployed under layouts folder, this can be also used in .net applications.
below is images shows you populated suggestions that are saved in database


First fill the data inside a gridview/table with fields that you need to auto populate
this can be done based on your coding capabilities

once you do it hide the table so that anyone cannot see it using CSS or code in my case i did with CSS
.GridHide is my class for hiding gridview and below other two classed is used to autocomplete list

<style type="text/css">
.GrdHide {
            display:none;
        }
        ul.ui-autocomplete {
    list-style: none;
}
.ui-autocomplete {
    height: 200px;
    overflow-y: scroll;
    overflow-x: hidden;

}
</style>

Code in JQuery to populate table data inside textbox i did this for two textboxes for project name and project number you can repeat the same as many columns you want

function GetData() {
            var MYProjNumb = new Array();
            var MYProjName = new Array();

            var table = $("#ctl00_PlaceHolderMain_hiddenGrd tbody"); //my table ID

            table.find('tr').each(function (i) {
                var $tds = $(this).find('td'),
                    ProjectNumber = $tds.eq(0).text(),
                    ProjectName = $tds.eq(1).text(),


                //alert('Row ' + (i + 1) + ':\npNumber: ' + ProjectNumber
                //      + '\nPName: ' + ProjectName);
                MYProjNumb.push(ProjectNumber);
                MYProjName.push(ProjectName);

            });
            ProjNumber(MYProjNumb);
            ProjName(MYProjName);
        }
        function ProjNumber(list) {
            var PJlst = GetUnique(list);
            $("[id*=txtProjNum]").autocomplete({
                source: PJlst,
                select: function (event, ui) {
                }
            });
        }
        function ProjName(list) {
            var PNLst = GetUnique(list);
            $("[id*=txtProjectName]").autocomplete({
                source: PNLst,
                select: function (event, ui) {
                }
            });
        }

to display only unique values in auto suggestion box then use the below code

        function GetUnique(list)
        {
            var unique = list.filter(function (itm, i, a) {
                return i == a.indexOf(itm);
            });
            return unique;
        }

call the above GetData() method on load of page

    <script type="text/javascript">
        $(function () {
            GetData();
});
</script>

all set...now you have auto populate textboxes on your page
limit your table data to 50 so that page loads faster.

Wednesday, November 16, 2016

Checking selected value in all dropdowns using jquery


Below code works if you have multiple drop downs where you want to check the selected value in all drop downs  in the form and see if this value is selected already, if selected then will show an alert message and change the selected value of that particular drop down


Add the "OnChange" in dropdown events as this onchange="ChkCurrent(this);
where 'id' is current value dropdown
 function ChkCurrent(id) {   
            var ddlValues = new Array();
            $("[id*='ddlstsCurrM']").each(function (i) {
                if ($(this).val()== 1) {
                    ddlValues.push($(this).val());
                }

            });
            if (ddlValues.length > 1)
            {
                alert("This value has been already selected");
                var ddlid ="#"+id.id;
                $(ddlid).val('0');

            }
        }

Thursday, August 11, 2016

Minimizing/hiding sub tasks on a tasks list in office 365


By default sharepoint will show all the subtask on a tasks list to minimize them use the below script by adding script editor webpart on tasks pages

<script src="https://sharepointsiteurl/SiteAssets/JS%20file/jquery-1.9.1.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $(".ms-commentcollapse-icon").click();

        });
</script>

Saturday, July 23, 2016

Workflows getting suspended when sending emails outside company domain using SharePoint designer in O365


SharePoint 2013 designer workflows does not allow users to send emails out side their company domain the alternative is to start 2010 workflow from 2013 with email functionality or degrade the workflow version to 2010

Wednesday, July 13, 2016

Retrieving all list items from a list which has crossed threshold limit in O365/sharepoint online using REST


To retrieve list item from a list which has already crossed the threshold limit i.e. 5000 items in 0365
this can only be done if we have indexed the list previously, i mean we can only query a list which has indexed column which has been created while list creation, in office 365 we cannot increase the threshold limit more than 5000 but we have an option to do that in on perm for up to 20000 items

increasing a threshold limit is not suggested by Microsoft, this will effect the performance, the only option to do this is to pull up data from a large list(more than 5000) in batches, you can batch data up to 4999 in once rest call and need to run untill the total count of the list completes

in the below code "ArchivedList" object will store all the items from a list in batch basis
use the script editor webpart to check this code.

<script src="https://yoursharepointsite/SiteAssets/Java%20Script%20Files/jquery-1.10.2.js"></script>  
<script type="text/javascript">
var ArchivedList = [];
var ListTest=[];
var i=0;
$(document).ready(
       function () {

           var spHostUrl = "https://yoursharepointsite";
           //Build absolute path to the layouts root with the spHostUrl
           var layoutsRoot = spHostUrl + '/_layouts/15/';
           $.getScript(layoutsRoot + "SP.Runtime.js", function () {
               $.getScript(layoutsRoot + "SP.js", getListData);
           }
           ); 
       }
     );
function getDataFromUrl(endpoint) {
     return jQuery.ajax({
         url: endpoint,
         method: "GET",
         headers: {
             "Accept": "application/json; odata=verbose",
             "Content-Type": "application/json; odata=verbose"
         }
     });
}
function getLargeList(nextUrl) {
     var dfd = new $.Deferred();
     if (nextUrl == undefined) {
         dfd.resolve();
         return;
     }
     getDataFromUrl(nextUrl).done(function (listItems) {
         var items = listItems.d.results;
          ListTest=items;
          ArchivedList=ArchivedList.concat(ListTest);
         var next = listItems.d.__next;
   
         $.when(getLargeList(next)).done(function (){
             dfd.resolve();
         });
     });
     return dfd.promise();
}
function getListData() {
     var documentLibName = 'Archived';
     
     https://yoursharepointsite/_api/web/lists/getbytitle(documentLibName)/items?$select=Title,No_Days,Current_x0020_State,Form_x0020_Type,Modified,ContentType/Name,ContentType/Id&$expand=ContentType&$filter=(Modified ge '"+strtDate +"' and Modified le '"+endDate+"') and startswith(ContentTypeId,'0x0120') &$top=200
     var listServiceUrl1= _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('Archived')/Items?$Select=Title,No_Days,Current_x0020_State,Form_x0020_Type,Modified,ContentType/Name,ContentType/Id&$expand=ContentType&$filter=startswith(ContentTypeId,'0x0120')&$top=200";
     
     
     
     var listServiceUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('" + documentLibName + "')/Items?$Select=Title,No_Days,Current_x0020_State,Form_x0020_Type,Modified,ContentType/Name,ContentType/Id&$expand=ContentType&$top=200";
     $.when(getLargeList(listServiceUrl)).done(function () {
            alert(ArchivedList.length);
 });
 }

</script> 

Deleting data from workflow history list using JSON 

copy past the below code in script editor webpart.

<script src="https://sharepoint_yoursite/subsitename/SiteAssets/Java%20Script%20Files/jquery-1.10.2.js"></script>
    <script type="text/javascript">
var clientContext;
var website;
var oList;
var cnt = 0;
var collListItem;
// Make sure the SharePoint script file 'sp.js' is loaded before your code runs.
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', sharePointReady);

// Create an instance of the current context.
function sharePointReady() {
    clientContext = SP.ClientContext.get_current();
    website = clientContext.get_web();
    oList = website.get_lists().getByTitle('Workflow History');

    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<View><RowLimit>1000</RowLimit></View>');
    this.collListItem = oList.getItems(camlQuery);

    clientContext.load(website);
    clientContext.load(collListItem, 'Include(Id)');
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}

function onQuerySucceeded(sender, args) {

    var listItemInfo = '';
    var listItemEnumerator = collListItem.getEnumerator();

    while (listItemEnumerator.moveNext()) {
        var oListItem = listItemEnumerator.get_current();
        var ID = oListItem.get_id();
        var oListItemDel = oList.getItemById(ID);
        oListItemDel.deleteObject();
        clientContext.executeQueryAsync(Function.createDelegate(this, this.onDeleteSucceeded), Function.createDelegate(this, this.onDeleteFailed));
        console.log(ID + " : Deleted");
    }
}

function onQueryFailed(sender, args) {
    console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}


function onDeleteFailed(sender, args) {
    console.log('Delete failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

function onDeleteSucceeded(sender, args) {
    cnt = cnt + 1;
    console.log('Delete success : ' + cnt);
}
</script> 

SharePoint - Cannot convert a primitive value to the expected type 'Edm.Double'. See the inner exception for more details If y...

Ad