chicks / sugarcrm

A ruby based REST Client for SugarCRM
MIT License
90 stars 64 forks source link

"Team name cannot be blank" when adding a new contact #53

Closed alexdesi closed 13 years ago

alexdesi commented 13 years ago

When I try to Add a Contact to an Account, exactly as in https://github.com/chicks/sugarcrm#readme, I get the message "Team name cannot be blank":

irb-shell > a.contacts << c SugarCRM::InvalidRecord: Team name cannot be blank, Team count cannot be blank from /home/banjo/.rvm/gems/ruby-1.8.7-p334/gems/sugarcrm-0.9.14/lib/sugarcrm/attributes/attribute_methods.rb:158:in save_modified_attributes!' from /home/banjo/.rvm/gems/ruby-1.8.7-p334/gems/sugarcrm-0.9.14/lib/sugarcrm/base.rb:169:in save!' from /home/banjo/.rvm/gems/ruby-1.8.7-p334/gems/sugarcrm-0.9.14/lib/sugarcrm/associations/association_collection.rb:68:in<<' from (irb):135

Any idea about that ?

Thanks, Alessandro

chicks commented 13 years ago

Sure - you are hitting a validation error. The gem enforces "module required fields" when you try and save a record (required fields can be changed in SugarCRM Studio). You'll need to set Team Name and Team Count before your save will work. You can view the required fields on an object with:

SugarCRM::Contact.new.required_fields
 => [:last_name] 

I'm not sure what team_count is used for, but you can try setting it to 0.

BTW, teams are in Pro and Enterprise versions only (which we don't test against) which is why the example doesn't exactly line up with what you are trying to do.

davidsulc commented 13 years ago

To expand on chicks' answer, the gem will check for required fields and expose the results much like rails would:

c = SugarCRM::Contact.new
c.valid? # => false
c.errors # => {"last_name" => ["cannot be blank"]}

The error you're seeing is from the fact that the record isn't valid before save! is called on it. You can either specify a team name and count (possibly automatically by extending the gem, as detailed at http://davidsulc.com/blog/2011/04/05/ruby-gem-for-sugarcrm-advanced-use/), or try to remove the requirements in the SugarCRM Studio interface.

alexdesi commented 13 years ago

Yes, it is on Pro version, thank you for your suggestions ! now it works :) Alessandro