Sep 27, 2012

Read Selected Guids from Subgrid

Through the article I posted about a custom recalculation button, I explained the way of introducing a custom buttons to the ribbon. Check it here.

When it comes to the subrid, most important requirement is to read the selected Ids. We will see how we pass those in to a Java script through the custom button.

This is the simple way we need to pass selected Ids as a parameter for the calling method. (Read the previous article if you need entire entry for custom button)

....
<Actions>
<JavaScriptFunction 
  Library="$webresource:new_createquote.js" 
  FunctionName="CreateQuote">
<CrmParameter Value="SelectedControlSelectedItemIds"></CrmParameter>
</JavaScriptFunction>
</Actions>
....

Will see how those Ids are grasped from the method.

function CreateQuote(value)
{
    alert(value);
}

Below is the result which shows the selected ids as an array.



Quite simple, yet important.

Note:
There are few more parameter types we can pass to JavaScript methods from ribbon as required. Please check them below;
  • SelectedEntityTypeCode : A number representing the unique type of entity for a record selected in a grid. The Entity type code will vary between deployments.
  • SelectedEntityTypeName : A string representing the unique name of the entity for a record selected in a grid.
  • FirstSelectedItemId : Provides one GUID identifier as a string for the first item selected in a grid.
  • SelectedControlSelectedItemCount : The number of selected items in a grid.
  • SelectedControlSelectedItemIds : A string array of GUID Id values for all selected items in a grid.
  • SelectedControlAllItemCount : A string array of GUID Id values for all selected items in a grid.
  • SelectedControlAllItemIds : A string array providing the GUID Id values for all items displayed in a grid.
  • SelectedControlUnselectedItemCount : The number of unselected items in a grid.
  • SelectedControlUnselectedItemIds : A string array of GUID Id values for all unselected items in a grid.
Read more information about CRM CrmParameter type here.

Sep 26, 2012

Execute a Dialog in form events

Dialogs are initially introduced to use through a given button and select one from the list in the resulted pop-up page. I think it could be used to get executed in different form events. Typically, when change a drop down, system can prompt a Dialog to get some responses related to that action which will do some other operation.

We can execute Dialog from any action. Check the method I use for this;

function launchDialog(_dID, _eName, _rId)
{

var sUri = Mscrm.CrmUri.create('/cs/dialog/rundialog.aspx');

window.open(sUri + '?DialogId=' + _dID + '&EntityName=' + _eName + '&ObjectId=' + _rId, null, 'width=615,height=480,resizable=1,status=1,scrollbars=1');

}

We need to pass three parameters here. Check the calling part as below;

    var _workflowid = 'f2057c43-0670-4384-93d4-ac6147611c98';
    var _onjecttype = 'new_insurance';
    var _instanceid = crmForm.ObjectId;

    launchModelDialog(_workflowid, _onjecttype, _instanceid);

Though other two parameters are familiar, not workflow id. Ok now this is the way of obtaining it;
- Import the customization of the Dialog
- Open the customization file
- Search for word “Workflow”

You will see this kind of section which gives you the workflow id.

<Workflows>
<Workflow WorkflowId="{f2057c43-0670-4384-93d4-ac6147611c98}" Name="Insurance Renewal">
....
</Workflow>
</Workflows>

Caution

1) Be careful when deploying the since Guid of the workflow is different in different environments. So you have to change it accordingly.

2) One could feel like using a Dialog for an operation which has nothing to do with individual record (record instance). In such occasions, though it is logical to think not to pass any value for instance id, it is a must to pass one. If you don’t pass, Dialog will not pop-up as expected, but below message will be thrown.


Conceptually, Dialog is always defined against an individual record.

Sep 24, 2012

Using CRM Webservice from custom web page (CRM 2011)

One of the previous posts we illustrated the way of using CRM service in custom page for CRM 4.0. Check it here.

Now we will see how the same task is accomplished in CRM 2011

If we put it in a method;

public static IOrganizationService getService()
{
ClientCredentials _cred = new ClientCredentials();

_cred.Windows.ClientCredential = new NetworkCredential("CRM_ADMIN_01", "F1xit@OR5", "CRMBIZDOMAIN");
string _url = "http://crmbiz:5555/abcltd/XRMServices/2011/Organization.svc";

OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(new Uri(_url), null, _cred, null);

return (IOrganizationService)serviceProxy;
}

Now the calling part;