Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Java script in CRM form scripting

Posted on by 594

Suppose say we have a field which has 2 options: Individual & corporate customers. Based on the field option selected we have to render a particular form (we have one form for individual option and another form for corporate option). 

How to approach this problem in CRM? If possible please give me the architecture of your solutions and java script code.

Thanks in advance

*This post is locked for comments

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: Java script in CRM form scripting

    Hi,

    Try the Javascript code below.

    function switchForm() {
        var lblForm;
        // get the value optionset field
        var value = Xrm.Page.getAttribute("optionSetFieldName").getValue();
        //check the value of the optionset field
        if (value == 1000001) {
            lblForm = "Individual";
        }
        else if (value == 1000002){
            lblForm = "Corporate";
        }
        //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();
                } 
            } 
        } 
    }

    Here1000001 and 1000002 are the option set values corresponding to the options Individual and Corporate respectively. Replace these values with option set values in your CRM.

    Hope this helps.

  • Suggested answer
    Guido Preite Profile Picture
    Guido Preite 54,081 Super User 2024 Season 1 on at

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans