FetchXML nvarchar returns nothing - Custom Report for CRM - sql

I am trying to get data from Dynamics CRM 2013 for a custom report using FetchXML.
I "converted" the following SQL Query to FetchXML using this page: http://www.sql2fetchxml.com/
SQL:
SELECT
accountidname,
billto_line1,
billto_postalcode,
billto_city,
invoicenumber,
name,
description
FROM FilteredInvoice
WHERE invoiceid = #invoiceid
FetchXML:
<fetch mapping="logical">
<entity name="invoice">
<attribute name="accountidname" />
<attribute name="billto_line1" />
<attribute name="billto_postalcode" />
<attribute name="billto_city" />
<attribute name="invoicenumber" />
<attribute name="name" />
<attribute name="description" />
<filter>
<condition attribute="invoiceid" operator="eq" value="#invoiceid" />
</filter>
</entity>
</fetch>
Both, "accountidname" and (e.g.) "billto_line1" are NVARCHAR(4000) and both contain data, but if I try to execute the query (e.g. in the "Query Designer" in Visual Studio) only the data of "billto_line1" is shown, not the data of "accountidname".
Since both fields "accountidname" and "billto_line1" are of the same type (nvarchar(4000)) and contain information in the database (I checked it with the "Microsoft SQL Server Management Studio") I am wondering why I can only receive the information from one of those two.
This has happend with many different fields of the type NVARCHAR - some are displayed correctly, while some are not - and I have no idea why.
I would be very pleased if somebody could give me a hint :)
Thank you

accountidname is on the Views, not the actual tables, in SQL. It is not a field on the invoice entity and therefore will not return any information in a FetchXml request.
You should be able to retrieve the Account's name by using accountid - I don't remember in SSRS how the Name property of an EntityReference is surfaced but it should be available.
The FetchXml converter is good at converting SQL SELECT's to FetchXml format and converting joins. It will not validate that the SQL fields are available in FetchXml - that could only be done by accessing the metadata of the CRM Org.

Related

CRM Api FetchXml replaces characters when using like

I'm trying to call CRM Api to fetch contacts. The requirement says I can search by name using the LIKE operator.
I'm using the fetchxml below to query CRM:
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
<entity name="contact">
<attribute name="fullname" />
<filter type="and">
<condition attribute="statecode" operator="eq" value="0" />
</filter>
<filter type="and">
<condition attribute="fullname" operator="like" value="%ben%" />
</filter>
</entity>
</fetch>
The problem is: If I try with "test" for example, it works fine. But if I try to search for "ben" it doesn't. I believe the issue is related to encoding but I can't find a way to fix it. Any ideas?
Seems like encoding error in your code. Try to pass your encoded fetchxml query in the below url & test in the browser address bar. If it results the expected record(s) then it’s not platform problem.
https://<yourorg>.crm.dynamics.com/api/data/v8.2/contacts?fetchXml=encodedFetchXML
To use FetchXml, we need to format FetchXml in usable Web API service
endpoint format. We do this by storing the FetchXML in a variable and
encoding the string with the encodeURI function native to JavaScript as
below.
var encodedFetchXml = encodeURI(fetchContact);
Read more
Update:
I tested this. Both the below fetch filter worked & gave me the expected contact record in browser test.
<condition attribute="lastname" operator="like" value="%thiy%" />
<condition%20attribute="lastname"%20operator="like"%20value=%27%25thiy%25%27%20/>
Edit:
We faced this issue in our Production application today when users trying to search for %bernhard%, but we are handling in code with value="%%bbbernhard%" as a workaround.

case statement inside of fetchxml script

Please note that although this question is an entirely different question, it relates directly to this question.
The following is the script that returns the dataset for my SSRS chart:
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false" aggregate="true">
<entity name="account">
<attribute name="bio_employeesworldwide" alias="TotalWorldWideEmployees" aggregate="sum" />
<filter>
<condition attribute="customertypecode" operator="eq" value="2" />
</filter>
<link-entity name="contact" from="parentcustomerid" to="accountid" alias="contact">
<attribute name="bio_webuseraccountstatus" alias="count_bio_webuseraccountstatus" aggregate="countcolumn" />
<attribute name="bio_webuseraccountstatus" alias="bio_webuseraccountstatusgroupby" groupby="true" />
</link-entity>
</entity>
</fetch>
The values for bio_webuseraccountstatus can be Active, Inactive, Disabled, Pending, etc..
In FetchXML is there a way to do a case statement where you "InActive" for every value that is not equal to "Active" ?
As you can see I've been trying to solve this issue within the reporting layer, but am experiencing lots of "string format" issues.
Can this be done with the dataset layer (fetchxml) instead?
According to this Microsoft forum post:
There's no equivalent function in FetchXml. Instead, you will need to return each field value, and process the CASE logic in the calling code. If this FetchXml is to be used in a report, then you may be able to implement the CASE logic in a calculated field on the report.
You can always parse the output of the fetchxml on return.
So rather than pushing to the screen, report, or db, the original record field of isreceivetravelalerts, you check the status (zero or one) and rewrite it, and add the new variable to your output. Clunky, but useful.
if ($record->isreceivetravelalerts == 1)
{
$travel_alerts = "Active";
}
$travel_alerts = "Inactive";

