Sorting on Link Entity’s Attribute in Fetch XML (CRM 2011)


Hi,

We had a requirement where we wanted our resultset to be sorted based on the associated link entity’s attribute.

This is how we need to write our fetch xml query.

Suppose we want to get all the Accounts records and its owner information sorted based on Owner’s Job Title. (Descending)

For this our Fetch XML query be something like this

The result

Bye.

Advertisements

Using Multivalued Parameter in Fetch XML based report in CRM 2011 online.


Hi,

Say for e.g. we want a report that shows all the contacts based on owners selected.

If we create the query using advanced find, our query will look like this

Here we have selected three users for owner.

From the query we get the initial impression that it won’t be possible to use the above Fetch XML in our report as the Value Tag needs to dynamic based on the no. of the owners selected.

However to use it in the report we need to make the following change in the query

Here @Owners Query Parameter will takes its value from a Multivalued Report Parameter.

Hope it helps.

Using BackgroundWorker in a WPF Application


Just sharing a small app that demonstrates the use of BackgroundWorker in WPF.

The app has two list boxes, one act as source of all the Process that needs to be processed and the other list box for the running and completed Processes.

The click of Start button starts the processing of Process.

Clicking on Cancel aborts the thread.

The XAML for the app.


<Window x:Class="BackgroundWorkerSampleApp.MainWindow"
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 Title="MainWindow" Height="324" Width="525" Loaded="Window_Loaded">
 <Grid Height="289">
 <ListBox Height="187" HorizontalAlignment="Left" Margin="20,52,0,0" Name="lstSource" VerticalAlignment="Top" Width="171"
 />
 <Button Content="Start" Height="41" HorizontalAlignment="Left" Margin="212,101,0,0" Name="btnStart" VerticalAlignment="Top" Width="75" Click="btnStart_Click" />
 <Button Content="Cancel" Height="42" HorizontalAlignment="Left" Margin="212,148,0,0" Name="btnCancel" VerticalAlignment="Top" Width="75" ContentStringFormat="Cancel" Click="btnCancel_Click" />
 <ListBox Height="187" HorizontalAlignment="Left" Margin="320,52,0,0" Name="lstDestination" VerticalAlignment="Top" Width="171" />
 <TextBlock Height="25" HorizontalAlignment="Left" Margin="195,252,0,0" Name="txtStatus" Text="" VerticalAlignment="Top" Width="232" />
 </Grid>
</Window>

The code behind for the app.


namespace BackgroundWorkerSampleApp
{
 using System.Collections.ObjectModel;
 using System.ComponentModel;
 using System.Threading;
 using System.Windows;

/// <summary>
 /// Interaction logic for MainWindow.xaml
 /// </summary>
 public partial class MainWindow : Window
 {
 #region Constants and Fields

private readonly BackgroundWorker backgroundWorker;

private readonly ObservableCollection<Process> obcProcess;

private readonly ObservableCollection<Process> obcRunningProcess;

private Thread workerThread;

#endregion

#region Constructors and Destructors

public MainWindow()
 {
 this.InitializeComponent();
 this.obcProcess = new ObservableCollection<Process>();
 this.obcRunningProcess = new ObservableCollection<Process>();
 this.lstSource.ItemsSource = this.obcProcess;
 this.lstDestination.ItemsSource = this.obcRunningProcess;
 this.lstSource.DisplayMemberPath = "ProcessName";
 this.lstDestination.DisplayMemberPath = "ProcessName";

// intialize BackgroundWorker class properties
 this.backgroundWorker = new BackgroundWorker();
 this.backgroundWorker.DoWork += this.backgroundWorker_DoWork;
 this.backgroundWorker.RunWorkerCompleted += this.backgroundWorker_RunWorkerCompleted;
 }

#endregion

#region Methods

/// <summary>
 /// Executes the process.
 /// </summary>
 /// <param name="backgroundWorker">The background worker.</param>
 private void ExecuteProcess(BackgroundWorker backgroundWorker)
 {
 if (this.obcProcess.Count > 0)
 {
 this.obcRunningProcess.Add(this.obcProcess[0]);
 backgroundWorker.RunWorkerAsync(this.obcProcess[0]);
 this.obcProcess.RemoveAt(0);
 }
 }

/// <summary>
 /// Handles the Loaded event of the Window control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
 var proc1 = new Process();
 proc1.ProcessName = "Process 1";

var proc2 = new Process();
 proc2.ProcessName = "Process 2";

var proc3 = new Process();
 proc3.ProcessName = "Process 3";

this.obcProcess.Add(proc1);
 this.obcProcess.Add(proc2);
 this.obcProcess.Add(proc3);
 }

/// <summary>
 /// Handles the DoWork event of the backgroundWorker control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.ComponentModel.DoWorkEventArgs"/> instance containing the event data.</param>
 private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
 {
 this.workerThread = Thread.CurrentThread;
 var process = e.Argument as Process;
 Thread.Sleep(5000);
 process.ProcessName = process.ProcessName + " Processed";
 }

/// <summary>
 /// Handles the RunWorkerCompleted event of the backgroundWorker control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.ComponentModel.RunWorkerCompletedEventArgs"/> instance containing the event data.</param>
 private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
 if (e.Error != null)
 {
 MessageBox.Show(e.Error.Message);
 }
 else if (e.Cancelled)
 {
 MessageBox.Show("Cancelled");
 }
 else
 {
 if (this.obcProcess.Count > 0)
 {
 this.obcRunningProcess.Add(this.obcProcess[0]);
 this.backgroundWorker.RunWorkerAsync(this.obcProcess[0]);
 this.obcProcess.RemoveAt(0);
 }
 else
 {
 this.txtStatus.Text = "Processing Completed";
 }
 }
 }

