A Practical Guide to SharePoint 2013

A Practical Guide to SharePoint 2013
A Practical Guide to SharePoint 2013 - Book by Saifullah Shafiq
Showing posts with label SPQuery. Show all posts
Showing posts with label SPQuery. Show all posts

Wednesday, May 14, 2008

XPath, XQuery, and XSLT Functions

Some XML functions can be very useful in InfoPath, especially if you are an InfoPath developer. For example, suppose you are using data validation in your InfoPath form and you want the users to enter a value in one of the text boxes on your form. Of course, you can use the built-in data validation functions, for example, "If field is blank then show error alert" but users can dodge you by entering a space in the text box. In this case, InfoPath won't generate any error and will accept the value entered by the user. How can handle this situation? The answer is XML functions. You can use normalize-space() function. Right click the control and select "Data Validation". In the drop down, select "The expression" and in the text box enter normalize-space(.)="". In the screen tip, enter "Please enter valid value" and click Ok. InfoPath will now show an error if users try to enter an invalid value like a whitespace. Similarly, you can use other XML functions in your code or to validate data using the built-in data validation. More functions can be found on the following page. The page has the list of functions and examples to show how each function works:
 
-SSA

Friday, June 15, 2007

Using "AND" in SPQuery

Level: Beginner

Ok, here is a small tip for the beginners. If you are trying to search records based on two values, for example, "select * from list where a=1 and b=2" then how will you write its equivalent using the SPQuery object. Here is the sample:

SPQuery query = new SPQuery();
query.Query = "<Where><And><Eq><FieldRef Name='Field1'></FieldRef><Value Type='Number'>1</Value></Eq><Gt><FieldRef Name='Field2'></FieldRef><Value Type='Number'>0</Value></Gt></And></Where>";

This query will find records where Field1 = 1 and Field2 > 0.

So you have learnt two new things, using "And" and "Gt".