Create a FetchXML query that uses ISNULL - dynamics-crm-2011

I want to make a FetchXML query that is using ISNULL like in SQL query.
In SQL
SELECT * FROM Contact WHERE ISNULL(FirstName, '') = ''
Do they have any operators for it in FetchXML?

Not exactly the same but the below query should give you something to work with.
<fetch mapping="logical">
<entity name="contact">
<all-attributes />
<filter>
<condition attribute="firstname" operator="null" />
</filter>
</entity>
</fetch>

Related

Modern SharePoint CAML query with multiple criteria

I am new to CAML. CAML seems like a great way to filter lists, but I am struggling to write nested and/or statements.
I am trying to start out small and write one CAML query with only two conditions so I can get the hang of it. Below is my failed attempt.
<View>
<Query>
<Where>
<and>
<Contains>
<FieldRef Name='PracticeArea_x0028_s_x0029_' />
<Value Type='Text'>Lean</Value>
</Contains>
<NotInclude>
<FieldRef Name='PracticeArea_x0028_s_x0029_' />
<Value Type='Text'>,</Value>
</NotInclude>
</and>
</Where>
</Query>
</View>
Any help, support, and/or insight this community can provide is greatly appreciated.
NotInclude used for Lookup field that allows multiple values, so won't work if you filter against a text field.
https://learn.microsoft.com/en-us/sharepoint/dev/schema/notincludes-element-query
You could filter by Contains first and then filter by Linq or similar approach.
SPList list = web.Lists.TryGetList("TestFilter");
SPQuery spQuery = new SPQuery();
spQuery.Query = #"<Where>
<Contains>
<FieldRef Name='PracticeArea' />
<Value Type='Text'>Lean</Value>
</Contains>
</Where>";
var items = list.GetItems(spQuery);
var filterItems=items.Cast<SPListItem>().Where(item => string.Format("{0}",item["PracticeArea"]).IndexOf(',') <0);
Console.WriteLine(filterItems.Count());

Join 2 lists in share point using CAML query

I just use Sharepoint for few days and I know this question have asked many times but I've tried all of them and none of them work.
These are my design
Document as a Document Library type have a Id
Id | DocumentName
---+-------------
1 | Document A
2 | Document B
Activities list, have a foreign key 'DocId' that reference to the Document Id
Id | DocId | Name
---+-------+-----------
1 | 1 | Activity A
2 | 1 | Activity B
3 | 1 | Activity C
4 | 2 | Activity D
The Problem is I need to get all the Activities that included the document name on the Document.
In SQL I can use Join query to get the additional information from another table. But I have try some Join statement in CAML query and none of them work.
Here is the result that I need to get.
Id | DocId | Name | DocumentName
---+-------+--------------------------
1 | 1 | Activity A | Document A
2 | 1 | Activity B | Document A
3 | 1 | Activity C | Document A
4 | 2 | Activity D | Document B
Could any one please suggest me the query?
Here is my query:
<View>
<ViewFields>
<FieldRef Name = 'DocLeafRef'/>
<FieldRef Name = 'ID'/>
<FieldRef Name = 'e8_document'/>
<FieldRef Name = 'Title'/>
<FieldRef Name = 'Author'/>
<FieldRef Name = 'Created'/>
</ViewFields>
<Joins>
<Join Type = 'INNER' ListAlias = 'Documents'>
<Eq>
<FieldRef Name ='e8_document' RefType = 'Id'/>
<FieldRef Name ='ID' List ='Documents'/>
</Eq>
</Join>
</Joins>
<ProjectedFields>
<Field ShowField ='FileLeafRef' Type ='Lookup' Name ='DocLeafRef' List ='Documents'/>
</ProjectedFields>
<Query>
<Where>
<Eq>
<FieldRef Name='e8_caseId'></FieldRef>
<Value Type = 'Number'>23</Value>
</Eq>
</Where>
</Query>
</View>
I'm query on the Activities list and the e8_document is the lookup field that reference to the Id in the Document. As I understand we need the projection and I've added the projection but the query throws an error.
It seems the Query element is invalid in your case, basically Query element could not contain Joins as a child element.
Server-Side Object Model
For SPQuery Class Joins element needs to be specified via SPQuery.Joins Property:
var qry = new SPQuery();
qry.Joins = #"<Join Type="LEFT" ListAlias="Documents">
<Eq>
<FieldRef Name="DocId" RefType="ID" />
<FieldRef Name="ID" List="Documents" />
</Eq>
</Join>";
Client-Side Object Model
Here is the complete CAML query for CSOM API:
<View>
<ViewFields>
<FieldRef Name="ID" />
<FieldRef Name="DocId" />
<FieldRef Name="Name" />
<FieldRef Name="Documents" />
</ViewFields>
<Joins>
<Join Type="LEFT" ListAlias="Documents">
<Eq>
<FieldRef Name="DocId" RefType="ID" />
<FieldRef Name="ID" List="Documents" />
</Eq>
</Join>
</Joins>
<ProjectedFields>
<Field ShowField="DocumentName" Type="Lookup" Name="Documents" List="Documents" />
</ProjectedFields>
<Query />
</View>

