Tuesday, 22 March 2016

Add .js reference at run time to the existing page.




var jQueryScriptOutputted = false;
function initJQuery() {

    if (typeof(jQuery) == 'undefined') {  if (! jQueryScriptOutputted) {
jQueryScriptOutputted = true;        
       
var path   = "//ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"
   var script   = document.createElement( 'script' );
   script.src   = path;
   document.getElementsByTagName( 'head' )[0].appendChild( script );
 }
        setTimeout("initJQuery()", 50); } else {
   $(function() {

// add your code here...............

         
        });  }}

initJQuery();


Sunday, 7 February 2016

Something went wrong. To try again, reload the page and then start the workflow, error on starting a workflow.


sharepoint designer workflow is howing above error message when tried to start worfklow manually on list item, and worflow is not triggered on item added or updaed event.

This was happening for only few lists. On other lists workflow is triggering with out any issue.

Reason for the issue: we modified the default display and edit forms of the list which are throwing issue. 

Removed the pages which are modified for customization and added new pages using designer making new pages as the default display and edit forms then designer workflow started working.



Tuesday, 22 December 2015

Delete data from large lists using powershell

Delete data from large lists using powershell

cls
$web = Get-Spweb "http://........:/";
$list =  $web.Lists["NintexWorkflowHistory"]
$query = New-Object Microsoft.SharePoint.SPQuery;
$query.ViewAttributes = "Scope='Recursive'";
$query.RowLimit = 2000;
$query.Query = '<Where><Lt><FieldRef Name="ID"/><Value Type="Counter">1000000</Value></Lt></Where>';
Write-Host $list.Title
$itemCount = 0;
$listId = $list.ID;
[System.Text.StringBuilder]$batchXml = New-Object "System.Text.StringBuilder";
$batchXml.Append("<?xml version=`"1.0`" encoding=`"UTF-8`"?><Batch>");
$command = [System.String]::Format( "<Method><SetList>{0}</SetList><SetVar Name=`"ID`">{1}</SetVar><SetVar Name=`"Cmd`">Delete</SetVar></Method>", $listId, "{0}" );

do
{
    $listItems = $list.GetItems($query)
    $query.ListItemCollectionPosition = $listItems.ListItemCollectionPosition
    foreach ($item in $listItems)
    {
Write-Host $item.ID
        if($item -ne $null){$batchXml.Append([System.String]::Format($command, $item.ID.ToString())) | Out-Null;$itemCount++;}
    }
}
while($query.ListItemCollectionPosition -ne $null)

$batchXml.Append("</Batch>");
$itemCount;

$web.ProcessBatchData($batchXml.ToString()) | Out-Null;
#$web.RecycleBin.DeleteAll()
$web.Dispose()

Friday, 20 November 2015

Sharepoint 2013 visual studio workflow is not updated on subsequesnt deployments

tasklist /FI "IMAGENAME eq vssphost5.exe" 2>NUL | find /I /N "vssphost5.exe">NUL
if "%ERRORLEVEL%"=="0" taskkill /f /im vssphost5.exe
exit 0


http://stackoverflow.com/questions/19286924/sharepoint-2013-visual-studio-workflow-not-updating

Friday, 16 October 2015

SharePoint 2010 error while submitting nintex forms

An SPRequest object was not disposed before the end of this thread.  To avoid wasting system resources, dispose of this object or its parent (such as an SPSite or SPWeb) as soon as you are done using it.  This object will now be disposed.  Allocation Id: {}  To determine where this object was allocated, set Microsoft.SharePoint.Administration.SPWebService.ContentService.CollectSPRequestAllocationCallStacks = true.

System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x80131904
 at Microsoft.SharePoint.Library.SPRequestInternalClass.AddOrUpdateItem(String bstrUrl, String bstrListName, Boolean bAdd, Boolean bSystemUpdate, Boolean bPreserveItemVersion, Boolean bPreserveItemUIVersion, Boolean bUpdateNoVersion, Int32& plID, String& pbstrGuid, Guid pbstrNewDocId, Boolean bHasNewDocId, String bstrVersion, Object& pvarAttachmentNames, Object& pvarAttachmentContents, Object& pvarProperties, Boolean bCheckOut, Boolean bCheckin, Boolean bMigration, Boolean bPublish, String bstrFileName, ISP2DSafeArrayWriter pListDataValidationCallback, ISP2DSafeArrayWriter pRestrictInsertCallback, ISP2DSafeArrayWriter pUniqueFieldCallback)  
 at Microsoft.SharePoint.Library.SPRequest.AddOrUpdateItem(String bstrUrl, String bstrListName, Boolean bAdd, Boolean bSystemUpdate, Boolean bPreserveItemVersion, Boolean bPreserveItemUIVersion, Boolean bUpdateNoVersion, Int32& plID, String& pbstrGuid, Guid pbstrNewDocId, Boolean bHasNewDocId, String bstrVersion, Object& pvarAttachmentNames, Object& pvarAttachmentContents, Object& pvarProperties, Boolean bCheckOut, Boolean bCheckin, Boolean bMigration, Boolean bPublish, String bstrFileName, ISP2DSafeArrayWriter pListDataValidationCallback, ISP2DSafeArrayWriter pRestrictInsertCallback, ISP2DSafeArrayWriter pUniqueFieldCallback)







Not allowing to edit list items wicth the above exception.

Fix: Removed indexed column in the list. started working.

Tuesday, 1 September 2015

 ##SharePoint Copy Users between Site Colletions to same Groups

$SourceUrl = "http://";
$DestinationUrl = "http://";
 ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  #
 ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  #
cls
if ((Get-PSSnapin -Name Microsft.SharePoint.PowerShell -ErrorAction SilentlyContinue)) {
    Add-PSSnapin Microsoft.SharePoint.Powershell
    Write-Host "Loaded Powershell" -ForegroundColor gray
}

function CopyUsersBetweenSiteColetions( $SourceUrl, $DestinationUrl){
$SourceWeb = Get-SPWeb $SourceUrl -ErrorAction SilentlyContinue
    $DestWeb = Get-SPWeb $DestinationUrl -ErrorAction SilentlyContinue
    if (!$SourceWeb) {
        Write-Host "Not able to get site with url : $SourceUrl" -ForegroundColor Red
        return
    }
    if (!$DestWeb) {
        Write-Host "Not able to get site with url : $DestinationUrl" -ForegroundColor Red
        return
    }


    if ($DestWeb) {
    $DestWeb.AllowUnsafeUpdates = $true
        Write-Host " Getting site groups from the Site : " $SourceWeb.Title -ForegroundColor Yellow
        foreach($SourceGrp in $SourceWeb.SiteGroups) {
            $desGrp = $DestWeb.SiteGroups[$SourceGrp.Name]
                if ($desGrp) {
                    Write-Host "Comparing Group Members of the Group:- " $desGrp.Name -ForegroundColor Cyan
                    foreach($SourceMembr in $SourceGrp.Users) {
                        $DesMember = $DestWeb.EnsureUser($SourceMembr)
                            if ($DesMember) {
                           $exist = $desGrp.Users | Where{ $_.LoginName -eq $DesMember.LoginName  }

                            if(!$exist)
                            {
                             Write-Host " Adding User" $DesMember.LoginName "to the destination web" -ForegroundColor Gray
                                $desGrp.AddUser($DesMember)                          
                                }
                             
                            } else {
                                Write-Host $SourceMembr.Email " User Not existing in destination web" -ForegroundColor Yellow
                            }
                    }
                } else {
                    Write-Host "Group not exists in Destination site : " $SourceGrp.Name -ForegroundColor Gray
                }
        }
        $DestWeb.AllowUnsafeUpdates = $false
        $SourceWeb.Dispose()
        $DestWeb.Dispose()
        Write-Host "Opeartion complted." -ForegroundColor DarkYellow
    }
 }
 CopyUsersBetweenSiteColetions $SourceUrl $DestinationUrl

Tuesday, 25 August 2015

SharePoint 2013 sort Left navigation using jquery

var $eleContainer = $("tr td:last-child.ms-tv-item").closest('div');
var $aryTblChl = $eleContainer.children('table');
$aryTblChl.sort(function (a, b) {
    a = $(a).find("tr td:last-child.ms-tv-item").text();
    b = $(b).find("tr td:last-child.ms-tv-item").text();
    return (a == b) ? 0 : ((a > b) ? 1 : -1);
}); $aryTblChl.detach().appendTo($eleContainer);