/// <summary>
 /// Handles the Click event of the btnCancel control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
 private void btnCancel_Click(object sender, RoutedEventArgs e)
 {
 this.workerThread.Abort();
 this.txtStatus.Text = "Processing Aborted";
 }

/// <summary>
 /// Handles the Click event of the btnStart control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
 private void btnStart_Click(object sender, RoutedEventArgs e)
 {
 this.ExecuteProcess(this.backgroundWorker);
 }

#endregion
 }
}

Hope it helps.

CRM 2011 Online Fetch XML based SSRS Report and the In condition.


Hi,

Suppose I have a simple Fetch XML based report that shows all the contact’s Full name and their Email Id.

The query for it

Now let us add a like condition to it. (i.e. get all the contacts where fullname like)

The full name parameter will appear in the report.

Now comes the tricky part.

Suppose we have to find all the contact records based on the owners selected.

For owners we will have drop down field in the report.

The fetch xml query would look like below (if we specify two owners)

But here the issue is that value (tag) part would be dynamic, it has to be equal to the values selected by user in the drop down owner parameter of the report. It seems that we can’t dynamically change the Fetch Xml query in runtime for the report.

So the “In” operator won’t be of much use in case of fetch xml based report.

One way we can overcome this issue is by using Default filters.

Here users will have option of editing the filter and specifying the values for the owner which would be then passed down to the report.

This is one way I can think of getting the multiselect thing working in Fetch XML based report.

Please share and suggest your ideas for the same.

Update :-

The multivalue can be passed in the following comma separated way, so we can make use of Multiselect Report Parameter here.


<fetch mapping="logical" count="50" version="1.0">
 <entity name="contact">
 <filter>
 <condition attribute="ownerid" operator="in">
 <strong><value>48379161-2782-e111-b0d1-78e3b5178a51,48379161-2782-e111-b0d1-78e3b5178a52,A81F00C-D4E4-E011-B58C-00155D2A49C7</value></strong>
 </condition>
 </filter>
 </entity>
</fetch>

The fetch XML will have condition in the following format

<condition attribute=”ownerid” operator=”in” value=”@ActivityOwner”>

Bye.

A very helpful post on SSRS


Hi,

I have come across this post many times while developing reports in SSRS.

So just thought of sharing the link

http://www.ssw.com.au/Ssw/Standards/Rules/RulesToBetterSQLReportingServices.aspx

Bye.

 

DateTime Parameter Issue in SSRS (The date/time format is not valid)


Hi,

In one of our SSRS Report we had 2 Report Parameters, one for “From Date” and other for “To Date”.

On selecting values for them through calendar control, the value was being displayed in the proper format (mm/dd/yyyy). However the value being passed to the query was in the format (dd-mm-yyyy), because of which we were getting “The date/time format is not valid” error.

The following was the regional setting in the server.

We changed it to English (United States)

We tried running the report, but we again got the same issue.

Next we tried by changing the Language Settings of Internet Explorer.

This also didn’t solve the issue.

Finally thought of restarting the server, in case if the settings might not have got reflected properly.

After restarting the system, again tried running the report and it ran successfully J

Hope it helps.

Nishant Rana's Weblog

Everything related to Microsoft .NET Technology

Skip to content ↓