Why the field is returning the previus value in an catalog client script?

Community Alums
Not applicable

Hello! I have an Onsubmit catalog client script on portal, in the script there is an alert that is showing twice, so with this i understand that the client is running twice. In portal, when the user change the current value of the field and press on SAVE button, the alert in the first run is showing the current value but the second run is showing the previus value. Any idea why this is happening? 

6 REPLIES 6

Shubham Singh
Mega Guru

Hi @Community Alums 

 

It will be good if you can share the code you have written on the client script.

Check if there is any restriction on any value you are trying to set during the form submission.

 

Thanks!

Community Alums
Not applicable

Hi @Shubham Singh ! Yes of course:

function onSubmit() {
 
    var test1 = g_form.getValue('test1');
    var test2= g_form.getValue('test2');

 
    if (test1 != 'TE' && test != 'AP') {
 
        var multiRowVariableSet = JSON.parse(g_form.getValue('details')); //multirow variable set
        var grandTotal = g_form.getValue('u_total');
        var totalCost = 0;
 
        for (var i = 0; i < multiRowVariableSet.length; i++) {
            totalCost += parseFloat(multiRowVariableSet[i].total_exp); //variable of multirow
        }
 
        g_form.setValue("u_total", totalCost); //grand total variable outside of multirow
 
    }
}

@Community Alums 

 

There is a typo in your if statement condition. I can see a test variable that is undefined.

if (test1 != 'TE' && test != 'AP') {

----your code------

}

 

function onSubmit() {
 
    var test1 = g_form.getValue('test1');
    var test2= g_form.getValue('test2');

 
    if (test1 != 'TE' && test != 'AP') {
 
        var multiRowVariableSet = JSON.parse(g_form.getValue('details')); //multirow variable set
        var grandTotal = g_form.getValue('u_total');
        var totalCost = 0;
 
        for (var i = 0; i < multiRowVariableSet.length; i++) {
            totalCost += parseFloat(multiRowVariableSet[i].total_exp); //variable of multirow
        }
 
        g_form.setValue("u_total", totalCost); //grand total variable outside of multirow
 
    }
}

 

 Thanks!

 

Mark it as correct and helpful if it works 🙂

Community Alums
Not applicable

I changed that and is not working 😞