On fetch return error 0x80040203 - dynamics-crm-2011

I'm trying to select the first 10 records "new_region" in MS Dynamical CRM
"<fetch mapping= ""logical"" count=""10"">"+
"<entity name='new_region'>"+
"<attribute name='new_regionid'/>"+
"</entity>"+
"</fetch>"+
Error:
<code>0x80040203</code>
<description>entity</description>
<type>Platform</type>
Please, help me!

Try this
string getRecords = #"<fetch mapping= 'logical' distinct ='true' count='10'>
<entity name='new_region'>
<attribute name='new_regionid'/>
<order attribute = 'new_name' descending = 'false'/>
</entity>
</fetch>";

Related

Create SharePoint CAML recurring calendar item

I'm using the Lists.asmx webservices to connect to my SharePoint 2010 server. I can upload a new calendar item using the below XML, but I can't figure out what field to add so that it's a "recurring every weekday" instead of an event that spans multiple days.
<Batch OnError="Continue" ListVersion="1" ViewName="">
<Method ID="1" Cmd="New">
<Field Name="Title">Test Event</Field>
<Field Name="EventDate">2018-10-01 00:00:00</Field>
<Field Name="EndDate">2018-10-01 23:59:59</Field>
<Field Name="fAllDayEvent">1</Field>
<Field Name="fRecurrence">1</Field>
<Field Name="EventType">1</Field>
<Field Name="UID">{17ea5230-d1f4-4fe2-acc2-450e839998ee}</Field>
<Field Name="RecurrenceData"><![CDATA[<recurrence>
<rule>
<firstDayOfWeek>su</firstDayOfWeek>
<repeat>
<weekly mo="TRUE" tu="TRUE" we="TRUE" th="TRUE" fr="TRUE" weekFrequency="1" />
</repeat>
<repeatInstances>10</repeatInstances>
</rule>
</recurrence>]]></Field>
</Method>
</Batch>
I'm creating the code as shown in this gist
You'll need to include two additional parameters are part of your event creation - one to let SharePoint know it is a recurring event (fRecurrence, a Boolean value) and another with the actual recurrence pattern (RecurrenceData, an XML string).
You can read more about the structure of the RecurrenceData XML here:
http://thehightechheels.blogspot.com/2012/12/sharepoint-evenet-recurrencedata-xml.html
There's quite a bit to it so rather than re-stating everything there, I'll share an example of how to create an event that recurs each weekday as requested:
<recurrence>
<rule>
<firstDayOfWeek>su</firstDayOfWeek>
<repeat>
<weekly mo="TRUE" tu="TRUE" we="TRUE" th="TRUE" fr="TRUE" weekFrequency="1" />
</repeat>
<repeatForever>FALSE</repeatForever>
</rule>
</recurrence>
Generally speaking a recurrence rule has 3 parts: the day of the week considered the first day; the pattern for repeating the event, and; when it ends, which can be never, after 'n' occurrences or by a certain calendar date.
Within the <repeat> section is where you have a lot of flexibility to set the pattern. For your scenario, the use of the <weekly> element combined with the weekFrequency parameter ensures this event will repeat every week. Within that week, we can then set which days of the week are to include the event; by setting Monday through Friday to "TRUE" (mo, tu, we, th, fr) we're telling SharePoint to repeat the event each of those days.
Summarizing the full Batch XML changes discussed in the comments below, here is the input I've used on my local SP2010 environment:
<Batch OnError="Return">
<Method ID="1" Cmd="New">
<Field Name="Title">Test Event</Field>
<Field Name="EventDate">2018-10-01 00:00:00</Field>
<Field Name="EndDate">2018-10-01 23:59:59</Field>
<Field Name="fAllDayEvent">1</Field>
<Field Name="fRecurrence">1</Field>
<Field Name="EventType">1</Field>
<Field Name="Duration">86340</Field>
<Field Name="WorkspaceLink">0</Field>
<Field Name="TimeZone">0</Field>
<Field Name="UID">{17ea5230-d1f4-4fe2-acc2-450e839998ee}</Field>
<Field Name="RecurrenceData"><![CDATA[
<recurrence>
<rule>
<firstDayOfWeek>su</firstDayOfWeek>
<repeat>
<daily weekday="TRUE" />
</repeat>
<repeatInstances>7</repeatInstances>
</rule>
</recurrence>]]>
</Field>
</Method>
</Batch>
Which yields this:
Just to make it easier on anyone else who finds this, here's the complete C# code necessary to create a recurring element.
private static XDocument GenerateBatchInsertXML(string title, DateTime start, DateTime end)
{
// http://thehightechheels.blogspot.com/2012/12/sharepoint-evenet-recurrencedata-xml.html
var recurrence = new XElement("recurrence",
new XElement("rule",
new XElement("firstDayOfWeek", "su"),
new XElement("repeat",
new XElement("daily",
new XAttribute("weekday", "TRUE"))),
new XElement("windowEnd", String.Format("{0:o}", end))));
return new XDocument(
new XElement("Batch",
new XAttribute("OnError", "Continue"),
new XAttribute("DateInUtc", "True"),
new XElement("Method",
new XAttribute("ID", "1"),
new XAttribute("Cmd", "New"),
new XElement("Field", new XAttribute("Name", "Title"), title),
new XElement("Field", new XAttribute("Name", "EventDate"), String.Format("{0:o}", start)),
new XElement("Field", new XAttribute("Name", "EndDate"), String.Format("{0:o}", end)),
new XElement("Field", new XAttribute("Name", "fAllDayEvent"), "1"),
new XElement("Field", new XAttribute("Name", "fRecurrence"), "1"),
new XElement("Field", new XAttribute("Name", "EventType"), "1"),
new XElement("Field", new XAttribute("Name", "UID"), "{" + Guid.NewGuid() + "}"),
new XElement("Field", new XAttribute("Name", "TimeZone"), "0"),
new XElement("Field", new XAttribute("Name", "RecurrenceData"),
new XCData(recurrence.ToString())))));
}

