[solved] Autoform - attach session value before insert not working?


#1

Situation

I’m using aldeed:autoform for inserts and updates.
Each document to be inserted needs:

  • The current userId (works)

  • A generated "productCountId"
    This gets generated when the user routes to the form and is then stored in a Session.

To attach these values to the inserted document I use AutoForm.addHooks().

Problem

I can’t get the Session value in the “before insert” hook.

Currently my code looks like this:

var addProductHooks = {
  before: {
    insert: function(doc) {
      doc.productCountId = Session.get('productCountId');
      doc.owner = Meteor.userId();
      return doc;
    }
  },
  onSuccess: function() {
    Router.go('/products_add_success');
  }
}

AutoForm.addHooks('product_from_add', addProductHooks);

Why cant i get the Session like this?
Many thanks for your help.


#2

Okay, I found my error:
I simply forgot to add the productCountId to my Schema. :-/