UI Action Script Issue

DEEPAK KUMAR SI
Tera Contributor

Hi All,

Need help in scripting.

Condition : UI Action to check if Closure Notes is Empty Of Not. If Empty Prompt for entering the values and then set the value of alert state to 100 and update the record and remain on Same page.

If not empty, set the value of alert state to 100 and update the record and remain on Same page.

--------------------------------------

On Click - checkAndSave()
---------------------------------
function checkAndSave() {
    var closureNotes = g_form.getValue('u_closure_notes');
    if (closureNotes.trim() === '') {
        alert('Please enter a value for "Close Notes And Save the form".');
    } else {
        current.u_alert_state = 100;
        current.update();
        action.setRedirectURL(current);
    }
}
---------------------------------
Issue is that, it is prompting , but even after entering the values of closure notes and saving the form, when we click again, it again prompts instead of setting the value of alert state and update the record
3 REPLIES 3

HIROSHI SATOH
Mega Sage

Solution:

You need to correct the script to handle the update properly after the user enters the value in the "Closure Notes" field. Instead of directly using current in the client-side script, which doesn't work properly in UI Actions, you should use g_form.setValue and g_form.save.

Here’s an updated version of your script:

 

function checkAndSave() {
    var closureNotes = g_form.getValue('u_closure_notes');
    
    if (closureNotes.trim() === '') {
        alert('Please enter a value for "Closure Notes" and save the form.');
    } else {
        g_form.setValue('u_alert_state', 100);
        g_form.save();
    }
}

 

Hi @HIROSHI SATOH  it is still not working and keep prompting the alert even after entering the value of closure notes.

Is "g_form.getValue('u_closure_notes');" correctly retrieving the value?