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!!
Parents
  • 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
Reply
  • 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
Children
  • 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.