[Utah] onChange works after canceling a two-choice message (confirm).

norio kondo
Tera Contributor

When I perform the following operations on a screen implemented in Workspace, the event in (5) occurs.
Please let us know the cause of the problem and how to deal with it.
Environment: Utah patch7a


(1) Manually enter a code value in the reference item "A code" and select the candidate displayed (focus out).
(2) Display a two-choice message (confirm) in the client script (onChange).
(3) Select "Cancel" in the two-choice message (the subsequent process of onChange returns the A code to the one before the change).
(4) The two-choice message is closed and the "A code" is restored to its original value.
(5) If you click on the appropriate area on the screen, the same two-choice message is displayed again.


The client script (onChange) updates "A code" in the client script (onChange), so that the client script (onChange) is called triggered by it is already taken care of (controlled by g_scratchpad.isCanceled).
*It is not reproduced when the magnifying glass of "A code" is clicked => A code is selected on the child screen.

Code Example

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    if (g_scratchpad.isCanceled) {
        g_scratchpad.isCanceled = false;
        return;
    }

    if (g_scratchpad.previousValue != newValue {
        getMessage('MessageXXXXX', function(msg) {
            if (confirm(msg)) {
                g_scratchpad.previousValue = newValue;
            } else {
                g_scratchpad.isCanceled = true;
                if (g_scratchpad.previousValue != undefined) {
                    g_form.setValue('u_code_A', g_scratchpad.previousValue); // "A code"
                } else {
                    g_form.setValue('u_code_A', oldValue); // "A code"
                }
            }
        });
    }

 

6 REPLIES 6

Amit Gujarathi
Giga Sage
Giga Sage

HI @norio kondo ,
I trust you are doing great.
Please try with below updated code :

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '' || g_scratchpad.isCanceled) {
        return;
    }

    // Debounce mechanism (adjust the time as needed)
    if (g_scratchpad.debounce) {
        clearTimeout(g_scratchpad.debounce);
    }

    g_scratchpad.debounce = setTimeout(function() {
        if (g_scratchpad.previousValue != newValue) {
            getMessage('MessageXXXXX', function(msg) {
                if (confirm(msg)) {
                    g_scratchpad.previousValue = newValue;
                } else {
                    g_scratchpad.isCanceled = true;
                    revertValue(oldValue);
                    g_scratchpad.isCanceled = false; // Reset the flag after reverting
                }
            });
        }
    }, 300); // 300 milliseconds

    function revertValue(oldValue) {
        if (g_scratchpad.previousValue !== undefined) {
            g_form.setValue('u_code_A', g_scratchpad.previousValue); // "A code"
        } else {
            g_form.setValue('u_code_A', oldValue); // "A code"
        }
    }
}

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



Thanks for your advice, it is much appreciated.
I have tried the above but have not been able to solve the problem.
The same event occurred after a short time.

newhand
Mega Sage

@norio kondo 
I have read your code ,and it seems you have already found the reason and fixed it ?
It works well on my instance..

 

Please mark my answer as correct and helpful based on Impact.

Thanks for your advice, I will try to get the problem fixed.
I see that the problem does not occur in your instance.
The problem still occurs in my environment.
I am developing in Japanese language, but I wonder if it has anything to do with it.