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 :
Microsoft Dynamics CRM (Archived)

JScript - Clear Whole Tab Values on Field Change

(0) ShareShare
ReportReport
Posted on by

Hi all! I am trying to write a script that will run OnChange for a field to clear all values in a specific tab. In this example, the Tab to be cleared is "Triage", and the field i'd like to have it execute on is "new_storereportedissue":

function clearTab() {

Xrm.Page.getAttribute("new_storereportedissue").addOnChange(clearTab)
var Triage = Xrm.Page.ui.tabs.get("Triage");
	   
    Triage.sections.forEach(function (section, sectionIndex) {
        section.controls.forEach(function (control, controlIndex) {

            switch (control.getAttribute().getAttributeType()) {
                case "boolean":
                    //for checkbox control, uncheck it
                    control.getAttribute().setValue(null);
                    break;
            }
        });
    });
}


I'd love any help. Thank you!

*This post is locked for comments

I have the same question (0)
  • Nicolas.Plourde Profile Picture
    240 on at

    You can also make a business rule to do this.

    function onload() {
    	// You can either do this in the onload of the form or bind the event
    	// on the control (double-click on the control and look for the tab events)
    	Xrm.Page.getAttribute("new_storereportedissue").addOnChange(clearTab);
    }
    
    function clearTab() {
    
    	var triage = Xrm.Page.ui.tabs.get("Triage");
    	
    	// This will work but it's a bit too much. You should consider setting each attributes yourself here.
    	//  Of course with this method you wont have to update your code.
        triage.sections.forEach(function (section, sectionIndex) {
            section.controls.forEach(function (control, controlIndex) {
    
    			// In theory, you can set null every fields without checking types
    			control.getAttribute().setValue(null);
    			
    			// Making sure the control will be saved
    			control.setSubmitMode('dirty');
            });
        });
    }
  • Community Member Profile Picture
    on at

    [quote user="Nicolas.Plourde"]

    [stuff]

    [/quote]

    I tried throwing this into the TabStateChange Handler of the Triage tab with no success:

    function clearTab() {
    	Xrm.Page.getAttribute("new_storereportedissue").addOnChange(clearTab);
    }

    Additionally, I tried to execute your version of clearTab and it errored out. Is it correct to reference a variable as shown (triage.sections.forEach)?

    If it helps, the reason I would like to blanket clear the whole tab is because it contains over 150 fields that are visible based on the store reported issue. Hope this helps, and thanks for replying.

  • Community Member Profile Picture
    on at

    [Reserved]

  • Community Member Profile Picture
    on at

    Bump - anyone have any ideas? I just want to get the Javascript to wipe a whole tab's info when a certain field is changed. Thanks!

  • RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    The script provided by Nicolas above should work fine. What's the error you got with that script?

  • Community Member Profile Picture
    on at

    Hi Ravi! Thanks for the reply. When I add Nicolas' version of the clearTab function to OnChange for the new_storereportedissue field, I get this error when it fires (had to edit out my companies instance name):

    clearTab/</<@example.crm.dynamics.com/.../new_CIClearTab
    forEach@example.crm.dynamics.com/.../global.ashx
    clearTab/<@example.crm.dynamics.com/.../new_CIClearTab
    forEach@example.crm.dynamics.com/.../global.ashx
    clearTab@example.crm.dynamics.com/.../new_CIClearTab
    @example.crm.dynamics.com/.../ClientApiWrapper.aspx line 157 > eval:1:1
    RunHandlerInternal@example.crm.dynamics.com/.../ClientApiWrapper.aspx
    RunHandlers@example.crm.dynamics.com/.../ClientApiWrapper.aspx
    ExecuteHandler@example.crm.dynamics.com/.../ClientApiWrapper.aspx
    $Ch_1@example.crm.dynamics.com/.../formcontrols.js
    executeHandler@example.crm.dynamics.com/.../formcontrols.js
    executeHandlerByDescriptor@example.crm.dynamics.com/.../formcontrols.js
    getHandler/<@example.crm.dynamics.com/.../formcontrols.js
    getHandler/<@example.crm.dynamics.com/.../global.ashx
    fireOnChange@example.crm.dynamics.com/.../formcontrols.js
    setValueInternal@example.crm.dynamics.com/.../formcontrols.js
    setValue@example.crm.dynamics.com/.../formcontrols.js
    updateDataAttributeValue@example.crm.dynamics.com/.../formcontrols.js
    $3e_2@example.crm.dynamics.com/.../formcontrols.js
    Function.createDelegate/<@example.crm.dynamics.com/.../MicrosoftAjax.js
    b@example.crm.dynamics.com/.../MicrosoftAjax.js


    Hope this helps!

  • Verified answer
    Community Member Profile Picture
    on at

    Problem resolved with the following code:

    function clearTab() {  
             var sectionName = Xrm.Page.ui.tabs.get("Triage").sections.get();
             for (var i in sectionName) {
             var controls = sectionName[i].controls.get();
             var controlsL = controls.length;
             for (var i = 0; i < controlsL; i++) {
                 controls[i].getAttribute().setValue(null);
              }
            }
        }


    Thanks everyone!

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 > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans