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