Error Encountered when Attempting to Change Forms Dynamically in CRM 2011: JavaScript Code Execution Problem

Upon form load, I check the type of the form and dynamically load the appropriate form based on that. It was working fine, but when the form reloads to the new form, I encounter a "JavaScript" error which says "cannot execute code from freed script" in English.

Here is the snippet of code that I am using:

avento_customertypecodeChange = function () {
    var lblShow = "information";
    var picklistName = Xrm.Page.getAttribute("customertypecode").getSelectedOption().text.toLowerCase();
    if (picklistName.contains("hc")) {
        lblShow = "information hc";
    }
    else {
        lblShow = "information";
    }

    var newIndex = -1;

    var currentName = Xrm.Page.ui.formSelector.getCurrentItem().getLabel().toLowerCase();
    if (currentName != lblShow) {
        Xrm.Page.ui.formSelector.items.forEach(function (item, index) {
            var itemLabel = item.getLabel().toLowerCase();
            if (itemLabel == lblShow) {
                newIndex = index;
            }
        });
    }

    if (newIndex != -1) Xrm.Page.ui.formSelector.items.get(newIndex).navigate();
}

Both forms are using the same "JavaScript" file. Could this be causing the error? How can I resolve this issue and avoid the error? I have been trying to find a solution for hours, but haven't had any luck. I'm hoping someone has encountered this problem before and can provide assistance.

Answer №1

My approach to solving this issue involved implementing a variety of techniques, even though it is not officially supported:

  1. First, I added the new "FormID" to the database.
  2. Next, I refreshed the entire page.
  3. As a result, the page was able to recall the associated FormID and display the correct form.

However, there are some disadvantages to this method:

  1. When creating a new form, there may be confusion about which form to use, resulting in a "Discard/Save changes" prompt if the form changes automatically...
  2. Another downside is that this method is not officially supported.

I believe the error mentioned above occurs because we attempt to access the same "Javascripts" web resources multiple times during form switching.

If anyone has a more efficient method for dynamically switching forms, please share your insights!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Failure to respond to dual part form by RemoveClass

Currently, I am utilizing jQuery to visually control a form. The issue arises when trying to remove classes from the first part of the form using removeClass. While this works initially, upon clicking the button to advance to the second part of the form, t ...

jquery to create a fading effect for individual list items

I have a group of items listed, and I would like them to smoothly fade out while the next one fades in seamlessly. Below is the code I've been working on: document.ready(function(){ var list_slideshow = $("#site_slideshow_inner_text"); ...

A JavaScript function that is only triggered half of the time

After browsing through various forums like StackOverflow, I couldn't find a solution that perfectly fits my issue. I may be new to programming, but I've managed to create several projects already. Currently, I am working on integrating them into ...

React - How to properly pass a reference to a React portal

I have a Card component that needs to trigger a Modal component. Additionally, there is a versatile Overlay component used to display content above the application. Displayed here is the App component: class App extends Component { /* Some Code */ ...

Is it possible to update only the necessary data using the Update Controller?

Update Controller exports.UpdatePanelMembers = (req, res) => { const { panelId } = req.params; if (panelId) { Panel.findOneAndUpdate( { _id: panelId }, { panelMembers: { member1: { memberId: req.body.pan ...

Sketch a straight path starting from the coordinates x,y at a specified angle and length

Is there a way to draw a line in Javascript starting from a specific x/y position with a given length and angle, without having to define two separate points? I have the x/y origin, angle, and length available. The line should be placed on top of a regula ...

Retrieve the Corresponding Content Inside the Div Element

I have a div with text that needs to be matched with comma-separated values: <div class="val"> This is paragraph 1 </div> <div class="val"> This is paragraph 2 </div> Using an Ajax call, I retrieve the ...

Altering Image Order Across Various Slides

I have customized a parallax website template that is divided into various sections and slides. I want to incorporate a fixed image sequence on each slide that animates based on the scroll position. With 91 images in the animation sequence, it moves quickl ...

The canvas is being expanded by utilizing the drawImage method

Ensuring the correct size of a <canvas> element is crucial to prevent stretching, which can be achieved by setting the width and height attributes. Without any CSS applied other than background-color, I am faced with an unusual issue. Using ctx.draw ...

An unusual html element

During a recent exploration of a website's code using the inspect tool, I stumbled upon a tag that was completely unfamiliar to me. <gblockquote></gblockquote> I've come across a blockquote before, but never a gblockquote. Interest ...

When transferring files to the src/pages directory in Next.js, the custom _app and _document components are not recognized

The documentation for Next.js mentions that the src/pages directory can be used as an alternative to /pages. However, I encountered a problem when moving my custom _app.tsx and _document.tsx files into the src folder, as they were being ignored. If you cr ...

Attempting to program a bot to navigate in a random pattern across a two-dimensional xz plane using Threejs

My journey began with the code below, which initiates a block moving in a straight line: const bot_geometry = new THREE.BoxGeometry(1,1,1); const bot_material = new THREE.MeshBasicMaterial( {color: 0x7777ff, wireframe: false} ); const bot = new THREE.Me ...

Personalize the start and end dates of Fullcalendar

While working with fullcalendar, I have a unique requirement. I want my days to start at 5:00 and end at 5:00 the next day. Is it feasible to achieve this customization? ...

What could be the reason for the lack of controller updates despite changes made to the service

Could someone please help me solve the issue with my code? I expected that after clicking the button, the text would be updated. However, it seems to not be working as intended. Any assistance you can provide would be greatly appreciated. main.js x = a ...

What could be the reason for a variable not being assigned a value following the xmlhttp.responseText?

During the validation process of a send-fax form, I am checking if a fax has been previously sent using our software fax package. This involves a simple query to a table executed by a script, which will return text if a previous fax exists or blank if not. ...

The action 'addSection' is restricted to private access and can only be utilized internally by the class named 'File'

const versionList = Object.keys(releaseNote) for (const key of versionList) { // Skip a version if none of its release notes are chosen for cherry-picking. const shouldInclude = cherryPick[key].some(Boolean) if (!shouldInclude) { continue } // Include vers ...

Ways to showcase the object on the console

How can I display the object function in the console? When I try, nothing is displayed. Can you please help me figure out what went wrong? I know I must have made a mistake somewhere, as this is my first question on Stack Overflow. import React, ...

Consecutive POST requests in Angular 4

Can you assist me with making sequential (synchronous) http POST calls that wait for the response from each call? generateDoc(project, Item, language, isDOCXFormat) : Observable<any> { return this.http.post(this.sessionStorageService.retriev ...

The authentication middleware is being executed for all routes within my app.js file, despite my intention to only apply it to a single route

I have developed a requireAuth middleware and integrated it into my app.js. In app.js, I have also imported all the routes from the routes folder. Each route.js file contains multiple chained routes. When I include the auth middleware in one of those files ...

Utilize Angular's $location to add or update the current URL parameter

I'm working on a function for handling multiple parameters in the URL when clicking an element. Specifically, I need to check if parameter pthree exists, update it to a new value without duplicating, and if it doesn't exist, append it to the curr ...