Search This Blog

Sunday, November 22, 2015

Display/Show CRM default Lookup(Lookup more records) window using Javascript

Display/Show CRM default Lookup(Lookup more records) window using Javascript

If you have any doubt in the post please post comments. I will try to solve your problem.

With the help of java-script we can display CRM lookup more records form for any entity .


URL:/_controls/lookup/lookupinfo.aspx?paremeter
Parameter:
&DefaultType=ObjectTypeCode
&DefaultViewId= ViewId
&DisableQuickFind=0(Do you want quick find enable or not disable) Enable=1 Disable=0
&DisableViewPicker=0(Do you want quick view picker enable or not disable)
&IsInlineMultiLookup=0
&LookupStyle=Lookup Style(single)
&ShowNewButton=1 (Do you want new button enable or not disable)
&ShowPropButton=1 (Do you want prop button enable or not disable)
&dType=1
&mrsh=false
&objecttypes=ObjectTypeCode
&search=Searchstring 

Example:
    var strSearch = Xrm.Page.getAttribute('shipto_postalcode').getValue();
        var strURL = "_controls/lookup/lookupinfo.aspx?AllowFilterOff=0&DefaultType=10161&DefaultViewId=%7b141FCA27-5F72-E511-9418-0050568107AE%7d&DisableQuickFind=0&DisableViewPicker=0&IsInlineMultiLookup=0&LookupStyle=single&ShowNewButton=0&ShowPropButton=1&dType=1&mrsh=false&objecttypes=10161&search=";
        strURL += strSearch;
        var oUrl = Mscrm.CrmUri.create(strURL);

        var dialogwindow = new Mscrm.CrmDialog(oUrl, window, 500, 600);

        //use setCallbackReference method to call some handler once dialog is closed
        //to result variable would be returned result of dialog call
        dialogwindow.setCallbackReference(function(result) {
       
        });

        //call this method to show dialog

        dialogwindow.show();

Filter types in CRM lookup window:

  • Filter a single column in the lookup window
  • Filter  multiple column in the lookup window

1) Filter a single columns( where country='usa') in the lookup window grid.

Solution:
It  is possible in both     CRM On-Premises and On-line.The value can be set both dynamically and static value.
    Static:
       Customization->Entity->views->Add filter in that form. Call that form in javascript.
    Dynamic:
        Pass the filter value in the "lookupinfo,aspx" query string with key name search.

2) Filter multi-column( where country='usa' and state='ny')  in the lookup window grid

Solutions:
The value can be set both dynamically and static in CRM On-Premises but in CRM online the only static value can be possible,because we can't able to access server page in CRM online.
  Static:
       Customization->Entity->views->Add filter in that form. Call that form in javascript.
  Dynamic:
      To copy the lookupSingle.aspx (C:\Program Files\Microsoft Dynamics CRM\CRMWeb\_controls\lookup\lookupSingle.aspx) form in server  and create a new aspx form in server. When you call this form in javascript pass your own parameter in the query string. In the aspx form you get that value and add filter in the fetch xml and load the grid.


Publish and Publish All message in CRM plugin


Before that please check my PreviousPost other messages

How context input parameter value differ in each message in CRM plugin

If you have any doubt in the post please post comments. I will try to solve your problem.

Message name:
PublishAllCustomization:

  • There is no value in the input parameter wherever you click publishAllCustomization.

Publish:

  • When you publish from "webresource" form the webresourceId value came in input parameter property of context in  plugin.
  • When you publish from "entity form" form the entity name value came in input parameter property of context in  plugin.


Get Entity type Code in CRM plugin code

If you have any doubt in the post please post comments. I will try to solve your problem.

In CRM each entity has separate object/entity type code. You can also get entity/object type code through plugin.          

Plugin Code:
 RetrieveEntityRequest request = new RetrieveEntityRequest();
 request.LogicalName = entity name;

