Need support to call custom js function during Change Request creation
Hello all,
I want to validate a specific IBA on Change Request creation. This IBA is multi-valued and has enumerated values, let's say A, B, C, and D. So, when the user selects A and B both at a time, it should give an error. All other combinations should work fine except this A and B both together... I have written a JS function and placed it in create.jsp of the change request and tried to call this in my custom action file using action as a wizard step, something like below...
<objecttype name="changeRequest" class="wt.change2.WTChangeRequest2" resourceBundle="com.ptc.windchill.enterprise.change2.changeManagementActionsRB"> <action name="defineItemAttributesWizStep" afterJS="validateMyAttr" id="defineItemAttributesWizStep" preloadWizardPage="false" required="true" resourceBundle="com.ptc.core.ui.componentRB"> <command windowType="wizard_step" /> </action> </objecttype>
Below is my js function..
<script language='JavaScript'>
function validateMyAttr() {
// Get the IBA field element by its internal name and object type
const attrField = document.getElementById("WCTYPE|wt.change2.WTChangeRequest2|MY_ATTR");
// If the field is not present on the page, skip validation
if (!attrField) return true;
// Extract selected values from the multi-select dropdown
const selectedValues = Array.from(attrField.selectedOptions).map(option => option.value);
// Check if both A and B are selected
const hasA = selectedValues.includes("A");
const hasB = selectedValues.includes("B");
if (hasA&& hasB) {
alert("Invalid selection: You cannot select both A and B together.");
return false;
}
// All other combinations are valid
return true;
}
</script>
I place this JS function in create.jsp file. However, this is not working. Any suggestions would really help me. Thanks in advance
Regards,
AKC

