Archive

Archive for March, 2010

Launching an Infopath form with a button click

March 22, 2010 2 comments

When an Infopath form is published to Sharepoint Form Library, the only way to open a new form is either my navigating to the corresponding sharepoint library and click “New” or by clicking on the “Fill Out This Form” menu.

In order to open a new Infopath Form elsewhere in the Sharepoint site, you can use the below script and use a button click to achieve the same. As shown in the script below all you need is the sharepoint document library link.

<script type="text/vbscript" language="vbscript">
	Dim urlLibrary
	Dim urlTemplate
	
	urlLibrary = "http://sharepoint/sites/teamsite/DocLibrary"
	urlTemplate = urlLibrary + "/forms/template.xsn"

	Sub CreateNewInfoPathDocument
	  dim objOpenXMLDocuments
	  set objOpenXMLDocuments = Createobject("SharePoint.OpenXMLDocuments")
	  objOpenXMLDocuments.CreateNewDocument2 window, urlTemplate, urlLibrary
	End Sub
</script>

<!--Button Code-->

<button onclick="CreateNewInfoPathDocument()">Create New</button>
Advertisements

SharePoint Lists.asmx CAML Queries

March 19, 2010 8 comments

Recently, i had been working with SharePoint’s webservices, particularly Lists.asmx which is used for working with lists and corresponding list data.

The Lists class exposes several methods wherein “GetListItems” method is the one that i used to interact with my custom list available in SharePoint. The “GetListItem” method accepts a series of parameters. “query” is one of the parameter which passes a CAML query (assigned to System.Xml.XmlNode object) to query the appropriate list.

When i wanted query 2 list fields, I didn’t face any issue and the XML looks like:

<Query>
	<Where>
		<And>
			<Geq>
				<FieldRef Name="Reported_x0020_On"/>
				<Value Type="DateTime">2010-03-15T00:00:00</Value>
			</Geq>
			<Lt>
				<FieldRef Name="Reported_x0020_On"/>
				<Value Type="DateTime">2010-03-16T00:00:00</Value>
			</Lt>
		</And>
	</Where>
</Query>

Now, when the need came to query 3 List fields, i wrote the CAML query as:

<Query>
	<Where>
		<And>
			<Geq>
				<FieldRef Name="Reported_x0020_On"/>
				<Value Type="DateTime">2010-03-15T00:00:00</Value>
			</Geq>
			<Lt>
				<FieldRef Name="Reported_x0020_On"/>
				<Value Type="DateTime">2010-03-16T00:00:00</Value>
			</Lt>
			<Eq>
				<FieldRef Name="Environment"/>
				<Value Type="Choice">UAT</Value>
			</Eq>
		</And>
	</Where>
</Query>

but this query resulted in the following exceptions when i tried calling the Lists webservice’s GetListItems method:

Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown.

Cannot complete this action.
Please try again.0x80004005

after a lot of guesses, i realized the fact that we need to format the criteria in pairwise conditions, like the one given below (note: i have used 3 conditions here)

<Query>
	<Where>
		<And>
			<And>
				<Geq>
					<FieldRef Name="Reported_x0020_On"/>
					<Value Type="DateTime">2010-03-15T00:00:00</Value>
				</Geq>
				<Lt>
					<FieldRef Name="Reported_x0020_On"/>
					<Value Type="DateTime">2010-03-16T00:00:00</Value>
				</Lt>
			</And>
			<Eq>
				<FieldRef Name="Environment"/>
				<Value Type="Choice">DEV 1</Value>
			</Eq>
		</And>
	</Where>
</Query>

similarly, when i’m in need for building 4 search criteria. Remember to group your criteria in pairs.

<Query>
	<Where>
		<And>
			<And>
				<Geq>
					<FieldRef Name="Reported_x0020_On"/>
					<Value Type="DateTime">2010-03-15T00:00:00</Value>
				</Geq>
				<Lt>
					<FieldRef Name="Reported_x0020_On"/>
					<Value Type="DateTime">2010-03-16T00:00:00</Value>
				</Lt>
			</And>
			<And>
				<Eq>
					<FieldRef Name="Environment"/>
					<Value Type="Choice">UAT</Value>
				</Eq>
				<Eq>
					<FieldRef Name="Resolved"/>
					<Value Type="Choice">Yes</Value>
				</Eq>
			</And>
		</And>
	</Where>
</Query>

i haven’t found much help when i was researching on this exception and it really took most of my time in this research and thats when i tried to document it and let others know about it.

%d bloggers like this: