web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Show Form based on Lookup field Value using js in CRM 365 9.0

(0) ShareShare
ReportReport
Posted on by 2,667

Hi All,

I have used js to show form based on lookup field value,here am using case entity which has 6 types of main forms which are active there i have used switch case to show particualr form, it was working earlier but suddenly got stopped working same script code am using for all the forms on load.

Apart from this active 2 more forms are there but they are in InActive forms which i dont think the script has to be present.In UCI i can see only 6 main forms & am toggling based on field value.

Is anyone has any idea why its not working the below code am using :

//Show form based on Interaction Type, keep this method in all case forms
function showForm(executionContext) {
    try {
        var formContext = executionContext.getFormContext();
        var interactionType = GetLookupName(formContext, "mdc_interactiontype");
        var lblForm;
        var relType = interactionType
        switch (relType) {
            case "Gift & Entertainment":
                lblForm = "Case Overview - G&E";
                break;
            case "Conflict of Interest":
                lblForm = "Conflict of Interest";
                break;
            case "Investigation":
                lblForm = "Case Overview - Investigation";
                break;
           case "Enquiry":
                lblForm = "Case Overview - Enquiry";
                break;
                                                case "Personal Trade Management":
                lblForm = "Case Overview - Personal Trade Management";
                break;
                                    case "Restricted Security Management":
                lblForm = "Restricted Securities";
                break;
            default:
                lblForm = "Case Overview - G&E";
        }
        //check if the current form is form need to be displayed based on the value
        var formLabel = formContext.ui.formSelector.getCurrentItem().getLabel();
        if (formLabel != lblForm) {
            var items = formContext.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();
                }
            }
        }
    } catch (error) {
        var errorOptions = {
            details: "Error in CaseOverviewEnquiry js, Method Name:showForm().Download Error log file",
            errorCode: 2,
            message: error.message
        };
        Xrm.Navigation.openErrorDialog(errorOptions);
    }
}
Thanks,
Jharana
I have the same question (0)
  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    Can you please provide that code of GetLookupName method?

  • Suggested answer
    Jharana Baliyar Singh Profile Picture
    2,667 on at

    Hi Andrew,

    Thanks for ur quick response.

    I got to know where was the exact issue u r correct, it was coming from web api which hv used to set lookup value. I used true in web api retrieve multiple request earlier after changed to false it got worked. I hope this is the cause being not populating lookup correctly & based on lookup also am using script to show the form.

    Thanks again !!

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

#2
ManoVerse Profile Picture

ManoVerse 55 Super User 2026 Season 1

#3
11manish Profile Picture

11manish 37

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans