cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can change your system assigned username to something more personal in your community settings. X

Adding my own afterVK Validator for Change Task set attributes page

avillanueva
22-Sapphire II

Adding my own afterVK Validator for Change Task set attributes page

I would like to add my own validation logic to creating and editing a change task, specifically the set attributes page. I see in the JSP for create its using the default for "object":

<jca:wizardStep action="defineItemAttributesWizStep" type="object"/>

and that already has a afterVK validator:

 

<objecttype name="object" class="wt.fc.Persistable" >
      <action resourceBundle="com.ptc.core.ui.componentRB" name="defineItemAttributesWizStep" id="defineItemAttributesWizStep" afterVK="setAttributesWizStep" preloadWizardPage="false" required="true" >
            <component name="defineItemAttributesWizStep" typeBased="true" windowType="wizard_step"/>
      </action>
</objecttype>

 

I do not want to upset and OOTB logic defined in the setAttributesWizStep and I only want this to be run for change task, not all objects. Is there an easy way to hook in this check?

Would I need to break from the default call out for "object" in the create.jsp and change the objectHandle to "task" and the copy the definition with my mod?

 

 

ACCEPTED SOLUTION

Accepted Solutions

Also an easy way to do this would be to override the FormProcessor. So you don't need to add your own action-model an actions. In the form Processor you can use the preProcess method to check the logic in the form. Just another way to do it.

View solution in original post

15 REPLIES 15

@avillanueva 

Can’t you add your own custom data utility that gets fired when the user selects the “Finish” button.

I think typically an OOTB data utility gets fired when you hit Finish and a validator can be fired when you hit the Next button.

 

So, you should be able to pick when you want your “validation” code to be fired.

 

I’ve not done this with Change Task but I have with Promotion Request. I would think it should work pretty much the same.

 

Just curious, but what are you validating? The object’s in the task are not already on an active CN/CA?

avillanueva
22-Sapphire II
(To:d_graham)

I am validating that the user did not pick the same person (themselves) for assignee and reviewer. Lots of ways to accomplish this I know but since jsp was defined to "object" and it traces back to SetAttributesStepValidator, I want to leave that as is but add something special to Change Task only. I think I know what I need to do. I will try extended that class and add my logic. Just means I need to alter create and edit jsp file to remove "object" clause to be more specific.

@avillanueva 

That was one of the things I was validating with the Promotion Notice.

Had to validate that a couple of roles had principals (if principal was group the group has WTUsers).

Had to validate the creator was not specifying themself as an Approver or Reviewer. (Nice try Joe User, but we’re not going let you slip your work by without some else looking at it).

Also, had to validate that the objects were not already on an active Promotion Request.

avillanueva
22-Sapphire II
(To:d_graham)

so with a data utility, you are disabling the finish button if the input is wrong?

Not “disabling”.

I return an error.,kind of like throwing an exception but different animal for sure..

I return a result that presents a window to the user with whatever text is appropriate to clearly explain the problem.

 

Finish button still works but rather than running OOTB data utility it runs my custom data utility 

Its like that.

HelesicPetr
22-Sapphire I
(To:d_graham)

Hi @avillanueva @d_graham 

 

The general question would be how to define datautility for the finish button. 

I know it is possible but I do not remember how 😄 

 

PetrH

avillanueva
22-Sapphire II
(To:HelesicPetr)

Did you have to define your own buttonList in the jsp file? I looks like it uses a standard one that is used everywhere. If you applied a DU to the generic finish button, wouldn't it be run on all Finish buttons that are part of "DefaultWizardButtonsNoApply"?

I know you replied to Petr, but I'll throw in my two cents.

 

Did you have to define your own buttonList in the jsp file?

That's a negative, I do everything with DU.

 

If you applied a DU to the generic finish button, wouldn't it be run on all Finish buttons that are part of "DefaultWizardButtonsNoApply"?

That's also a negative. You specify which Finish button will fired it.

avillanueva
22-Sapphire II
(To:d_graham)

Where is that done? I know how to write the DU but failing to see where its called out.

I looked at the screenshot you sent and then looked into the exact form (using WC 12.1.2.1).

 

You need a Validator not a Data Utiity. In the Promotion Request example I mention the Finish button fires a Data Utility but a Change Task Finish button fires a Validator.

 

To fire a custom Validator you need to override the OOTB Validator that the Finish button fires . This is done using a custom-action, same as you would to override any OOTB action.

So, to get it to work you have to register the Validator and override the Finish button’s OOT Validator.

 

In my Promotion Request form example I did have to override the Next button’s OOTB validator (to record the object types on the Promotion Request, the idea was if certain type exist limit the selectable workflow templates in the final step. Tricky for sure but it worked)

What I describe above is how I did it.

Also an easy way to do this would be to override the FormProcessor. So you don't need to add your own action-model an actions. In the form Processor you can use the preProcess method to check the logic in the form. Just another way to do it.

I might have to do this. All my tests have failed to show any execution of my validator specified in the afterVK block. I will do a quick stupid check before trying something new.

Hi @avillanueva 

Have you read this? https://www.ptc.com/en/support/article/CS171922

if I understand correctly the afterVK is activated by next|previose buttons 

PetrH

avillanueva
22-Sapphire II
(To:avillanueva)

Followed @BjoernRueegg suggestion after exhausting afterVK modification. Stupid check passed but still did not work with afterVK. I ended up extending the CreateChangeTaskFormProcessor and EditChangeTaskFormProcessor. This was much simpler. Two almost identical classes. Only needed to create preProcess method and call super.preProcess to keep same functionality. Then add my own business rule:

public FormResult preProcess(NmCommandBean nmBean, List<ObjectBean> beans) throws WTException {
		logger.debug("in preProcess of DanburyCreateChangeTaskFormProcessor");
		FormResult result=super.preProcess(nmBean, beans);
		logger.debug("super result was " + result.getStatus());
		if (result.getStatus() == FormProcessingStatus.SUCCESS) //if some other failure, go with that.
		{
			for (ObjectBean bean:beans)
			{
				ParticipantSelectionDelegate psd = ParticipantSelectionDelegate.newInstance(bean);
				if (psd.showMultipleParticipantSelection()) {
					logger.debug("Workflow roles are processed using the multiple participant selection component.");
				} else {
					WTPrincipal assignee = ChangeManagementFormProcessorHelper.getUser("changeTask_AssigneePicker_dn", bean);
					WTPrincipal reviewer = ChangeManagementFormProcessorHelper.getUser("changeTask_ReviewerPicker_dn", bean);
					logger.debug("Assignee:"+assignee + "|Reviewer:"+reviewer);
					if (assignee == null) //never should be executed
					{
						logger.debug("Assignee is not set");
						result.setStatus(FormProcessingStatus.FAILURE);
						String message="Assignee is not set";
						String explanation="Assignee should be one do the task.";
						result.addFeedbackMessage(new FeedbackMessage(FeedbackType.FAILURE, getLocale(), message, (ArrayList) null, new String[]{explanation}));
					}
					else if (reviewer == null) //never should be executed
					{
						logger.debug("Reviewer is not set");
						result.setStatus(FormProcessingStatus.FAILURE);
						String message="Reviewer is not set";
						String explanation="Reviewer be one to should validate task is complete (Peer, Lead or Manager).";
						result.addFeedbackMessage(new FeedbackMessage(FeedbackType.FAILURE, getLocale(), message, (ArrayList) null, new String[]{explanation}));
					}
					else if (assignee.equals(reviewer))
					{
						logger.debug("Assignee and Reviewer are the same, business rule violation");
						result.setStatus(FormProcessingStatus.FAILURE);
						String message="Assignee and Reviewer cannot be the same person";
						String explanation="Assignee should do the task.\nReviewer be one to should validate task is complete (Peer, Lead or Manager).";
						result.addFeedbackMessage(new FeedbackMessage(FeedbackType.FAILURE, getLocale(),message, (ArrayList) null, new String[]{explanation}));
					}
				}
				logger.debug("Checks complete, exitting preProcess of DanburyCreateChangeTaskFormProcessor");
			}
		}	
		return result;
	}
avillanueva
22-Sapphire II
(To:avillanueva)

Also needed to override callouts for those processors in my custom-actions.xml file for the change task edit, create and a few other actions.

Announcements

Top Tags