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

Notifications

Announcements

No record found.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 108 Super User 2025 Season 2

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans