Featured Post

Web API Requests Series

Web API Series:  Create and Retrieve , Update and Delete , Retrieve Multiple , Associate/Disassociate , Impersonation , Run Workflows

03 March 2012

Crm 2011 Survey Creator Beta

The Crm 2011 Survey Creator is a CRM solution that allows us to create Surveys in CRM 2011.
A survey can be created in different ways, for example:
  1. From the Contact form
  2. From the Account form
  3. From the Main Page Navigation Pane
A survey consists of the following parts/entities:
  1. Survey Template
  2. Questions Group
  3. Question
  4. Survey
 To create a Survey we first need to create a Survey Template, add Questions Groups to the Template, add Questions to the Group and then we are ready to create our Survey/questionnaire.


1. Create a Survey Template  


















2. Add Questions Groups to the Survey






















We can specify an order number, this will tell in what order to display the question group in the Survey.

3. Add Questions to the Group/s




















4. Here we can specify the question name, if an answer is required or not, the order in which the Question will appear in the Question Group in the Survey, and the type of answer we expect:
  1. Text
  2. Number
  3. Decimal
  4. Date
  5. Yes or No
  6. Picklist/Dropdown
Once we are done with the Template, Groups and Questions we are ready to create a Survey based on the template we created.



















Fill the required fields (the Performed On date will automatically filled in and is read-only) and then save the Survey, when the survey form reloads it will come up with the questions on the form, see below.

Part 1



















Here we can see Text fields, Ye/No and Dropdown.

Part 2














Here we can see a required field in red and Number fields. We also have a little help that says what is the type of the filed. However, Validation on the fields is implemented on the Survey Form. See below for the validation messages:

Validation on Number Fields










Validation on Date Fields










The date separator is based on your CRM customisation so if you enter an "invalid" date you'll be prompted with an error.

Validation on Decimal Fields







Validation on Required Fields








Finally if we try to save a Survey without filling require field we will not be able to save the survey and the user will be prompted with the above message.
One more thing, the survey can be marked as complete by clicking the Custom button "Save as Complete". If we do this the next time we open the survey, all the fields will be disabled and the Survey status at the bottom will say "Completed".

Survey Complete








This is all for today, hope you find this post useful.

11 January 2012

How to retrieve all the activities for a record

In this post I will show how to retrieve all the activities in which a record is related to as:
  1. BBC Recipient
  2. CC Recipient
  3. Customer Optional Attendee
  4. Organizer
  5. Owner
  6. Regarding
  7. Required attendee
  8. Resource
  9. Sender
  10. To Recipient
It is also possible, of course, to select only few of them. To achieve this I will use a fetch XML query.
Here is  the query:

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
  <entity name="activitypointer">
    <attribute name="activitytypecode" />
    <attribute name="subject" />
    <attribute name="statecode" />
    <attribute name="prioritycode" />
    <attribute name="modifiedon" />
    <attribute name="activityid" />
    <attribute name="instancetypecode" />
    <order attribute="modifiedon" descending="false" />
    <link-entity name="activityparty" from="activityid" to="activityid" alias="aa">
      <filter type="and">
        <condition attribute="participationtypemask" operator="in">
          <value>4</value>
          <value>3</value>
          <value>11</value>
          <value>6</value>
          <value>7</value>
          <value>9</value>
          <value>8</value>
          <value>5</value>
          <value>10</value>
          <value>1</value>
          <value>2</value>
        </condition>
        <condition attribute="partyid" operator="eq" uitype="contact" value="Xrm.Page.data.entity.getId()" />
      </filter>
    </link-entity>
  </entity>
</fetch>

The corresponding advanced find query is:









Hope this helps,

Luciano.

20 October 2011

13 September 2011

Interact with CRM form objects from Silverlight through the HTML Bridge

In this post I will show you how we can access attributes on the form via Silverlight managed code.

When you host a Silverlight application in a HTML page you can access the HTML Document Object Model (DOM) from the managed code, and call managed code from JavaScript. This is possible using the HTML Bridge technology available in Silverlight.
In the same way you can access the xrm objects on a Dynamics Crm form using managed code and vice versa when a Silverlight application is embedded in a Crm form.
In this post I will show you a simple example of how to do this.

Recipe for this example:
  • I will create a simple Silverlight application
  • Create a Silverlight web resource
  • Add the web resource to a Crm form
  • Verify
The Silverlight application consists of a Textbox and a Button as shown below:

<StackPanel Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Stretch">
            <TextBox x:Name="InputText" Width="200" Height="23"/>
            <Button Content="Go" Width="22" Height="20" Click="Button_Click" Margin="4,0,0,0"/>
</StackPanel>

After having created the Silverlight application let's add the following code to the Button_Click  event handler:

add this a reference to the "System.Windows.Browser" to your Silverlight project and the using statement in order to be able to use the HTML Bridge,

using System.Windows.Browser;

private void Button_Click(object sender, RoutedEventArgs e)
        {
            //Get the xrm object using the dynamic type
            dynamic xrm = (ScriptObject)HtmlPage.Window.GetProperty("Xrm");
            //this is the number of employees attribute
            var numEmployees = xrm.Page.data.entity.attributes.get("numberofemployees");

            try
            {
               
                if (!string.IsNullOrEmpty(InputText.Text))
                {
                    //convert to int the input from SL text box
                    var employees = Convert.ToInt32(InputText.Text);

                    //set the attribute on the Crm form
                    numEmployees.setValue(employees);
                }
                else
                {
                    //set the attribute on the form
                    numEmployees.setValue(null);
                }
            }
            catch(System.FormatException fe)
            {
                HtmlPage.Window.Alert(string.Format("{0}", fe.Message));
            }
            catch(System.OverflowException ofe)
            {
                HtmlPage.Window.Alert(string.Format("{0}" , ofe.Message));
            }
        }

After having added the Silverlight web resource (see this post) we can now embed it in a form (the account form in this example), thje result is shown below:







To test the application enter a value into the textbox and enter "Go", you should see the number of employee populated with the value you have inserted in alternative you can leave the text box empty.
If you try to enter a value that is too large, too small or is not a number an exception will be thrown and a message will be displayed (see below) . Note that the messages are once again shown using the HTML Bridge through the following lines of code:

HtmlPage.Window.Alert(string.Format("{0}", fe.Message));
HtmlPage.Window.Alert(string.Format("{0}" , ofe.Message));


Alternatively we could have used a Silverlight Child window or simple MessageBox.Show("")

Well that's all really! Next time we will see how to call a Silverlight method from Crm form.

Stay tuned.

Luciano.




02 September 2011