Tuesday, December 8, 2009

Update Sharepoint list using javascript

function CreateListItem(lstName,updateXML,wsURL,action)
{
var oXMLHttpRequest;
try
{
oXMLHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
alert("XMLHttpRequest not supported");
}


var soapEnv = '<?xml version="1.0" encoding="utf-8"?>';
soapEnv += '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ';
soapEnv += 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">';
soapEnv += '<soap:Body><UpdateListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">';
soapEnv += '<listName>'+lstName+'</listName><updates>'+updateXML+'</updates></UpdateListItems></soap:Body></soap:Envelope>';

oXMLHttpRequest.open("POST", wsURL, false);
oXMLHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
oXMLHttpRequest.setRequestHeader("SOAPAction", action);

oXMLHttpRequest.send(soapEnv);

alert(oXMLHttpRequest.status);

}

function updateList()
{
var updateXML = stringNode= "<Batch OnError='Continue'>";
updateXML+= "<Method ID='1' Cmd='Update'>";
updateXML+= "<Field Name='ID'><![CDATA[374]]></Field>";
updateXML+= "<Field Name='Title'><![CDATA[555]]>";
updateXML+= "</Field></Method></Batch>";
CreateListItem('ListName',updateXML,'http://siteURL/_vti_bin/Lists.asmx','http://schemas.microsoft.com/sharepoint/soap/UpdateListItems');
}

Tuesday, December 1, 2009

Site restoration using SPD

Steps to restore site from SPD
1. Open the site in the Sharepoint designer which you want to backup
2. Click on Site Tab -> Administration -> Backup Web Site
3. Click on the Advanced Button to verify if the site URL is corrected
4. If you want to put the Subsite in the archival, select the Checkbox
5. Save the .cmp file in the local system
6. Create a blank site
7. Open the newly created site in the SPD
8. Click on Site Tab -> Administration -> Restore Web Site
9. Click on the Advanced Button to verify if the site URL is corrected
10.Click ok to restore the site.

Monday, November 30, 2009

Split using CTE

Create function [dbo].[fn_Split](
@String nvarchar (4000),
@Delimeter nvarchar (10)
)
returns @RetTable table (pos int IDENTITY(1,1), String nvarchar(4000))
Begin
set @String = @String + @Delimeter;

with MySplit(x,y,z,Result)
as
(
select x = @String, y= @Delimeter , z = 0, Result = @String
union all
select ltrim(substring(x,charindex(y,x)+len(y),len(x))),y,z+charindex(y,x),substring(x,0,charindex(y,x)) from MySplit where len(x) >= len(y) and len(Result) >0
)

insert into @RetTable select Result from MySplit where z>0

return
End


--more than 100 entries are not supported here, so if the result is more than 100 rows then it will geve error

Split in SQLServer

Create function [dbo].[fn_Split](
@String nvarchar (4000),
@Delimiter nvarchar (10)
)
returns @ValueTable table (pos int,[Value] nvarchar(4000))
begin
declare @NextString nvarchar(4000)
declare @Pos int
declare @NextPos int
declare @CommaCheck nvarchar(2)
declare @index int
declare @lenstring int

set @index=1
set @lenstring= len(@Delimiter)
set @NextString = ''
set @CommaCheck = right(@String,@lenstring)
set @String = @String + @Delimiter

set @Pos = charindex(@Delimiter,@String)
set @NextPos =@lenstring
while (@pos <> 0)
begin
set @NextString = substring(@String,1,@Pos - 1)
insert into @ValueTable (pos, [Value]) Values (@index,@NextString)
set @String = substring(@String,@pos +@lenstring,len(@String))
set @NextPos = @Pos
set @pos = charindex(@Delimiter,@String)
set @index = @index +1
end

return
end

Friday, November 27, 2009

Fibonacci series using CTE

with MyCTE(x, y)
as
(
select x = 1 , y = 1
union all
select x + y,x from MyCTE where x<100
)
select x from MyCTE
order by x

PIVOT Queries

Pivot is basically used for the purpose of Presentation of data in the reports, and by using PIVOT the case and group by clauses are no longer useful

Following is an example of PIVOT table for getting the SLA for the different application

create a table
CREATE TABLE [dbo].[WeeklyStatus](
[Ticket] [int] NOT NULL,
[SLA] [int] NULL,
[Module] [nvarchar](50) )
make Ticket and Module pair as primary key

Insert few elements in the table and run the following query to get the no of tickets meet SLA for the application

select [Module],
[0] as SLAnotMeet,
[1] as SLAMeet
from (select [Module],[SLA],[Ticket] from WeeklyStatus) s
PIVOT
( count([Ticket]) for [SLA] in ([0],[1])) ws
order by [Module]

Update list item using web service

WS.Lists lst = new WS.Lists();
lst.Credentials = new NetworkCredential("userName", "Password","domain");
lst.Url = @"SiteURL/_vti_bin/Lists.asmx";

XmlDocument doc = new XmlDocument();
XmlElement element = doc.CreateElement("Batch");