CAML filter to get the current month from the list?

In SharePoint 2010, I need to get items from a list based on a condition. Considering one of the fields to be 'Date' of type DateTime, the condition is:
Get Current Month Data.
How do I filter the list items based on this condition using CAML query?
By,
Raji
Use SPUtility.CreateISO8601DateTimeFromSystemDateTime to create relevant dateTime string
DateTime firstDay = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
Sting stringQuery =
String.Format(#"<And>
<Geq>
<FieldRef Name='Date' />
<Value Type='DateTime'>{0}</Value>
</Geq>
<Leq>
<FieldRef Name='Date' />
<Value Type='DateTime'>{1}</Value>
</Leq>
</And>",
SPUtility.CreateISO8601DateTimeFromSystemDateTime(firstDay),
SPUtility.CreateISO8601DateTimeFromSystemDateTime(firstDay .AddMonths(1)));
SPQuery query = new SPQuery(stringQuery);

Caml Query to fetch the items where the Lookup Column value is not null

I have a list of employees in sharepoint. One of the columns in the Employee list is a lookup Column called Organization.
I am trying to write a CAML query to fetch all the employees where the Organization value is not empty. But, I receive all the items even if the value of Organization is empty.
This is what I am trying
string querystring = string.empty;
querystring = "<Where><IsNotNull><Field RefName='EmployeeOrganization_x0020_Organization' /></IsNotNull></Where>";
This query is returning all the items in the list.
SPQuery query = new SPQuery();
query.Query = "<Where><IsNotNull><FieldRef Name='EmployeeOrganization_x0020_Organization'/></IsNotNull></Where>";
DataTable dtemp = emplist.GetItems(query).GetDataTable();
if (dtemp != null)
{
GridView1.DataSource = dtemp ;
GridView1.DataBind();
}
<Query>
<Where>
<IsNotNull>
<FieldRef Name='Project'/>
</IsNotNull>
</Where>
</Query>
Is working for me.You should use U2U CAML Query Builder to build the Query by using the Designer.. It automatically generates the required CAML expression for you.
Can you provide more from your context. What are your settings on the SPQuery instance?
Edit:
<Field RefName='Project'/>
to
<FieldRef Name='Project'/>

CAML Query BeginsWith Numeric Issue

In the following CAML query I reference 0 in the the line below.
<Value Type='Text'>0</Value>
This doesn't work even when the value is 0 bu twhen it is A it does work (I have entries in for both A and 0). I am unsure why numeric values are not getting picked up.
Any help would be appreciated.
<Query>
<Where>
<And>
<Eq>
<FieldRef Name='TCategories' />
<Value Type='Text'>Abbreviations</Value>
</Eq>
<BeginsWith>
<FieldRef Name='FirstCharacter' />
<Value Type='Text'>0</Value>
</BeginsWith>
</And>
</Where>
</Query>
i do have a similar query like this
which is actually working fine for me.
Make sure that the columns in your query "TCategories" and "FirstCharacter" are of Text type.
Thanks,
-Codename "Santosh"

Resources