0
I have two single-relational fields titled Category and Type. Type is dependent on Category.

I’m trying to use a Form Action to perform this logic:

“If the Category value = ‘Export Control’ Then set the field value for Type field to N/A”

So, in my Form Action I have the following logic in the “When” space:
Category field changes value

My IF condition is “If a Javascript equates to true.” This is my IF statement (which seems to be working):

$("option:selected", GetFieldByName("CATEGORY_SR")).val() == "48"


My THEN action is “Execute a Javascript.” This is my THEN statement:
SetFieldValue("TYPE_SR", "N/A", true);
What actually happens:
I get a popup box stating “Currently processing previous request, please wait until the request completes, you silly, silly man.”

Need some help figuring out what is going on here.
Like

Accepted Answer

Thursday, April 09 2015, 10:14 AM - #Permalink
0
When you change an independent single relation field, a round-trip has to occur to the server to update all of the selections available for the fields dependent on that field. So the problem is that this round trip is occurring at the same time you are trying to update that field.

You might try changing your When condition to be based on the TYPE_SR (dependent) field, although I've had problems in the past making that work. If N/A is the only valid selection in the list for that Category SR value, then you could also change the dependency setup to change value to "First Valid Entry". Of course, it will do that for all of your other dependent selections as well, so not sure if that is okay or not. If neither of those works, then you would have to delay a bit before setting the value (or maybe just hide the TYPE_SR field and set it at form submit time).
The reply is currently minimized Show
Responses (3)
  • Accepted Answer

    Jeff Malin
    Jeff Malin
    Offline
    Thursday, April 09 2015, 11:55 AM - #Permalink
    1
    Here is a function which we wrote to use in this situation and many others like it. This checks to see if a server-side call is currently executing, and if so, creates an interval listener which waits until the call completes, then executes your desired function.


    function AddAjaxLoadCallback(fnCallback) {
    // Adds a transient callback to the currently-executing AJAX request, allowing execution of scripts after sub-relational fields load
    // Usage: AddAjaxLoadCallback(myFunction) // Previously-defined function name (no parameters)
    // Usage: AddAjaxLoadCallback(function(){do something}); // directly-entered anonymous function

    if (top && top.req) {
    if (top.req.readyState == 4) {
    if (top.req.status == 200) { // If no request is in progress, execute callback immediately
    fnCallback();
    };
    } else { // AJAX request is in progress, create a listener
    var ajaxListener = setInterval(function() {
    if (top.req.readyState == 4) {
    clearInterval(ajaxListener);
    if (top.req.status == 200) {
    fnCallback();
    };
    }
    }, 100); // Polls every 100ms to detect load state
    }
    };
    };
    The reply is currently minimized Show
  • Accepted Answer

    Jeff Malin
    Jeff Malin
    Offline
    Thursday, April 09 2015, 12:01 PM - #Permalink
    0
    By the way, this same function can be used to take actions based on the value of sub-relational fields when their parent item changes. By waiting until the server-side request completes, you are ensured that the sub-relational value has loaded and is now available for whatever calculation or actions are needed.
    Like
    The reply is currently minimized Show
  • Accepted Answer

    Thursday, April 09 2015, 12:14 PM - #Permalink
    0
    I created a form action to hide the dependent field if the Category field value matched by condition. Then I added a second form action to execute at form submission to change the value of the dependent field (TYPE_SR) to N/A - worked like a charm.

    Thanks Lynn!
    Like
    The reply is currently minimized Show
Your Reply

Recent Tweets