string item = "<Method ID='1' Cmd='New'>" +
"<Field Name='Title'>mritunjay</Field>" +
"<Field Name='Area'>" + getID(lst, "11", "Area") + "</Field>" +
"<Field Name='Gasket'>None</Field>" +
"</Method>";
element.InnerXml = item;
lst.UpdateListItems("ListName", element);

Monday, October 26, 2009

MIME Types

application/envoy
application/fractals
application/futuresplash
application/hta
application/internet-property-stream
application/mac-binhex40
application/msword
application/msword
application/octet-stream
application/oda
application/olescript
application/pdf
application/pics-rules
application/pkcs10
application/pkix-crl
application/postscript
application/rtf
application/set-payment-initiation
application/set-registration-initiation
application/vnd.ms-excel
application/vnd.ms-outlook
application/vnd.ms-pkicertstore
application/vnd.ms-pkiseccat
application/vnd.ms-pkistl
application/vnd.ms-powerpoint
application/vnd.ms-project
application/vnd.ms-works
application/winhlp
application/x-bcpio
application/x-cdf
application/x-compress
application/x-compressed
application/x-cpio
application/x-csh
application/x-director
application/x-dvi
application/x-gtar
application/x-gzip
application/x-hdf
application/x-internet-signup
application/x-iphone
application/x-javascript
application/x-latex
application/x-msaccess
application/x-mscardfile
application/x-msclip
application/x-msdownload
application/x-msmediaview
application/x-msmetafile
application/x-msmoney
application/x-mspublisher
application/x-msschedule
application/x-msterminal
application/x-mswrite
application/x-netcdf
application/x-perfmon
application/x-pkcs12
application/x-pkcs7-certificates
application/x-pkcs7-certreqresp
application/x-pkcs7-mime
application/x-pkcs7-signature
application/x-sh
application/x-shar
application/x-shockwave-flash
application/x-stuffit
application/x-sv4cpio
application/x-sv4crc
application/x-tar
application/x-tcl
application/x-tex
application/x-texinfo
application/x-troff
application/x-troff-man
application/x-troff-me
application/x-troff-ms
application/x-ustar
application/x-wais-source
application/x-x509-ca-cert
application/ynd.ms-pkipko
application/zip
audio/basic
audio/mid
audio/mpeg
audio/x-aiff
audio/x-mpegurl
audio/x-pn-realaudio
audio/x-wav
image/bmp
image/cis-cod
image/gif
image/ief
image/jpeg
image/pipeg
image/svg+xml
image/tiff
image/x-cmu-raster
image/x-cmx
image/x-icon
image/x-portable-anymap
image/x-portable-bitmap
image/x-portable-graymap
image/x-portable-pixmap
image/x-rgb
image/x-xbitmap
image/x-xpixmap
image/x-xwindowdump
message/rfc822
text/css
text/h323
text/html
text/iuls
text/plain
text/richtext
text/scriptlet
text/tab-separated-values
text/webviewhtml
text/x-component
text/x-setext
text/x-vcard
video/mpeg
video/quicktime
video/x-la-asf
video/x-ms-asf
video/x-msvideo
video/x-sgi-movie
x-world/x-vrml

Thursday, September 24, 2009

Get pixel color of an Image

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" viewSourceURL="src/EmbeddingImages/index.html" layout="horizontal" width="626" height="626">

<mx:Image id="imageID" source="1.PNG" x="55" complete="image_bitmap(event);" mouseDown="image_click(event)"/>

<mx:Script>

<![CDATA[

import mx.graphics.BitmapFill;
import mx.controls.Alert;
import flash.display.Bitmap;

private var bm:Bitmap;
private var bmd:BitmapData;

private function image_click(e:MouseEvent):void
{
var color:int = bmd.getPixel(e.localX, e.localY);
Alert.show(color.toString(16).toUpperCase());
}
private function image_bitmap(e:Event):void
{

bm = imageID.content as Bitmap;
bmd = new BitmapData(imageID.contentWidth, imageID.contentHeight);
bmd.draw(bm.bitmapData);
}
]]>

</mx:Script>

</mx:Application>

Thursday, September 17, 2009

Creating the Column chart dynamically

Creating the Column chart dynamically


private function getData():ArrayCollection
{
var arr:Array = [];
arr.push({Month:"Jan", Profit:500});
arr.push({Month:"Feb", Profit:800});
arr.push({Month:"Mar", Profit:1000});
arr.push({Month:"Apr", Profit:700});
arr.push({Month:"May", Profit:900});
return new ArrayCollection(arr);
}


public function CreateColumnChart():void
{
Alert.show("CreateColumnChart");
var colmnChart:ColumnChart = new ColumnChart();
colmnChart.dataProvider =getData();
var catAxis:CategoryAxis = new CategoryAxis();
catAxis.categoryField = "Month";
colmnChart.horizontalAxis = catAxis;
var col:ColumnSeries = new ColumnSeries();
col.yField = "Profit";
col.xField = "Month";
colmnChart.series = [col];
colmnChart.visible = true;
hBox1.addChild(colmnChart);
}

Tuesday, September 8, 2009

Getting Sharepoint list item using lamda expression

SPSite objSPSite = new SPSite(@"http://server:portno/sites/myExample");
SPWeb objSPWeb = objSPSite.OpenWeb("mk");

