Monday, June 11, 2012

How to display an entity form based on the option set field (Multiple forms CRM2011)

Sometimes we need multiple forms based on categorisation of an entity. For example, an account can be  a customer or a competitor or a supplier etc. It is possible that we need to capture or display different fields based on the type of an account. Suppose we have different forms  for different types of account. If the user opens an account record, the system should open a appropriate form based on the type of the account.
In this example I am using account entity. I have created 2 custom forms. Now I have 3 account forms (Information, Information1, Information2). In out of the box account entity . there is a “Relationship Type” or customertypecode field to categorise the account entity. It is picklist field. I want to open a different form based on the value of the customertypecode field . Here is the code.
function showForm() {

//if the form is update form
if (Xrm.Page.ui.getFormType()==2)
    // variable to store the name of the form
    var lblForm;

    // get the value picklist field
    var relType = Xrm.Page.getAttribute("customertypecode").getValue();

    // switch statement to assign the form to the picklist value
    //change the switch statement based on the forms numbers and picklist values
    switch (relType) {
        case 1:
            lblForm = "Information1";
            break;
        case 2:
            lblForm = "Information2";
            break;
        default:
            lblForm = "Information";
    }
    //check if the current form is form need to be displayed based on the value
    if (Xrm.Page.ui.formSelector.getCurrentItem().getLabel() != lblForm) {
        var items = Xrm.Page.ui.formSelector.items.get();
        for (var i in items) {
            var item = items[i];
            var itemId = item.getId();
            var itemLabel = item.getLabel()

            if (itemLabel == lblForm) {
                //navigate to the form
                item.navigate();
            } //endif
        } //end for
    } //endif
 }//endif
} //end function
The code is checking if the form is an  “Update” form and opens up the form based on the value of customertypecode field. The code is reloading the form only if the current form is different than the form the system should be displaying.
Call this function on form load event.
Happy programming…

