Tuesday, February 24, 2009

SharePoint PreSaveAction


You can use below JavaScript function to execute any JavaScript Code in New or Edit Forms for SharePoint List before saving (When Pressing OK button this function will be fired first)

You can use this function for validation before PostBack

PreSaveAction()
{
    //Add Your JavaScript Code Here Then Return True Or False

    return false; // Cancel the item save process

    return true; // OK to proceed with the save item
}

Get Value of any SharePoint Control Using JavaScript

You can Get any Form Field Value By Using This JS Function

function getTagFromIdentifierAndTitle(TagName, Identifier, Title)
{
var len = Identifier.length;
var tags = document.getElementsByTagName(TagName);
for (var i=0; i < tags.length; i++)
{
var tempString = tags[i].id;
if (tags[i].title == Title && (Identifier == "" tempString.indexOf(Identifier) == tempString.length - len))
{ return tags[i]; }
}
return null;
}

Ex:
getTagFromIdentifierAndTitle('input','TextField', 'Title').value

Monday, February 23, 2009

SharePoint Site Backup and Restore Batch

Just copy backup part or restore part and past it in a new file then save it as *.bat

Backup Batch

Echo Site BackUp

@SET STSADM="%CommonProgramFiles%\Microsoft Shared\web server extensions\12\BIN\stsadm.exe"

pause

%STSADM% -o backup -url http://localhost:2009/ -filename "FileName.bak" -overwrite
%STSADM% -o execadmsvcjobs

Restore Batch

Echo Restore Site

@SET STSADM="%CommonProgramFiles%\Microsoft Shared\web server extensions\12\BIN\stsadm.exe"

pause

%STSADM% -o restore -url http://localhost:5000/ -filename "FileName.bak" -overwrite
%STSADM% -o execadmsvcjobs

Sum Of List Column



< xsl:value-of select="sum(/dsQueryResponse/Rows/Row/@ColumnName)" />

Saturday, February 07, 2009

SharePoint 2007 Built-in JS Functions


//Get Current User ID  i.e - alert(_spUserId);
_spUserId

//Run JS Function on Page Load
_spBodyOnLoadFunctionNames.push('FunctionName');

//First we must call the EnsureSetup method
JSRequest.EnsureSetup();

//Get a query string parameter called ItemId. i.e - "page.aspx?ItemId=11" will return 11
itemId = JSRequest.QueryString["ItemId"];

//Get the current page name. i.e - "default.aspx"
pageName = JSRequest.FileName;

//Get the current path name. i.e - "/doclib/default.aspx"
path = JSRequest.PathName;

SharePoint RPC Protocol (URL Protocol)

//Get List items in XML format
http://localhost/_vti_bin/owssvr.dll?XMLDATA=1&List={ ListDUID }

//Get List items where FieldName = Value in XML format
http://localhost/_vti_bin/owssvr.dll?XMLDATA=1&List={ ListGUID }&View={ ViewGUID }&FilterField1= FieldName &FilterValue1= Value

you can try it in your browser and see the result

For More >>