Extracting sql from SSRS Reports

I am trying to extract the sql from all my SSRS reports so I can see what database tables and columsn are used . Does anyone know how to do this if you have 50 reports ? Is there any exsiting functionality I have overlooked that does this ?
The RDL files are simple XML files. You could create a simple parser that extracts the information you want. If you don't have access to the RDL files right now, you can download them through the SSRS web interface.
Here's an excerpt of the relevant part of an RDL file:
<DataSets>
<DataSet Name="Test">
<Fields>
<Field Name="Testfield">
<DataField>Testfield</DataField>
<rd:TypeName>System.DateTime</rd:TypeName>
</Field>
</Fields>
<Query>
<DataSourceName>MyDataSource</DataSourceName>
<CommandType>StoredProcedure</CommandType>
<CommandText>spMyGreatStoredProcedure</CommandText>
<QueryParameters>
<QueryParameter Name="#param1">
<Value>=Parameters!Param1.Value</Value>
</QueryParameter>
<QueryParameter Name="#param2">
<Value>=Parameters!Param2.Value</Value>
</QueryParameter>
<rd:UseGenericDesigner>true</rd:UseGenericDesigner>
</Query>
</DataSet>
</DataSets>
There are one or more DataSet blocks, which define one data set of the report. First, all the fields are defined and then the query with its parameters.

SSRS can't use "Required Attendees" in dataset?

I am creating report in SSRS for CRM. I have a table with Dataset for Appointment info and I noticed that it does not allow me to report on required attendees??? Is this true? If so is there a workaround around this? I basically want my report to show appointments details and of course who participated.
Any advice is much appreciated!
Below is the fetchXML I gathered from using Advanced Find in CRM 2013.
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
<entity name="appointment">
<attribute name="subject"/>
<attribute name="statecode"/>
<attribute name="scheduledstart"/>
<attribute name="activityid"/>
<attribute name="instancetypecode"/>
**<attribute name="requiredattendees"/>**
<order attribute="subject" descending="false"/>
<link-entity name="account" from="accountid" to="regardingobjectid" alias="ae">
<filter type="and">
<condition attribute="accountid" operator="eq" value="#name"/>
</filter>
</link-entity>
</entity>
</fetch>
To get this information you will have to create another one datasource and retrieve information from ActivityParty entity. All items like requiredattendees, optionalattendees in appointment, from, to, cc, bcc in email, e.t.c. are stored inside ActivityParty entity.

In VersionOne REST API how does one use multiple “with” statements with multiple “Where” clauses?

With the following query:
Base-URL/rest-1.v1/Data/Epic?sel=Category.Name,Custom_RoadmapInOut&where=Number=$numbers&with=$numbers=E-05322%2CE-05280%2CE-05616%2CE-04942%2CE-04921
I am getting the following response:
<Assets total="5" pageSize="2147483647" pageStart="0">
<Asset href="End-of-Base-URL/rest-1.v1/Data/Epic/138904" id="Epic:138904">
<Attribute name="Category.Name">Business Objective</Attribute>
<Attribute name="Custom_RoadmapInOut">2</Attribute>
</Asset>
<Asset href="End-of-Base-URL/rest-1.v1/Data/Epic/139078" id="Epic:139078">
<Attribute name="Category.Name">Initiative</Attribute>
<Attribute name="Custom_RoadmapInOut">1</Attribute>
</Asset>
<Asset href="End-of-Base-URL/rest-1.v1/Data/Epic/147147" id="Epic:147147">
<Attribute name="Category.Name">Parent Story</Attribute>
<Attribute name="Custom_RoadmapInOut"/>
</Asset>
<Asset href="End-of-Base-URL/rest-1.v1/Data/Epic/148702" id="Epic:148702">
<Attribute name="Category.Name">Parent Story</Attribute>
<Attribute name="Custom_RoadmapInOut"/>
</Asset>
<Asset href="End-of-Base-URL/rest-1.v1/Data/Epic/156961" id="Epic:156961">
<Attribute name="Category.Name">Milestone</Attribute>
<Attribute name="Custom_RoadmapInOut"/>
</Asset>
</Assets>
I want to limit the results to only return those assets that have a "Category.Name" of either "Business Objective" or "Initiative" and from those types to only return the ones that have a "Custom_RoadmapInOut" set to between 1 and 99.
What do I need to add to the query to have VersionOne do the heavy lifting and return only the desired items?
I am thinking I should be able to also add:
Category.Names=$names&with=$names=Business+Objective%2CInitiative
to the query and another where part to check the Custom_RoadmapInOut but I am not sure how to do this.
Currently I am making multiple queries and then using my own code to go through the results and keep only the ones that I desire to see.
Thanks for any help that can be provided.
Doug
Multiple with values can be separated by | (pipe). If you need more details than are shown in the documentation, you can try reading the grammar.
Multiple where filter tokens must be joined by logical operators. Logical and is ; (semicolon). Logical or is | (pipe). Again, the documentation can be a little sparse so you might try reading the grammar.
If you still find yourself still needing to run multiple queries to get what you need, you may find it advantageous to convert to the query.v1 endpoint.