28 comments:

  1. hi grate post i have done this and but small problem on loaded form. all the ribbon buttons are disabled any idea to resolve this

    ReplyDelete
    Replies
    1. further im using this to quote entity and also notice that once we active the record the form selector script not executing

      Delete
    2. I don't have access to CRM right now. I will check it for you.

      Delete
  2. I was having minor difficulties with the program and I was just looking for the solution. So, this is how it should have been done. It's been helpful, this code.

    ReplyDelete
  3. Microsoft Dynamics CRM training will help you manage and prioritize your business goals, customize.we teach MS Dynamics CRM training and class available at Hyderabad.

    ReplyDelete
  4. Hello,

    This looks exactly like what I am need, however, when I run this on the Form Load event, I keep getting an error:

    The value of the property 'ShowForm' is null or undefined, not a Function object.

    I created a new javascript web resource called dmo_ShowForm and than add it as a Form Library. Then selected Control:Form and Event:Onload and Function:ShowForm

    I also tried replacing the "" with straight quotes and single quotes in case something in the copy/paste changed the quotes.

    In the error report it says Syntax error, line 39, however, that is just the end of the script and I have tried adding/remove braces } but doesn't seem to get rid of the error. Also tried alert(relType) to see if I was getting a value but the alert just gets ignored.

    Any ideas?

    ReplyDelete
    Replies
    1. Of course, after posting I was able to find what was causing the error.

      1. I had called the function in the script showForm but had called it ShowForm in the Function field of the CRM UI...case matters here.

      2. In line 1 of the script, if (Xrm.Page.ui.getFormType()==2) it is missing an open brace ({) at the end

      (Xrm.Page.ui.getFormType()==2) {

      Thanks again for posting this! It was very helpful!

      Mike

      Delete
    2. Thank you Amreek for the original script and MikeH for your revisions to the script. The script is working however, when I close out of the form I get an error. MikeH - would you be able to post your final script? I have attached mine in hopes someone could identify the error. Thanks!

      function showForm() {

      //if the form is update form
      if (Xrm.Page.ui.getFormType()==2) {
      //variable to store the name of the form
      var lblForm;

      //get the value picklist field
      var relType = Xrm.Page.getAttribute("casetypecode").getValue();

      //switch statement to assign the form to the picklist value
      //change the switch statement based on the forms numbers and picklist values
      switch (relType) {
      case 1:
      lblForm = "Information1";
      break;
      case 2:
      lblForm = "Information2";
      break;
      default:
      lblForm = "Information";
      }
      //check if the current form is form need to be displayed based on the value
      if (Xrm.Page.ui.formSelector.getCurrentItem().getLabel() != lblForm) {
      var items = Xrm.Page.ui.formSelector.items.get();
      for (var i in items) {
      var item = items[i];
      var itemId = item.getId();
      var itemLabel = item.getLabel()

      if (itemLabel == lblForm) {
      //navigate to the form
      item.navigate();
      }//endif
      }//end for
      }//endif
      }//endif
      }//end function

      Delete
  5. Hello! Do you utilize any specific services to attract more readers your domain on a daily basis? Can't wait to hear from you.

    ReplyDelete
  6. Hi Amreek,
    We have used similar script to redirect between multiple forms which was working fine, after UR 13 is applied we are getting a save/discard alert. Any idea how to fix that?

    Regards
    Jeevan

    ReplyDelete
  7. Hi,

    Could you please help me out, how to show/hide the field based on radio button. How to get rid of Empty space of hidden field?

    ReplyDelete
    Replies
    1. Put that field in a section and hide the section using

      Xrm.Page.ui.tabs.get("TabName").section("SectionName").setVisible(false);

      Delete
  8. Can we switch between multiple Form without loading the form twice?

    ReplyDelete
  9. " Can we switch between multiple Form without loading the form twice?" - AnonymousJanuary 20, 2015 at 2:23 AM

    I'm also really curious to that! Has someone developed this kind of great functionality already or know its somehow possible?

    ReplyDelete
  10. I was searching for a loan to sort out my bills & debts, then I saw comments about Blank ATM Credit Cards that can be hacked to withdraw money from any ATM machines around you . I doubted this but decided to give it a try by contacting { officialblankatmservice@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 to pick up my car key and drove to a nearest ATM machine to confirmed if the card really work to my greatest surprise it did.. This is no doubt because I have the card & have made use of the card. These hackers are UK based hackers set out to help people with financial freedom!! Contact them via email: officialblankatmservice@gmail.com or WhatsApp +447937001817 if you want to get rich.

    ReplyDelete

  11. We are a professional carding team with a large ring around the globe. With over 2 million ATM infected with our malware and skimmers, we can grab bank card data which include the track 1 and track 2 with the card pin. We in turn clone this cards using the grabbed data into real ATM cards which can be used to withdraw at the ATM or swipe at stores and POS. We sell this cards to all our customers and interested buyers worldwide, the card has a daily withdrawal limit of $2500 on ATM and up to $50,000 spending limit on in stores.



    Here is our price lists for the ATM CARDS :
    BALANCE: PRICE
    $10,000: $500
    $20,000: $1000
    $35,000: $1700
    $50,000: $2500
    $100,000: $5000
    The prices include the shipping fees and charges, order now: Contact us: smoothhackers006@gmail.com Whatsap +16572677149
    FREQUENTLY ASKED QUESTIONS (FAQ)

    ReplyDelete
  12. 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.The programmed ATM card 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.
    -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 us now and get whatever you want at
    Email:creditcards.creditscoreupgrade@gmail.com
    whatsapp:+1785 279 3047

    ReplyDelete
  13. I would strongly love to recommend the services of the best team of dark web hackers. They are professional and very discreet in carrying out their jobs, they have the best customer service agents and satisfaction at heart. If you have any services you wish to contact them for, go on info@albertgonzalezwizard.online / Whatsapp +31684181827 or Telegram:  +31687920980. They help track and monitor your cheating partner's phone without his idea, clear or erase criminal records as well as repair a bad credit score, all social media hacks,funds recovery and many others.

    ReplyDelete

  14. I know many thing could have gone wrong this past few days investing online and getting scammed. I was also in your shoes when I invested into a fake binary option where I got scammed of $3000 of BTC but thanks to the help of cchacker0002@gmail.com . They assisted me in recovering back my scammed BTC. I initially didn’t trust them but I was referred by a friend who I trust well. I was able to get my refund within the space of two weeks. Thanks to cchacker0002@gmail.com

    ReplyDelete
  15. I am a consultant firm linking and looking for foreign individuals/Business enterprises and corporate bodies that need business expansion and have a business idea that needs investment and I am willing to invest profitably a huge amount of money that is at my disposal in a profitable long-term venture, most importantly, I am required to invest these funds on real estates/Loans to public firms or businesses with a low-interest rate/open companies and buy villas and give out for rents. preferably in your country of residence or any other suitable location.

    I shall appreciate it if you can give me the best assistance I need, hoping to cooperate with you in the near future I will let you know the amount of fund client funds that will be invested, Interested individuals or corporate bodies should contact me for more information, waiting for your prompt reply as soon as possible.
    Contact us now
    For more information,
    WhatsApp/telephone number:+447456048939
    Email: raywaters63@gmail.com

    ReplyDelete
  16. QUICK EASY EMERGENCY URGENT LOANS LOAN OFFER EVERYONE APPLY NOW +918929509036 financialserviceoffer876@gmail.com Dr. James Eric

    ReplyDelete
  17. I'd like to express my sincere gratitude to the woman who commented on how she used DWOH to recover her bitcoin and return it to her wallet. Coincidentally, I experienced a similar issue and, after losing a total of $88,000 on a phony cryptocurrency investment platform, I felt compelled to contact them for assistance. Today, I can attest to their authenticity because, as I type this, I have my lost bitcoin back in my CoinBase wallet and am in tears of joy. Please get in touch with DWOH using the following information via Email Address: dwchzone@gmail.com OR Whats-App: +1 (803) 392-1735 if you're having withdrawal issues, wish to recover, or want to confirm a website is legitimate before investing.

    ReplyDelete


  18. How I Recovered My scammed Cryptocurrency with Captain WebGenesis

    "Being a victim of a Cryptocurrency fraud, I had given up on ever getting my hard-earned money back. Having Lost a significant amount of my portfolio through the scam, I was completely depleted and on the verge of losing everything. That is until I came across Captain WebGenesis, a group of experienced Cryptocurrency recovery experts. Their group was really beneficial and effective in assisting me in getting my money back from the con artists. They went above and beyond to guide me through the process, and I'm glad to report that with their help, I was able to get my money back. I appreciate Captain WebGenesis' commitment to aiding victims such as myself."

    Send a complaint to
    Email: Captainwebgenesis@ hackermail. c om
    Text/ Call; +1 (501) 436,9362.

    Learn More; Captainwebgenesis. com

    ReplyDelete
  19. ASSET RECLAIM IS POSSIBLE WITH THE RIGHT FIRM:
     The world of online trading is a harrowing journey, filled with financial opportunities and rough edges. I'm publishing this review voluntarily, so others can lean on ICC RECOVERY SERVICE for retrieving over a million dollars worth of assets to my digital ledger. I was caught in a web of fraud and disillusionment when the investment platform mediating my trades betrayed my trust. My quest for justice led me down a path filled with bitter stories & testimonials. Negative reviews that painted a grim picture of heinous exploitations. In my searches, I came across ICC RECOVERY SERVICE on Yelp. Guided by reviews and recommendations from other victims, I hit it off immediately with ICC RECOVERY SERVICE and they became a beacon of hope in my murky waters. ICC RECOVERY SERVICE quickly became ally in my fight for justice, offering more than technical expertise in reclaiming what's rightfully mine. Although the road to redress was riddled with obstacles, ICC team meticulously traced my assets to multiple digital wallets. Their professionalism and dedication offered me comfort in the midst of chaos, reassuring redress was within reach, and I got my assets back in 3 business days. For timely recovery of lost passwords and seed phrases, hacked wallets and lost funds with scandalous financial brokers, a chat with ICC RECOVERY SERVICE will be just right. I highly recommend ICC for your recovery needs.
    Contact addresses:
    Email: (ironcladcyber@techie.com)
    W/App: (+1-(623) 688-6815)
    Email: (ironcladcyberrecovery@gmail.com)

    ReplyDelete