JavaScript API interaction with server side validation...

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!!
  • Verified Answer

    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.
  • 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".
  • 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)
    if currValue = DBValue then
    checkFieldChanged = false
    elseif currValue = "" and dbValue = -2 then ' Workaround for null Date issue
    checkFieldChanged = false
    checkFieldChanged = true
    end if
    end function
  • 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.
  • 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.
  • 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.
  • 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!
  • 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.
  • 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.
  • Two thoughts:

    1. What is the Orchestration doing, is it something that needs to be an Orchestration (external web service or API calls) or can you put its logic in an AppScript instead?

    2. If you need to keep a separate Script and Orch, try adding an intermediate Decision node in the workflow that checks if the flag is set. Put the AppScript on the transition into the decision node. Then on the "True" branch of the decision (if the flag is set), hang the Orchestration. That should ensure it fires after the AppScript runs.