// Retrieve the MetaData.
RetrieveEntityResponse response = (RetrieveEntityResponse)service.Execute(request);
int iEntityTypecode = response.EntityMetadata.ObjectTypeCode.Value;



Hide view in CRM

If you have any doubt in the post please post comments. I will try to solve your problem.

Some times we would need hide some view based on the roles. The below i have simply hide the view by the name starts with "my".

Plugin Code:
if (context.InputParameters.Contains("Query") && context.InputParameters["Query"] is QueryExpression)
                   {
                       QueryExpression qe = (QueryExpression)context.InputParameters["Query"];
                       if (qe.EntityName == "savedquery")
                       {
                           if (qe.Criteria != null)
                           {
                               if (qe.Criteria.Conditions != null)
                               {
//Custom logic can also apply
                                   /*The query is edited to look at views not starting with "my" at the begining of the View Name*/
                                   ConditionExpression queryCondition = new ConditionExpression("name", ConditionOperator.NotLike, "my%");
                                   qe.Criteria.Conditions.Add(queryCondition);
                               }
                           }
                       }
                   }
Plugin Configuration:
Meggage:  RetrieveMultiple
Primary Entity: savequery
Eventing Pipline: Pre-validation


Hide view based on Roles:
  • In custom logic code mention in the plugin area.
  • Get the role name based on the current logged in user
  • Form the list of roles that user have to display the view
  • Check if the user has able to display the view or not based on list
  • If not then filter with view name not to display 


Saturday, November 14, 2015

When Lookup control get disabled in CRM

In general, lookup control will be disabled if one of the following conditions is true:

If you have any doubt in the post please post comments. I will try to solve your problem.
  • Field is protected by the Field level security and user does not have create or update privilege when creating or updating the record
  • User does not have Append privilege for the child entity (the one being edited)
  • User does not have Append To privilege for the parent entity (the one being looked up)

Which event fire first Plugin or Workflow

Which event fire first Plugin or Workflow

If you have any doubt in the post please post comments. I will try to solve your problem.

Let us see which event fir first plugin or workflow

We have created a new workflow and configure the workflow  as trigger at the time of new_name of testentity get change and update the same entity.

We also develop the plugin for the same testentity and configure the plugin as trigger at the time of new_name(with the help of filter attribute feature in plugin we can set the plugin to fire only particular attribute/column get fired) of  testentity get change.

Plugin configure as "pre-validation" and  Work-flow configure as Synchronous:

  • Plugin
  • Workflow

Plugin configure as "per-operation" and  Work-flow configure as Synchronous:

  • Plugin
  • Workflow
Post operation:
In plugin, we have to remove the attribute of new_name and update the testentity, otherwise 
infinite loop exception occur because we have  trigger the plugin at the time of new_name changed. In plugin if the new_name   updated in the database  even though new_name not change in the code. Thats while we remove attribute in the entity in plugin code.


Plugin configure as "post-operation with Synchronous"  and  Work-flow configure as Synchronous(new_name remove):

  • Workflow
  • Plugin

Plugin configure as "post-operation with Asynchronous"  and  Work-flow configure as Synchronous(new_name remove):

  • Workflow
  • Plugin

Plugin configure as "post-operation with Asynchronous"  and  Work-flow configure as  Asynchronous(new_name remove):

  • Plugin
  • Workflow

Plugin configure as "post-operation with synchronous"  and  Work-flow configure as  Asynchronous(new_name remove):

  • Plugin
  • Workflow is not triggered



Thursday, November 12, 2015

Check whether control value is changed or not in CRM

getDirty in CRM

If you have any doubt in the post please post comments. I will try to solve your problem.

It is one of the method in Xrm.Page.getAttribute. This method is used to check whether control value is changed from previous value.

Syntax:
Xrm.Page.getAttribute(control schema name).getIsDirty();

Control value    Status
Changed            true
Not Changed     false

Note:
The value in the control is India and it changed to Indian without saving the entity if you again change the value to India then getDirty returns false. Because the value in the control is not changed from previous value