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,...
Suggested Answer

Open specific form based on field value in CRM 9.2 Online

(0) ShareShare
ReportReport
Posted on by 2,667

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
I have the same question (0)
  • meelamri Profile Picture
    13,216 User Group Leader on at

    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 ?

  • Jharana Baliyar Singh Profile Picture
    2,667 on at

    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

  • Suggested answer
    Wahaj Rashid Profile Picture
    11,321 on at

    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.

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 83 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

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

#3
#ManoVerse Profile Picture

#ManoVerse 40

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans