Look Up Filtering Using addCustomFilter

Filtered LookUp  Using addCustomFilter By Javascript:-

Contact entity has the lookup of account entity. The Account lookup must show the related Email Accounts based on the email of contact entity. Before entering the email value on contact entity, It will show all the accounts and once if he entered the email it has to show the only related email accounts.

Trigger the following function EmailPreFilterLookup()  on ONLOAD of form.

addPreSearch method will trigger when we click on the Account LookupFiled Icon 45

 

function EmailPreFilterLookup() {
 Xrm.Page.getControl("parentaccountid").addPreSearch(function () {
 addLookupFilter();
 });
}
function addLookupFilter() {
debugger;
 var email = Xrm.Page.getAttribute("emailaddress1").getValue();
 if (email != null) {
 fetchXml = "<filter type='and'><condition attribute='emailaddress1' operator='eq' value='" + email + "' /></filter>";
 Xrm.Page.getControl("parentaccountid").addCustomFilter(fetchXml);
 }
}

 

Enjoy 🙂

Advertisements

Dependent Picklist / OptionSet in CRM 2016

Dependent Picklist / OptionSet in CRM 2016

In a recent scenario, I was asked to create a dependent Pick-list/ Option set list where the options of Second Pick-list are dependent on the Value of the First one. By default there is no such option in Dynamics CRM but I came up with a solution from SDK.

I’m going to share the steps in detail for the solution here :-

Step1-

Create a Webresource of type Jscript  with name “SDK.DependentOptionSet.js” and upload the JScript file from SDK -> SsmpleCode -> JS -> FormScripts -> SDK.DependentOptionSet.js

By default it is available in CRM SDK.

1.JPG

Step2:-

Create Another Web resource of type XML with name- “new_dependentoptionsetxml

3.JPG

Step 3:-

Modify the XML based upon your options from Parent optionSet and Dependent optionSet

In my case the XML is like the following:-

<!---->
<!--<snippetTicketDependentOptionSetConfig.xml>-->
<DependentOptionSetConfig enity = "account">
<ParentField id = "new_category" label="Category">
<DependentField id="new_subcategory" label="Sub Category" />
    <Option value="1" label="Gold">
        <ShowOption value="1" label="gold1" />
        <ShowOption value="2" label="gold2" />
        <ShowOption value="3" label="gold3" />
        <ShowOption value="4" label="gold4" />
    </Option>
    <Option value="2" label="Silver">
       <ShowOption value="5" label="silver1" />
       <ShowOption value="6" label="silver2" />
       <ShowOption value="7" label="silver3" />
       <ShowOption value="8" label="silver4" />
    </Option>
    <Option value="3" label="Diamond">
       <ShowOption value="9" label="dialmond1" />
       <ShowOption value="10" label="diamond2" />
       <ShowOption value="11" label="dialmond3" />
       <ShowOption value="12" label="diamond4" />
    </Option>
 </ParentField>
 </DependentOptionSetConfig>
 <!--</snippetTicketDependentOptionSetConfig.xml>-->

 
<!---->

Step 4 :-

Attach the Library and add the function on OnLoad event of the Form for the “new_SDK.DependentOptionSet.js” :

Function :-  SDK.DependentOptionSet.init

Parameter :- “new_dependentoptionsetxml (its basically the xml that we created before)

5.JPG

Step 5 :-

Add the function at onChage Event of the First OptionSet / Picklist

Function :- SDK.DependentOptionSet.filterDependentField

Parameter :- “new_category”,”new_subcategory”

6.JPG

Now You’re done. After Publishing all the changes, when you first open the record you’ll get the dependent picklist / OptionSet as ReadOnly.

7

After the selection of the Parent Picklist, the Dependent picklist will show the dependent values.

8.JPG

That’s it Enjoy:-))