If I understood correctly you want show the field 'Reason for Removal' if Keep/Remove is set to 'Remove'. Here is a JavaScript that should work:
function Onload(executionContext) {
//Execution Context needs to be passed as first parameter in form event handler
try {
var functionName = Onload.name;
let formContext = executionContext.getFormContext();
let formType = formContext.ui.getFormType();
switch (formType) {
case 6:
if (formContext.getAttribute("$Keep/remove").getValue() == "$Remove") {
formContext.getControl("$ReasonForRemoval").setVisible(true)
formContext.getAttribute("$ReasonForRemoval").setRequiredLevel("required")
}
break;
default:
break;
}
}
catch (e) {
//Error Message, not necessary for the logic to work
let alertStrings = { confirmButtonLabel: 'OK', text: "Function name: " + functionName + "\nMessage: " + e.message, title: "JavaScript erro" };
let alertOptions = { height: 180, width: 260 };
Xrm.Navigation.openAlertDialog(alertStrings, alertOptions).then(
function (success) {
// perform operations on alert dialog close
},
function (error) {
console.log(error.message);
// handle error conditions
}
);
}
}
1. You will need to replace the following:
- $Keep/remove: Is the logical name of your corresponding field
- $Remove: Is the value of the optionset when it's set to 'Remove' (e.g. 100000001)
-$ResaonForRemoval: Is the logical name of your field which should be visible and required.
2. You will need to create a Webresource (JScript) and paste/Upload the code there
Create web resources in Dynamics 365 Customer Engagement (on-premises) | Microsoft Learn
3. You will need to register the Webresource in the OnLoad Handler of your form (Main form)
Walkthrough: Write your first client script in model-driven apps - Power Apps | Microsoft Learn
If you have problems/questions, let me know.