Big news! The community will be moving to a new platform April 21. Read more.
Big news! The community will be moving to a new platform April 21. Read more.
Cadet 1st Class
Cadet 1st Class
4740 views

JavaScript API interaction with server side validation...

Jump to solution
I have a field A, which I am trying to detect a change in on the client and then pass a flag to the server in field Z.
I am using AddChangeCallback to set field Z when A changes.
On the server I am able to query field Z to know that A has changed during the transition.

However, I have a field Q which is a required field.
If I change field A and leave field Q blank then the server side validation fails and this causes the page to reload.
When the page is reloaded field A still contains the new value, but I no longer know that this has changed.

Is there a better way to reliably detect changes in the client? At present I am checking whether an error is displayed on page load and if so then I have to assume everything has changed which is not ideal for me. I have submitted another post recently about this... I am trying to call a web service method on the server, but this is an expensive operation and I would only like to do this when a field is actually changed.

Any help or thoughts about this would be much appreciated... thanks!!
0 Likes
1 Solution

Accepted Solutions
Absent Member.
Absent Member.
I'm not sure why field Z wouldn't retain its new value, unless you are clearing it on form load.

Can you fire the orchestration from the notification, instead of the transition? Then you pretty much define exactly the rule you want and can include Field A Changes.

View solution in original post

14 Replies
Absent Member.
Absent Member.
I'm not sure why field Z wouldn't retain its new value, unless you are clearing it on form load.

Can you fire the orchestration from the notification, instead of the transition? Then you pretty much define exactly the rule you want and can include Field A Changes.

View solution in original post

Fleet Admiral
Fleet Admiral
How about doing the validation of field Q with JavaScript or Form Actions. That saves the round-trip to the server. See the docs on "AddSubmitCallback".
Absent Member.
Absent Member.
You can use an AppScript to compare the DB Value with the current value in the post-transition context. Here's a utility function to do this:

function checkFieldChanged(fieldName)

dim fldObj, currValue, dbValue
set fldObj = shell.item.Fields().FindField(fieldName)
fldObj.getValue(currValue)
fldObj.getDBValue(dbValue)
if currValue = DBValue then
checkFieldChanged = false
elseif currValue = "" and dbValue = -2 then ' Workaround for null Date issue
checkFieldChanged = false
else
checkFieldChanged = true
end if
end function
Cadet 1st Class
Cadet 1st Class
Following on from Jeff's suggestion, the problem I would have is that if I have an AppScript and an Orchestration that both need to fire post-transition then I can't get the AppScript to fire before the Orchestration.

I need to fire the AppScript first to store a value in a field to indicate that another field has changed and then this can be passed to the Orchestration, but I cannot seem to be able to configure the order in which they fire.
0 Likes
Cadet 1st Class
Cadet 1st Class
Thanks everyone for your help with this! After mulling this over some more I think what would have made this a lot easier is if I didn't have so many transitions where the same field could be updated. I think the workflow and forms are just badly designed and you can pretty much change everything on every transition. On most of the transitions I think I should be using less generic forms where only certain fields can be changed. If the field I was interested in could only be changed on 1, or perhaps a few, transitions then this would have made both solutions above really simple. Thanks again!
0 Likes
Absent Member.
Absent Member.
You may not need new forms, just field overrides. I usually set most of my fields to Read Only by default, and then override them on the transitions where it makes sense for users to be updating them. Sometimes I create special transition forms, but if the correct fields are Read Only, you can use the same transition form for multiple transitions.
0 Likes
Cadet 1st Class
Cadet 1st Class
I am clearing the field on form load, which is the cause of the problem. I am wondering whether to clear the field on the server instead... possibly in a pre-transition step or set the field to a default value for each transition, and/or possibly reset the field on the post-transition step once I have processed my on change handling on the server.
0 Likes
Cadet 1st Class
Cadet 1st Class
I am not sure whether you can fire orchestrations from notifications, it has not been something I have actually looked into... do you know if this is possible? However, what I am trying to achieve is complex server side validation using a web service method, so the idea was to use a synchronous orchestration on my transition, so that I can then throw an error and prevent the transition from occurring. I am not sure whether you would be able to achieve the same thing and prevent a transition using notifications... I would expect not, but again this is not something I have looked into.
0 Likes
Absent Member.
Absent Member.
On the transitions that are using the form, you can override the field and choose to Clear the field. This will occur before the form comes into play and the field would not be cleared again because of a missing required field.

You can fire an orchestration from a notification, but it would be an asynchronous orchestration.
0 Likes
Cadet 1st Class
Cadet 1st Class
Yes, that would indeed solve the issue in this particular case and would certainly be an improvement on what I have currently done. The problem is that I have other server side validation and for this to work well I would have to do all my validation on the client, which cannot always be easily done, especially if there is more complex server side validation. I could also not guarantee that someone would not add additional server side validation in future, but I guess I could fall back to my "there is an error so my field might have changed" handling... it's certainly a possible option!
0 Likes
Cadet 1st Class
Cadet 1st Class
I really like the idea of detecting the change on the server... it seems like the sensible and most reliable place to do this and the provided utility function is really handy. However, the problem I have is how can I get the result of this app script to be used in an Orchestration. My thinking was have an app script that stores the result in a separate field and this can then be passed to the orchestration... it sounded very promising! The problem with this is that the Orchestration seems to be invoked before the app script is run with no way of changing the order. I'll explain this in a separate reply so I can include a picture to make this clearer.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.