Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 79901

Javascript error

$
0
0

There will be a multi-select field with four values.

When the value 'Other' is selected, another field which will be a text field called 'Other', will be visible on the same form.

When 'Other' is deselected or never chosen, the 'Other' text field will be hidden from the form.

JScript will be on an OnChange event which will be used when the multi-select field is changed.

The multi-select field name is sh_funderreportingschedule. 


The 'Other' text field name is sh_other


The multi-select field cannot have a default value,


Both fields are on the form.


I will use JavaScript in a web resource by copying and pasting the code into the text editor. 


function toggleOtherField() {
// Get the multiselect field and 'Other' text field elements
var multiSelectField = Xrm.Page.getControl("sh_funderreportingschedule");
var otherField = Xrm.Page.getControl("sh_other");

// Get the selected options in the multiselect field
var selectedOptions = multiSelectField.getAttribute().getValue();

// Check if 'Other' is among the selected options
var hasOtherOption = false;
selectedOptions.forEach(function(option) {
if (option.name === 'Other') {
hasOtherOption = true;
return;
}
});

// Show/hide the 'Other' text field based on whether 'Other' is selected in the multiselect field
otherField.setVisible(hasOtherOption);
}

// Register the OnChange event for the multiselect field
Xrm.Page.getAttribute("sh_funderreportingschedule").addOnChange(toggleOtherField);

Error- Cannot read properties of null (reading 'forEach')Session Id: 907bb68e-fbf7-4f58-8c1a-7ec1c550f18cCorrelation Id: 4a4e9032-a312-40f3-b9e7-6d966d4a6c4dEvent Name: onchangeTime: Mon Jan 09 2023 16:02:52 GMT+0000 (Greenwich Mean Time)

 


Viewing all articles
Browse latest Browse all 79901

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>