Reset a glide_duration field to zero from a UI Action

Jerome MAISETTI
Mega Guru

Hello All
I would like to have a button to reset a value type glide_duration in the ast_service table.

I have written the below code but it doesn't work, value doesn't reset

function ResetYearlyChangeHoursFunction() {
//g_form.setValue('u_used_yearly_change_hours','0 00:00:00');
var zero = gs.getDurationDate('0 0:0:0');
var usedHours = current.u_used_yearly_change_hours;
usedHours = '0 0:0:0';
//current.u_used_yearly_change_hours = zero;
//g_form.clearValue('u_used_yearly_change_hours');
action.setRedirectURL(current);
gs.addInfoMessage("Used Yealy Change Hours are now back to zero");
}

 

Can someone help me ? 🙂

 

Thanks!

Jérôme

1 ACCEPTED SOLUTION

Sai Shravan
Mega Sage

Hi @Jerome MAISETTI ,

 

It seems like the code you've written doesn't actually update the 'u_used_yearly_change_hours'field with the new duration value. You have only defined a variable zero with the value of 0 duration, and then set the 'usedHours' variable to the string '0 0:0:0'.

To actually reset the value of the "u_used_yearly_change_hours" field, you can try the following code:

function ResetYearlyChangeHoursFunction() {
    // Get 0 duration value
    var zeroDuration = gs.getDuration('0 0:0:0');
    
    // Set the value of u_used_yearly_change_hours to 0 duration
    current.u_used_yearly_change_hours = zeroDuration;
    current.update();
    
    // Redirect to the same record to refresh the UI
    action.setRedirectURL(current);
    
    gs.addInfoMessage("Used Yearly Change Hours have been reset to zero.");
}

In this updated code, we first use the 'gs.getDuration()' method to get the 0 duration value. Then, we set the 'u_used_yearly_change_hours' field on the current record to this 0 duration value and save the record using current.update(). Finally, we redirect to the same record to refresh the UI and display the success message.

Regards,
Shravan

Regards,
Shravan
Please mark this as helpful and correct answer, if this helps you

View solution in original post

2 REPLIES 2

Sai Shravan
Mega Sage

Hi @Jerome MAISETTI ,

 

It seems like the code you've written doesn't actually update the 'u_used_yearly_change_hours'field with the new duration value. You have only defined a variable zero with the value of 0 duration, and then set the 'usedHours' variable to the string '0 0:0:0'.

To actually reset the value of the "u_used_yearly_change_hours" field, you can try the following code:

function ResetYearlyChangeHoursFunction() {
    // Get 0 duration value
    var zeroDuration = gs.getDuration('0 0:0:0');
    
    // Set the value of u_used_yearly_change_hours to 0 duration
    current.u_used_yearly_change_hours = zeroDuration;
    current.update();
    
    // Redirect to the same record to refresh the UI
    action.setRedirectURL(current);
    
    gs.addInfoMessage("Used Yearly Change Hours have been reset to zero.");
}

In this updated code, we first use the 'gs.getDuration()' method to get the 0 duration value. Then, we set the 'u_used_yearly_change_hours' field on the current record to this 0 duration value and save the record using current.update(). Finally, we redirect to the same record to refresh the UI and display the success message.

Regards,
Shravan

Regards,
Shravan
Please mark this as helpful and correct answer, if this helps you

Thanks a lot! That worked 🙂