Autoform update method : how to add extra fields to the "modifier" argument


#1

I have an autoform calling the following method on submit:

  updateChartAf: function (modifier, theId) {
    return Chart.update(theId, modifier);
  },

modifier is:

{ '$set': 
{ 'demographics.lastName': 'Smith',
'demographics.firstName': 'Bill'}
}

So, I would like to add a field like:
‘lastUpdateDate’: new Date()

How would I do this?
Can I alter the $set information to include this new value prior to calling .update() ?


#2

Try modifier.$set.lastUpdateDate = new Date();


#3

Thanks, that was what I needed!.. the syntax just seemed weird being new to javascript. Also, part of my problem was that I had not added “lastUpdateDate” as a field in the schema, so it was not saving that field until I realized that and added the field to the schema!


#4

Any idea how this would be possible with a nested field?

For example, if the modifier looked like this…

{ ‘$set’:
{ ‘contactDetails.orderedBy’: ‘MvCun8p6vxndj3cr8’ }
}

I have unsuccessfully tried the following and am out of options…

var orderedBy = modifier.$set.contactDetails.orderedBy;
Result: TypeError: Cannot read property ‘orderedBy’ of undefined

var orderedBy = modifier.$set.'contactDetails.orderedBy';
Result: Unexpected token error

Is there any way to do this?
Thanks


#5

I’m stuck in a similar situation as you right now. By any chance, did you get this to work?


#6

this should work:

var modifier = { $set: { 'contactDetails.orderedBy': 'MvCun8p6vxndj3cr8' }};
var orderedBy = modifier.$set['contactDetails.orderedBy'];