SPList objSPList = objSPWeb.Lists["EmployeeList"];

IEnumerable oSPListItemEnum = objSPList.Items.OfType();

foreach (SPListItem objSPListItem in oSPListItemEnum.Where(x => x["ows_Status"].ToString() == "Closed" ))
{
Console.WriteLine(objSPListItem["Name"].ToString());
}

Tuesday, August 25, 2009

Triggers in SFDC

Apex triggers are the scripts that executes before and after the DML events.
Triggers that are associated with different business objects inside the Salesforce can be found at Setup->Develop->Apex Triggers and in the respective business object details page.

Syntax of writing a Trigger

trigger triggerName on ObjectName (trigger_events)
{
// code_block
}


types of trigger_events are:
1.before insert
2.before update
3.before delete
4.after insert
5.after update
6.after delete
7.after undelete

Single trigger can be of 32000 characters in length.

Lets see an example of how to send mail from the trigger

trigger mailMyObject on myObject (after update)
{
if(Trigger.isafter)
{
for(myObject s : Trigger.new)
{
String[] toAddresses;
String[] ccAddresses;
String[] replyTo;

//Business Logic

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(toAddresses);
mail.setCcAddresses(ccAddresses);
mail.setReplyTo(replyTo;);
mail.setSenderDisplayName('SFDC');
mail.setSubject('Mail from SFDC');
mail.setBccSender(false);
mail.setUseSignature(false);
mail.setHtmlBody('Mail Body');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
}

Monday, August 24, 2009

Named and Optional Arguments

One of the interesting feature of C # 4.0 is to have the Named and Optional Arguments, Optional Argument gives the flexibility of omitting the parameters in the call, and Named Argument gives the flexibility of passing the arguments by name in place of position.

Named Argument:
It provides us the flexibility or positioning the parameters by name in place of position, the value can be be provided by the use of argument. Lets see an example

student s = new student(name : "Ram", age : 25)

Optional Argument:
Any call for the function having the Optional Arguments have to specify only the required argument and can omit the optional arguments. Each of the Optional argument must have the default value assigned so that that value can be used when the value is not provided in the method call.

Method definition
void getClass (string Name, int age=20) (…)
Method Call
s.getClass(“Ram”);

When we invoke the method above it will pass Name as the parameter provided in the method call and the default value of age will be used.

Now let us consider the overloaded methods
void getClass (string Name, int age=20) (…)
void getClass (object o) (…)
void getClass (int age , string name = “Ram”) (…)
void getClass (int age) (…)

and if we call
s.getClass(4);

In the above overloaded functions the function getClass (string Name, int age=20) cannot be called as the parameter are not matching so remaining 3 are the better bet, in the remaining 3 converting the value 4 to int is better than converting to object.Among the last two overloaded functions, signature of the method getClass(int age) matches exactly to the call due to which the optional argument method will get lower priority and method getClass(int age) will be called.

Dynamic in C#

Dynamic Keyword allows us to invoke things dynamically, any operations that are called on the object, will be analyzed only at the runtime and the behavior will be decided at that instance.

static void Main(string[] args)
{
dynamic d1 = 1; //1
int i = d1; //2
dynamic d2 = GetDynamicObject(); //3
d2.foo(1,2) ; //4
var x = d2 + 10; //5

}

Let us diagnose the above-mentioned code how the things are working
1. Implicit Conversion of an integer.
2. Assignment Conversion to an integer.
3. Implicit conversion of an object to dynamic, this statement will be skipped at the compile time and will be resolved only at runtime and the compiler will allow us to call a method with any name and argument.
4. As the method foo is called, compiler will instruct that at runtime method foo have to be called with two arguments. Therefore, the runtime instance of d2 will decide the method availability.
5. As the operator + is having the dynamic typed argument it will be resolved at the runtime, at runtime object d2 will search for the operator overloaded resolution for +.


Compile time: At compile time for all the dynamic lookups uses DLR (Dynamic Language Runtime). DLR takes advantage of its call sites for all the dynamic operations.

Run time: All Methods and properties are binded by using reflection

customize newform/Editform in Sharepoint 2007

Steps to customize newform/Editform in Sharepoint 2007 using sharepoint designer.
1. Create a custom list
2. Open the site in Sharepoint designer
3. Navigate to newform.aspx of newly created custom list in Sharepoint designer
4. Take the back up of newform.aspx in the same folder.
5. Open the newform.aspx in the Edit mode and select the Split view.
6. Select the webpart in PlaceHolderMain (Custom) in “Design Mode”, and move to the “Code View” and Hide the webpart by putting the webpart code a separate table and Hide the row. You can hide the row by setting style 'display:none'.
We need to Hide the default content in place of deleting the code otherwise the reference with the parent code will be missing.
7. Switch to Design Mode and place the cursor on the new row of the table.
8. Navigate to Insert->Sharepoint Control->Custom List Form


9. A new Popup will appear for selecting the List

As we are editing the Newform.aspx select “New item form” in the “Type of Form to create” section.
10. Now the page is ready for the editing purpose and you can design by changing the location of the controls on the page