Potential Bug for On Submit Task

Potential Bug for On Submit Task

I'm creating a time card system. 

Case 1: When users submit time for projects already reported  I want the form action to update time rather than create a new record

Case 2: If a project is not reported yet, the form will create a new record reporting project + time.

While I can do this with a stateless form, I need features of a normal form (validation, "Add" button on record view)

The the structure of my on submit code is as follows

check = time_entry_form[((month == input.month && project == input.project) && Reported_by == zoho.loginuserid)].count();

if (check  ==  1)
{
    fetch_record  =  time_entry_form  [((month == input.month && project == input.project) && Reported_by == zoho.loginuserid)];

    fetch_record.hours = (input.hours  +  fetch_record.hours);

    delete from time_entry_form[ ID == input.ID ];
}

So the code first checks to see if a user has already reported project hours. If true, the code fetches that record and then updates the hours. To prevent the form from adding a new record, I run the delete task based on the current form's input.ID.

My observations:

If I attempt to add a project + time not already reported, on submit runs without errors but a record is not created. If I attempt to add hours to a project that is listed, a new record is created. It's like my code logic is backwards.

Debug:  I added " info check; ". 

In the case of a new project + time being added, info reports 1 rather than 0.  When I attempt to update hours for a project already listed, info reports 2 rather than 1 .

Workaround:

To correct this I had to add

check =  check - 1;

This is why I think it's a bug. Let me know if I'm crazy!

Cheers,
John Whitney