Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

Open specific form based on field value in CRM 9.2 Online

(0) ShareShare
ReportReport
Posted on by 2,665

Hi All,

I have used the below code in online crm 9.1 to load the specific from based on lookup field value & called the method onload of case but its not working in online but this code worked in onprem 9.0 version.What could be the issue ?

//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);
    }
}
Any idea anyone it will be appreciated !!
Thanks,
Jharana
  • Suggested answer
    Wahaj Rashid Profile Picture
    11,321 on at
    RE: Open specific form based on field value in CRM 9.2 Online

    Hi,

    Thank you for your query.

    I believe following line in your code should be replaced:

      var items = formContext.ui.formSelector.items.get();

     // No need of .get() after Items (it will return the collection, .get(arg) expects an argument)

      var items = formContext.ui.formSelector.items; 

    Also, did you check if the value is being returned by GetLookupName() function? Apparently code looks just fine,  log this value using console.log or add debugger; in start of the function so you can debug it in the dev tools.

  • Jharana Baliyar Singh Profile Picture
    2,665 on at
    RE: Open specific form based on field value in CRM 9.2 Online

    Hi Mehdi,

    Thanks for the response. There is no specific error its loading wrong form based on field value which is interaction type lookup field here.

    GetLookupName is using in common library :

    function GetLookupName(formContext, fieldName) {

       var value = formContext.getAttribute(fieldName).getValue();

       if (value != null) {

           return value[0].name;

       }

    }

    The above code woked fine in 9.0 CRM Onpremise version.

    Thanks,

    Jharana

  • meelamri Profile Picture
    13,216 User Group Leader on at
    RE: Open specific form based on field value in CRM 9.2 Online

    Hi,

    what is the generated error? Can you give more details about the error please? Also, could you share the code of the GetLookupName function ?

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 225 Super User 2025 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 91

#3
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 78 Super User 2025 Season 1

Overall leaderboard

Product updates

Dynamics 365 release plans