Incrementing a value


#1

First - thanks for your help. New to the whole Geckoboard experience. Looking to fire one-off changes to a gecko board data set from AWS Lambda.

Assuming I had a dataset like this whose tuple is { date , count }:

 gecko.datasets.findOrCreate({
    id: 'drip.subscribers',
    fields: {
        date: {
            type: 'date',
            name: 'Date'
        },
        quantity: {
            type: 'number',
            name: 'Lead Count',
        }
    }
}, function(err,dataset){
    if( err ){
        statusCallback(err);
        return;
    }
});

Which function could I leverage to gradually increment a ‘date’ value? All I’m looking to do, is +1 the quantity value for current day.

Thanks for helping me get started!


#2

Hi @Saeven, thanks for reaching out here. You can use the Date class to get the current date:

new Date().toISOString() which returns e.g. '2017-06-28T22:42:40.800Z'. To format it as a date string, you can use new Date().toISOString().slice(0, 10) which returns e.g. 2017-06-28.

gecko.datasets.findOrCreate({
  id: 'drip.subscribers',
  fields: {
    date: {
      type: 'date',
      name: 'Date'
    },
    quantity: {
      type: 'number',
      name: 'Lead Count',
    }
  }
}, function(err, dataset) {
  if (err) {
    statusCallback(err);
    return;
  }
  const data = [
    {
      date: new Date().toISOString().slice(0,10),
      quantity: 10,
    },
  ];

  dataset.post(data, function(err) {
    if (err) {
      statusCallback(err);
      return;
    }
  });
});

I hope that helps and answers your question! Let me know if you need any further help.