How Do I Properly Increment a Field?

chriscorbett
Giga Contributor

Hello All -

I have a table that has three fields: u_date, u_total and u_total_amount

u_total_amount is a calculated field based on u_total.

I am trying to write a Client Script that checks the table for an existing date. If the date is not in the table, a new record is inserted. I have this part working in the code below. Where I am running into difficulty is with a record for an existing date. If the date exists, I want to increment u_total by one.

Here is what I have so far:

function onSubmit() {

      var dateNow = g_form.getValue('u_entry_date');

      var dateCheck = new GlideRecord('u_daily_totals');

      dateCheck.addQuery('u_date',dateNow);

      dateCheck.query();

              if (dataCheck.get(current.u_total)){

              ******************

              This is where I am having trouble

            *******************

      } else {

              var insertRec = new GlideRecord('u_daily_totals');

              insertRec.initialize();

              insertRec.u_date = dateNow;

              insertRec.insert();

      }

}

The starred section is where I'm having problems. I cannot figure out how to read in the u_total value of the current record, increment it by one and save it back to the u_total field.

Any help the community could provide would be appreciated!

11 REPLIES 11

Many Many Thanks Chuck!



I got it to do what I wanted with a slight modification:




if (tot.next()) {


      tot.u_image_total++;       <---------   to actually increment the field


        tot.u_image_total += current.u_image_total;        


        tot.update();



}



Outside of that it worked great. Thanks for setting me straight!


You are welcome Chris. Don't forget to mark my response helpful and/or correct so others can find it easily in the future.