Liferay CustomSQL table doesn't exist

I have a service entity declaration which is as follows:
<entity name="MyContentRepo" local-service="true" remote-service="true" table="contentrepo">
</entity>
I am trying to use Custom SQL to fetch some details:
session = openSession();
String sqlQueryString = CustomSQLUtil.get("query_id");
SQLQuery query = session.createSQLQuery(sqlQueryString);
query.addEntity("MyContentRepo", MyContentRepoImpl.class);
QueryPos qPos = QueryPos.getInstance(query);
qPos.add("someparameter");
list = (List<MyContentRepo>) query.list();
But I get the following error upon execution:
08:02:26,640 ERROR [http-bio-8090-exec-72][JDBCExceptionReporter:82] Table 'mysqldb.mycontentrepo' doesn't exist
com.liferay.portal.kernel.dao.orm.ORMException: org.hibernate.exception.SQLGrammarException: could not execute query
The query is taking the name of entity declared not the table="contentrepo". can anyone tell me how to bypass this issue?
AddEntity once the SQLQuery has been translated to QueryPos. Change your code as given below:
session = openSession();
String sqlQueryString = CustomSQLUtil.get("query_id");
SQLQuery query = session.createSQLQuery(sqlQueryString);
QueryPos qPos = QueryPos.getInstance(query);
qPos.add("someparameter");
query.addEntity("MyContentRepo", MyContentRepoImpl.class);
list = (List<MyContentRepo>) query.list();

CAML person or Group field with Multiple values

I have a Field with Name TargetedPeople in a Sharepoint list. This is a Person or User group which can have multiple values.
The CAML I used for Querying is
siteDataQuery.Query = #"<Where><Includes><FieldRef Name='TargetedPeople' LookupId='TRUE'/><Value Type='Integer'>" + webInContext.CurrentUser.ID + "</Value></Includes></Where>";
This works fine if we have set the Allow Multiple Selections for "No" in the field. But this seems like not working for if it set to "Yes".
Please share me how to query a multiple field.
After some changes I was able to figure out this. If the field has multiple values we should define the value Type as LookupMulti. Following is the working code sample
siteDataQuery.Query = #"<Where><Contains><FieldRef Name='TargetedPeople' LookupId='TRUE'/><Value Type='LookupMulti'>" + webInContext.CurrentUser.ID + "</Value></Contains></Where>";
Also works and looks like simpler (tested on SP Online):
<Contains>
<FieldRef Name='TargetedPeople' />
<Value Type="Integer">
<UserID Type="Integer" />
</Value>
</Contains>

Element <Batch> of parameter updates is missing or invalid exception occurs while deleting sharepoint list record

I'm getting
Element <batch>
of parameter updates is missing or invalid
The error occurs while deleting sharepoint list record. The sharepoint list does not have any required column.
Following is the code:
string batchCommand = "<Batch OnError='Continue'><Method ID='1' Cmd='Delete'>";
batchCommand += string.Concat("<Field Name='CrfiId'>", rowId);
batchCommand += "</Field></Method></Batch>";
XmlElement batchElement = xmlDoc.CreateElement("batchElement");
batchElement.InnerXml = batchCommand;
lock (_lock)
{
xmlReturn = client.UpdateListItems(listName, batchElement);
}
Any idea why is this error occurring?
Use ID instead of CrfiID.. You need to filter by the built-in id field, it won't work with user created fields.
You need to specify your XML as follows;
<Batch OnError="Continue" ListVersion="1">
<Method ID="1" Cmd="Delete">
<Field Name="ID">itemId</Field>
</Method>
</Batch>
Where, for example;
string itemId = 5;

FetchXML doesn't return aggregate column when null values encountered

I have a FetchXML query that reuturns two aggregate columns:
<fetch distinct='false' mapping='logical' aggregate='true'>
<entity name='blocktrade'>
<attribute name='sourceref' alias='trade_count' aggregate='count'/>
<attribute name='allocationtradecount' alias='alloc' aggregate='sum'/>
<attribute name='organisation' alias='org' groupby='true'/>
</entity>
</fetch>
If I restrict the query to return objects that have values in allocationtradecount it works as expected. However, if some objects have null for the allocationtradecount, the column is not returned in the results!
i.e.
(int)((AliasedValue)e["alloc_count"]).Value;
fails. Is this 'expected'? How can I ensure 0 is used when null values are summed?
For this you need to first check whether that record contains any value.
Like shown in following code...
Consider, you want to assign value to int sum.
int sum = e.Attributes.Contains("alloc") ? (int)((AliasedValue)e["alloc"]).Value : 0;
Above code first check whether record contains any value if yes it will return sum else it will return 0.
Hope this helps.

Resources