Monday, October 8, 2018

Dynamics CRM Native Lookup with filtered view

Introduction

Well, we all know that dynamic CRM supports filtered view in Lookup that are opened from native lookup attribute or lookup control. This can be done by using addCustomFilter and addPreSearch Client APIs that are available. However, this has its own limitations. There is no proper reference or documentation that tells us how we can open a filtered lookup popup window without having attribute placed on the from.

Problem

Dynamics CRM Lookups can be called by constructing the URL and opening the same using Xrm.Internal.openDialog but, this cannot have filter dynamically added. To have a lookup popup from a custom webresource, that will filter default view based on certain criteria set programatically is not possible.

Solution

To solve this problem, I have created a custom method that opens a native lookup popup without any dependency. There is also a callback which can be used to get the record(s) selected by the user on the lookup.
Method needs
  1. Object type code of the entity you are trying to open. In my case it was a custom entity.
  2. Filter XML
  3. Default view Id of the entity.


     function testLookUp()
     {
    var lookupObjectTypeCode = 10011; //entity object type code
    var fetchXml = "<filter type='and'><condition attribute='new_name' operator='like' value='%test%' /></filter>";
    var defViewId = "{325CB2BC-0307-4721-AA52-71F0570DFEF4}"; //your entity viewid

    openlookup(lookupObjectTypeCode, fetchXml, defViewId);
}
function openlookup(otc, filterXml, viewId)
{
   
    var currentObj = new Object();
    currentObj.currentObjectType = window.parent.Xrm.Internal.getEntityCode(window.parent.Xrm.Page.data.entity.getEntityName()).toString();
    currentObj.currentid = window.parent.Xrm.Page.data.entity.getId();

    var lookupObj = new window.parent.Xrm.LookupOptions();
    var arrLookuptype = new Array(1);
    arrLookuptype[0] = window.parent.Xrm.Internal.getEntityName(lookupObjectTypeCode);
    lookupObj.lookupStyle = "single";
    lookupObj.lookupTypes = arrLookuptype;
    lookupObj.defaultViewId = defViewId;
    lookupObj.additionalParams = currentObj;
    lookupObj.customViews = null;
    lookupObj.searchText = "";
    lookupObj.defaultType = lookupObjectTypeCode.toString();
    lookupObj.disableQuickFind = "1";
    lookupObj.showNew = false;
    lookupObj.viewIds =  null;
    lookupObj.disableViewPicker = true;
    lookupObj.filterRelationshipId = "";
    lookupObj.filterRelationshipName = null;
    lookupObj.filterRelationshipType = "";
    lookupObj.filterRelationshipDependantAttribute = null;
    lookupObj.allowFilterOff = false;
    lookupObj.customFilters = new Array(window.parent.CrmEncodeDecode.CrmUrlEncode(fetchXml));
    lookupObj.customFilterTypes = new Array("");
    window.parent.Xrm.Internal.lookupObjects(lookupObj, function (lookupItems) {
        if (lookupItems && lookupItems[0]) {
            alert(lookupItems[0].id + " " + lookupItems[0].name);
        }
    }, null);

}

dynamicsforbusiness.blogspot.com
Image shows filtered lookup from custom code

Disclaimer :
  1. This is just a sample code for educational purpose. Use at your own risk.
  2. Code further needs proper callback handling.
  3. Code is tested in DCRM 2016, need little modification for DCRM 365

