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
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!
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!
Hi,
The script provided by Nicolas above should work fine. What's the error you got with that script?
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!
[Reserved]
[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.
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'); }); }); }
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156