Featured Post

Web API Requests Series

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

13 April 2012

How to assign a record to another User in CRM 2011

In this brief post I will show you how to set the Owner of a record in C#, in other words how to assign a record to a User.

To assign a record an Owner you have to send an Assign Request using the Execute method.


service.Execute(new AssignRequest()
                                                    {
                                                        Assignee = new EntityReference("systemuser", userId),
                                                        Target = new EntityReference(updateEntity, recordId)
                                                    }
                );

The Assign  Request has two properties:

  1. Assignee: This can be either a Team or a User.
  2. Target: this is the record you want to assign.

Hope this helps.

03 April 2012

Open CRM form via JavaScript

Have you been struggling to find out how to open a CRM form from another form or from a custom page?

Here is the solution:

Use window.open("/main.aspx?etn=entityname&pagetype=entityrecord&id=" + recordGUID");

or simply:
 window.open("/main.aspx?etn=entityname&pagetype=entityrecord");

to create a new record.

You can also pass custom parameters using the extraqs parameter and encodeURIComponent. You can find out more from the Crm SDK.

Cheers.

25 March 2012

Read only fields are not saved.

If you are writing your custom web resource and using it to update standard crm fileds, rememember that they will not be saved if they are read-only.
Let me make myself clear with an example.
I was developing an HTML web resource and I was changing the value of a field only shown on the footer. In order to be able to change the value of that field I had to place it on the form as well and hide it. This means that I set, from the form designer, the following properties:
  1. Visible by default = false
  2. Field is read-only = true
If you do this you will be able to access the read-only field but when you save the form that field will not be saved because is read-only.
So what you should do is: Hide the field on the form but don't set the field to be read-only as shown below.















If it is a bug or it is normal, I don't know. If someone knows the reason of this behavior please let me know.
Thank you.

19 March 2012

How to pass parameters from subgrids to JavaScript

In this post I will show you how to pass parameters regarding a grid or subgrid to a JavaScript function by clicking a custom button on the ribbon menu.
A common requirement is to pass poarameters to a JavaScript function called when clicking a Ribbon button.
To pass parameters regarding a grid or a subgrid we can use the "crmparameter" element of the RibbonDiffXml file.
The available parameters can be devided in three groups:

  1. Selected items 
    • SelectedControlSelectedItemCount: The number of selected items in a grid or subgrid.
    • SelectedControlSelectedItemIds: A string array of GUID Id values for all selected items in a grid.
    • SelectedControlSelectedItemReferences: An array of EntityReference objects that represent all the selected items in the grid
  2. All items
    • SelectedControlAllItemCount: The number of items in a grid or subgrid.
    • SelectedControlAllItemIds: A string array of GUID Id values for all items in a grid.
    • SelectedControlAllItemReferences: An array of EntityReference objects that represent all the items in the grid.
  3.  Unselected items
    • SelectedControlUnselectedItemCount: The number of unselected items in a grid or subgrid.
    • SelectedControlUnselectedItemIds: A string array of GUID Id values for all unselected items in a grid.
    • SelectedControlUnselectedItemReferences: An array of EntityReference objects that represent all the unselected items in the grid. 
The way you can pass these parameters by clicking a Ribbon button is shown below:

  <CommandDefinition Id="Mscrm.SubGrid.opportunity.Command">
            <EnableRules>
              <EnableRule Id="Mscrm.SubGrid.opportunity.EnableRule"></EnableRule>
            </EnableRules>
            <DisplayRules></DisplayRules>
            <Actions>
              <JavaScriptFunction Library="$webresource:functions.js" FunctionName="MyFunction" >
                <CrmParameter Value="SelectedControlSelectedItemIds" />
                <CrmParameter Value="SelectedControlSelectedItemCount" />
              </JavaScriptFunction>
            </Actions>
</CommandDefinition>

To access these parameters add them to your function definition like below:

function MyFunction(SelectedControlSelectedItemIds, SelectedControlSelectedItemCount) {
      for (i = 0; i < SelectedControlSelectedItemCount; i++) {
       }
}


So as you can see it is possible to access records displayed in a subgrid using supported code, so don't get tempted to use document.getElementById.  ;)

I hope this help.



14 March 2012

ITSM SEMINAR

Using an ITIL accredited ITSM suite can dramatically improve your operations by:
•Enabling users to log and track their own incidents, change requests and service requests
•Automating SLA adherence, workflows and assignments
•Root cause analysis with deep insight from powerful reporting tools
•Increase end user satisfaction with timely actions and accurate information

During this seminar you will learn how to achieve all of the above and more. Our ITSM enables you to leverage your exisiting environment and maximise effectiveness. We look forward to seeing you in two weeks!!

Register here: http://www.alfapeople.com/UK/EN/Events/Pages/Events.aspx