Skip to main content
1-Visitor
October 29, 2025
Question

Need support to call custom js function during Change Request creation

  • October 29, 2025
  • 1 reply
  • 228 views

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

1 reply

avillanueva
23-Emerald I
23-Emerald I
October 29, 2025

Can you verify that script is being called at all and that its cycling through attribute? Its possible that the field names it checking are slightly different. I would have it output a list of all field names to make sure when you are getting it, that it matches the text you put in.

HelesicPetr
22-Sapphire II
22-Sapphire II
November 5, 2025

Hi @AKC_301264 

Put the alert at start of the JS script and also at the end. 

This is a way how to check(debug) if the script works. 

If the alert is not triggered then something is wrong in the definition and has to be solved by moving the script to general or upper html(jsp) page. 

If the script is run but it can not finish then the script throws some error and you have to find it and solve it. 

PetrH

PetrH