13 comments:

  1. Super collection thanks for sharing and keep update. For more information Azure Online Hyderabad.
    Microsoft Dynamics AX Online Training

    ReplyDelete
  2. Here is the investors contact Email details,_ lfdsloans@lemeridianfds.com Or Whatsapp +1 989-394-3740 that helped me with loan of 90,000.00 Euros to startup my business and I'm very grateful,It was really hard on me here trying to make a way as a single mother things hasn't be easy with me but with the help of Le_Meridian put smile on my face as i watch my business growing stronger and expanding as well.
    I know you may surprise why me putting things like this here but i really have to express my gratitude so anyone seeking for financial help or going through hardship with there business or want to startup business project can see to this and have hope of getting out of the hardship..
    Thank You.

    ReplyDelete
  3. I am very grateful to Elegant loan firm for helping me get a $ 600,000 loan with the helping of loan officer Russ Harry, and I will always be grateful. My life has changed, my money has been paid, I now own a business that I used to support my family. I am grateful to you, Mr. Russ, and God bless you. You can contact them for your financial assistance by e-mail: Elegantloanfirm@hotmail.com for your financial assistance.

    ReplyDelete
  4. Hello everyone, I'm Patricia Sherman in Oklahoma USA right now. I would like to share with you my experience of borrowing USD $185,000.00 to clear my bank draft and start a new business. It all started when I lost my house and I took my stuff because of the bank policy and I met some bills and some personal needs. So I became very desperate and started looking for funds in every way. Fortunately for me, a friend of mine, Linda told me about a credit company firm, I was intrigued by the fraud, but I was intrigued by my situation and had no choice but to get advice from my friend about this company. contacting them really doubted me because of my past experience with online lenders, did you know that little? '' Elegantloanfirm@hotmail.com This company has been very helpful to me and my colleague and today, thanks to this credit company, the proud owner of well-organized work and responsibilities, they smiled back at me. So if you really need to grow or start your own business, or if you really need to borrow money in any financial hardship, we recommend you find a financial development opportunity in your business today. {E-mail:} Elegantloanfirm@hotmail.com / whats-app number +393511617486.... online for credit not a victim of scam Thank you.

    ReplyDelete
  5. HOW I GO MY DESIRED LOAN AMOUNT FROM A RELIABLE AND TRUSTED LOAN COMPANY LAST WEEK Email for immediate response: drbenjaminfinance@gmail.com Call/Text: +1(646)820-1981 Whatsapp +19292227023 Visit their website and believe yourself Company Website: https://capitalmanage-inc.com/

    Hello everyone, My name is Mr.Justin Riley Johnson, I am from Texas, United State, am here to testify of how i got my loan from BENJAMIN LOAN INVESTMENTS (drbenjaminfinance@gmail.com) after i applied Two times from various loan lenders who claimed to be lenders right here this forum,i thought their lending where real and i applied but they never gave me loan until a friend of mine introduce me to {Dr.Benjamin Scarlet Owen} the C.E.O of BENJAMIN LOAN INVESTMENTS who promised to help me with a loan of my desire and he really did as he promised without any form of delay, I never thought there are still reliable loan lenders until i met {Dr.Benjamin Scarlet Owen}, who really helped me with my loan and changed my life for the better. I don't know if you are in need of an urgent loan also, So feel free to contact Dr.Benjamin Scarlet Owen on his email address: drbenjaminfinance@gmail.com BENJAMIN LOAN INVESTMENTS holds all of the information about how to obtain money quickly and
    painlessly via Whatsapp +19292227023 Email: drbenjaminfinance@gmail.com

    And consider all your financial problems tackled and solved. Share this to help a soul right now, Thanks
    Visit their website and believe yourself Company Website:https://capitalmanage-inc.com/

    ReplyDelete
  6. I was searching for loan to sort out my bills& debts, then i saw comments about Blank ATM Credit Card that can be hacked to withdraw money from any ATM machines around you . I doubted thus but decided to give it a try by contacting (smithhackingcompanyltd@gmail.com} they responded with their guidelines on how the card works. I was assured that the card can withdraw $5,000 instant per day & was credited with$50,000,000.00 so i requested for one & paid the delivery fee to obtain the card, after 24 hours later, i was shock to see the UPS agent in my resident with a parcel{card} i signed and went back inside and confirmed the card work's after the agent left. This is no doubts because i have the card & has made used of the card. This hackers are USA based hackers set out to help people with financial freedom!! Contact these email if you wants to get rich with this Via: smithhackingcompanyltd@gmail.com or WhatsApp +1(360)6370612

    ReplyDelete
  7. My name is Mr. Klaus Dieter, I work for the French financial institution Crédit Mutuel with the partnership of the bank BNP Paribas, we offer you offers at an interest rate of 3% per year, to start with new projects:
    - You have unpaid debt.
    - Buying a new house.
    - buy a new car.
    - Buying a new apartment or property.
    Get personal loans, business loans.
    If you would like loans for setting up your business and project, do not hesitate to send us an email:
    bnpfinanzenhilfe@gmail.com

    Whatsapp: +4917694954827

    ReplyDelete
  8. I was searching for loan to sort out my bills& debts, then i saw comments about Blank ATM Credit Card that can be hacked to withdraw money from any ATM machines around you . I doubted thus but decided to give it a try by contacting (smithhackingcompanyltd@gmail.com} they responded with their guidelines on how the card works. I was assured that the card can withdraw $5,000 instant per day & was credited with$50,000,000.00 so i requested for one & paid the delivery fee to obtain the card, after 24 hours later, i was shock to see the UPS agent in my resident with a parcel{card} i signed and went back inside and confirmed the card work's after the agent left. This is no doubts because i have the card & has made used of the card. This hackers are USA based hackers set out to help people with financial freedom!! Contact these email if you wants to get rich with this Via: smithhackingcompanyltd@gmail.com or WhatsApp +1(360)6370612

    ReplyDelete
  9. Programmed ATM Cards
    Do you know that you can hack any ATM machine !!!
    We have specially programmed ATMs that can be used to withdraw money at ATMs, shops and points of sale. We sell these cards to all our customers and interested buyers all over the world, the cards have a withdrawal limit every week.
    Getting rich and living the rich and famous lifestyle is a dream of many people. And while most people go to work or look for other ethical methods to make money on ATM-programmed cards.
    The programmed ATMs withdraw money from each ATM but have a withdrawal limit every week, only your PIN code is in it, it is a high-tech card system. The PROGRAMMED ATM card works on all card-based ATMs, anywhere in the world.
    Email: atmservices44@aol.com
    Email: hacklords.investors@gmail.com

    ReplyDelete
  10. I would like to thank Lapo Micro Finance for giving me a loan. I was deceived several times trying to get a loan until I came across Lapo Micro Finance who provided me with a loan worth $ 23,000 to care for my sick child. If you need a real lender today, contact Lapo and don't be fooled.Contact email: lapofunding960@gmail.com
    Whatsapp +447883183014

    ReplyDelete
  11. HAVE YOU BEEN IN SEARCH FOR GENUINE HACKER'S ONLINE?. HAVE YOU LOST YOUR MONEY TO BINARY OPTION SCAM OR ANY ONLINE SCAM WHATSOEVER?. WELL, YOU HAVE FOUND REDEMPTION .

    BLANK ATM CARD :We have specially programmed BLANK ATM CARDS that can be used to hack any ATM machine, these ATM cards can be used to withdraw at the ATM or swipe, stores and outlets. We sell this BLANK CARDS to all our customers and interested buyers worldwide, the BLANK CARDS has a daily withdrawal limit of $5000 in ATM and up to $50,000 spending limit in stores. and also if you are in need of any other cyber hacking services, we are here for you at any time any day. Email :
    Email:Creditcards.atm@gmail.com
    WhatsApp: +1(539) 888-2243

    -hack into any kind of phone
    _Increase Credit Scores
    _western union, bitcoin and money gram hacking
    _criminal records deletion
    _BLANK ATM/CREDIT CARDS
    _Hacking of phones(that of your spouse, boss, friends, and see whatever is being discussed behind your back)
    _Security system hacking...and so much more. Contact THEM now and get whatever you want at
    Email:Creditcards.atm@gmail.com
    WhatsApp: +1(539) 888-2243
    You can also contact us on Telegram.
    ����������✔����������������������������

    ReplyDelete
  12. When I was applying for a loan to purchase my building as a small business owner in a tough situation, conventional banks said they could not help me. Mr Pedro, a loan officer, sat down with me, heard my situation and decided that I was worth taking a chance on. Here we are 3 years later and I have just renewed my loan for another 7 years. I couldn’t have purchased my building without the help of Mr Pedro and will be forever indebted to them for giving me a chance when no one else would."
    I will recommend you to contact a loan officer Mr Pedro on the information below if you need any financial assistance.
    Email & Chat: +1 863 231 0632 pedroloanss@gmail.com

    ReplyDelete

Dynamics CRM Native Lookup with filtered view

Introduction Well, we all know that dynamic CRM supports filtered view in Lookup that are opened from native lookup attribute or lookup ...