chicks / sugarcrm Goto Github PK
View Code? Open in Web Editor NEWA ruby based REST Client for SugarCRM
License: MIT License
A ruby based REST Client for SugarCRM
License: MIT License
Documented with SugarCRM as bug 43340
If a user creates a relationship and then deletes it, the vardefs.ext.php (e.g. for Contacts module: custom/modules/Contacts/Ext/Vardefs/vardefs.ext.php) aren't updated properly: the link is still present in the vardefs file, even if the join tables are deleted.
This link_field (for an inexistent relationship) is returned when the REST API for get_module_fields is called, which pollutes the link_field namespace and can make it impossible to access the desired relationship programmatically (e.g. REST API wrapper).
Steps to reproduce:
Proposed solution: when deleting a relationship in Studio, make sure the vardefs for the modules get updated correctly.
When booting up the server or the console I keep getting the following error:
Any ideas on what may be causing it? I already have all of the requirements met.
undefined method `class_attribute' for SugarCRM::Base:Class
/Library/Ruby/Gems/1.8/gems/sugarcrm-0.9.10/lib/sugarcrm/base.rb:10: undefined method class_attribute' for SugarCRM::Base:Class (NoMethodError) from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in
gem_original_require'
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in require' from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:156:in
require'
from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:521:in new_constants_in' from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:156:in
require'
from /Library/Ruby/Gems/1.8/gems/sugarcrm-0.9.10/lib/sugarcrm.rb:19
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in gem_original_require' from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in
require'
from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:156:in require' from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:521:in
new_constants_in'
from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:156:in require' from /Library/Ruby/Gems/1.8/gems/rails-2.3.8/lib/rails/gem_dependency.rb:215:in
load'
from /Library/Ruby/Gems/1.8/gems/rails-2.3.8/lib/initializer.rb:307:in load_gems' from /Library/Ruby/Gems/1.8/gems/rails-2.3.8/lib/initializer.rb:307:in
each'
from /Library/Ruby/Gems/1.8/gems/rails-2.3.8/lib/initializer.rb:307:in load_gems' from /Library/Ruby/Gems/1.8/gems/rails-2.3.8/lib/initializer.rb:169:in
process'
from /Library/Ruby/Gems/1.8/gems/rails-2.3.8/lib/initializer.rb:113:in send' from /Library/Ruby/Gems/1.8/gems/rails-2.3.8/lib/initializer.rb:113:in
run'
from /Users/billy/Sites/incarcerate/config/environment.rb:9
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in gem_original_require' from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in
require'
from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:156:in require' from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:521:in
new_constants_in'
from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:156:in require' from /Library/Ruby/Gems/1.8/gems/rails-2.3.8/lib/commands/server.rb:84 from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in
gem_original_require'
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
from script/server:3
Steps followed:
require 'sugarcrm' (produces the following error)
NoMethodError: undefined method `class_attribute' for SugarCRM::Base:Class
from /usr/local/lib/ruby/gems/1.8/gems/sugarcrm-0.6.1/lib/sugarcrm.rb:25
Rails version is 2.3.3
Always returns 0 when conditions are given on custom attributes. Gem will raise an error instead of returning erroneous results.
Work around: use Base.all(...).size (i.e. query all results and count them).
Issue documented with SugarCRM as bug 43339
It's easier to explain this issue with an example:
expiration_date_c is a field I added in Account Module (in Sugar web interface)
In the console:
acc = SugarCRM::Account.find_by_name 'My Account'
put acc.expiration_date_c
=> '03/06/2011"
c = SugarCRM::Contact.find_by_last_name 'User_in_My_Account'
puts c.accounts.first.exiration_date_c (note: the only account is My Account)
=> nil (should be '03/06/2011")
Note: the accounts ID are the same, the object should be the same:
(acc.id == c.accounts.first.id)
=> true
Is this a bug ? or I am overlooking something ?
Alexdesi
What would the best practice for adding methods to a module be. Like if I wanted to add methods to SugarCRM::Opportunities. Normally in AR, I would just subclass it, but the queries return SugarCRM::Opportunities, which wouldn't have my methods.
Attempting to use the gem to upload a simple excel (.xls) document fails. Verified that CSV works. Looks like there is an error somewhere the gem tries to convert the xls to_json. Additionally, I have seen that it works with SOME pdf files, not with others.
require 'test_helper'
class TestDocumentAttachment < ActiveSupport::TestCase
context "A SugarCRM.connection" do
should "1. Create a CSV Document" do
csvfile = File.read("../tmp/m_accounts.csv")
assert csvfile.to_json
csv = SugarCRM::Document.new
csv.active_date = Date.today,
csv.document_name = "test_excel.xls"
csv.filename = "test_excel.xls"
csv.revision = 0
csv.uploadfile = csvfile
csv.save
assert !csv.new?
end
should "2. Create an Excel Document" do
excelfile = File.read("../tmp/test_excel.xls")
assert excelfile.to_json
excelfile = SugarCRM::Document.new
excelfile.active_date = Date.today,
excelfile.document_name = "test_excel.xls"
excelfile.filename = "test_excel.xls"
excelfile.revision = 0
excelfile.uploadfile = excelfile
excelfile.save
assert !excelfile.new?
end
end
end
Finished in 1.720047 seconds.
1) Error:
test: A SugarCRM.connection should 2. Create an Excel Document. (TestDocumentAttachment):
ArgumentError: redundant UTF-8 sequence
2 tests, 2 assertions, 0 failures, 1 errors
cfrugard@cfrugard-laptop:~/projects/sugar/test$
Loaded suite unit/sugar_document_test
Started
E
Finished in 0.780885 seconds.
1 tests, 1 assertions, 0 failures, 1 errors
Is it possible this is because I am using version 6.0.3? I tried omitting the second argument, which seems to make it work, but I get a "Invalid File Reference" when trying to bring up the document.
I don't believe some special characters are being escaped when attempting to do a set entry from the save! method. I've found this to be the case when putting an ampersand (&) in a string. In my situation I was creating a new user with the department as 'G&A' and the server won't accept it, I get a SugarCRM::InvalidRequest with all the json saying it is invalid.
Need to double check JSON for accuracy. For instance, the login request will fail because of an extra comma on line 10 of login.rb.
I used the SugarCRM gem with IRB, and it works well.
I know the documentation says:
"The SugarCRM Ruby gem relies on ActiveSupport >= 3, and therefore isn’t compatible with Rails 2"
but I need to use it in a Rails 2.3.9 app.
I can't use: Run 'rails g sugarcrm:config' to generate the config, of course I can create manually the config file, but will it work ?
How I can do that ? there is some workaround to use SugarCRM in Rails 2 ?
Many Thanks
Alessandro
Hello,
I was wondering if there was a way to speed up requests? I will give an example...
mysugar::Contacts.all.each do |contact|
puts "contact id: #{contact.id}"
end
This works fast. Looks like only one request is done. But if I change the puts statement to be this:
puts "account id: #{contact.account_id}"
Then it looks like it does a separate request for each contact that is returned, because account_id is referring to a different model. The result is very slow. I also tried changing the request to be this:
mysugar::Contacts.all do |contact|
But the result was the same. In rails (active record) there is a thing called 'eager loading' which I tried but it didn't seem to make a difference. Is there any way to make the above request faster?
Hi all, when getting a Contact, the account_id field is nil in sugarcrm 6.2. In 6.1 this worked fine. Here is my relevant code:
@sugar::Contact.all.each do |contact|
puts contact: #{contact.inspect}"
end
Here is some of the request:
get_entry_list: Request:
{
"session": "ltpn47ihvbgupo5ubfm9lb3qo5",
"module_name": "Contacts",
"query": "",
"order_by": "date_entered",
"offset": "",
"select_fields": ["assigned_user_id","assistant_phone","phone_home","date_modified","alt_address_postalcode","accept_status_id","team_set_id","picture","description","email1","ti
tle","primary_address_city","assigned_user_name","alt_address_state","reports_to_id","email2","report_to_name","primary_address_state","department","cec_bcse_c","assistant","sync_c
ontact","email_and_name1","team_name","accept_status_name","phone_mobile","c_accept_status_fields","account_name","phone_other","alt_address_country","modified_by_name","last_name"
,"designer_c","alt_address_city","account_id","name","do_not_call","date_entered","team_count","m_accept_status_fields","birthdate","swh_installer_c","created_by_name","phone_fax",
"alt_address_street_2","campaign_name","deleted","salutation","alt_address_street_3","primary_address_street_2","invalid_email","primary_address_street_3","email_opt_out","electric
ian_c","modified_user_id","created_by","first_name","opportunity_role_fields","team_id","opportunity_role_id","opportunity_role","lead_source","full_name","primary_address_country","primary_address_street","primary_address_postalcode","alt_address_street","phone_work","id","campaign_id"],
"link_name_to_fields_array": [],
"max_results": "5",
"deleted": 0
}
and now part of the response:
get_entry_list: JSON Response:
{"entry_list"=>
[{"name_value_list"=>
{"primary_address_postalcode"=>
{"name"=>"primary_address_postalcode", "value"=>""},
"primary_address_street"=>
{"name"=>"primary_address_street", "value"=>""},
...
"salutation"=>{"name"=>"salutation", "value"=>""},
"account_id"=>{"name"=>"account_id", "value"=>""},
"report_to_name"=>{"name"=>"report_to_name", "value"=>""},
"date_modified"=>
{"name"=>"date_modified", "value"=>"2011-04-14 04:49:31"},
When I do this manually without the gem, the account_id is returned correctly. Granted, this is the latest beta version of sugar but thought I would submit this report anyway because doing it without the gem using direct get_entry_list() call works as expected.
Thanks =)
Documented at Sugar with 43341
When creating a relationship in Studio, the user can specify a label for the related modules.
Currently the REST API get_module_fields doesn't return this label, making it impossible for services to differentiate between multiple relationships between two same modules (e.g. 2 relationship between contacts and accounts where once the accounts are "suppliers" and once they are "customers").
Proposed evolution: return label given to relationship with get_module_fields.
When querying an object for its joined objects through a custom relationship, the returned objects dont have many attributes set properly, except the id. Verified below by doing a find on the record by id afterward to show the fully populated object. Notice, for example, the types_c field. This is in the HEAD version, the 0.98 version doesn't seem able to find objects through the custom relationship.
irb(main):058:0> o = SugarCRM::Opportunity.find_by_name("Spend Thrift Inc - 1000 units")
=> #<SugarCRM::Opportunity account_id: nil, account_name: "Spend Thrift Inc", amount: "50000", amount_usdollar: "50000", assigned_user_id: "seed_chris_id", assigned_user_name: "Chris Olliver", campaign_id: "", campaign_name: nil, created_by: "1", created_by_name: "Sidrera Administrator", currency_id: "-99", currency_name: "", currency_symbol: "", date_closed: "2011-06-27", date_entered: "2011-01-25 18:20:54", date_modified: "2011-01-25 18:20:54", deleted: false, description: "", id: "209f01de-02f1-99ce-319c-4d3f1474d270", lead_source: "Employee", modified_by_name: "Sidrera Administrator", modified_user_id: "1", name: "Spend Thrift Inc - 1000 units", next_step: "", opportunity_type: "", probability: 10, sales_stage: "Negotiation/Review", sid1_contact_types_opportunities_name: "", team_count: "3", team_id: "East", team_name: "East ", team_set_id: "539b4447-b5c3-c71e-78bc-4d3f142190fa">
irb(main):069:0> o.opportunities_sid1_contact_types.first
=> #<SugarCRM::Sid1ContactType assigned_user_id: nil, assigned_user_name: " ", created_by: "1", created_by_name: "Sidrera Administrator", date_entered: "2011-01-25 18:50:09", date_modified: "2011-01-25 18:50:09", deleted: false, description: nil, id: "1e2c6e67-e8c8-281e-bfbd-4d3f1b21cda2", modified_by_name: "Sidrera Administrator", modified_user_id: "1", name: nil, opportunities_sid1_contact_types_name: " ...", sid1_contact_types_contacts_name: " ...", sid1_contact_types_opportunities_name: nil, team_count: "1", team_id: "1", team_name: "Global ", team_set_id: "1", types_c: nil>
irb(main):070:0>SugarCRM::Sid1ContactType.find(o.opportunities_sid1_contact_types.first.id)
=> #<SugarCRM::Sid1ContactType assigned_user_id: "", assigned_user_name: "", created_by: "1", created_by_name: "Sidrera Administrator", date_entered: "2011-01-25 18:50:09", date_modified: "2011-01-25 18:50:09", deleted: false, description: "", id: "1e2c6e67-e8c8-281e-bfbd-4d3f1b21cda2", modified_by_name: "Sidrera Administrator", modified_user_id: "1", name: "", opportunities_sid1_contact_types_name: "Spend Thrift Inc - 1000 units", sid1_contact_types_contacts_name: "Jaime Wanner", sid1_contact_types_opportunities_name: "", team_count: nil, team_id: "1", team_name: "Global", team_set_id: "1", types_c: "^a_loc^,^z_loc^">
irb(main):071:0>
Hi,
I am using ruby "ruby 1.9.2p180 (2011-02-18) [x86_64-darwin10.7.0]" on Mac "Darwin Zia-Ul-Hudas-iMac.local 10.7.0 Darwin Kernel Version 10.7.0: Sat Jan 29 15:17:16 PST 2011; root:xnu-1504.9.37~1/RELEASE_I386 i386".
I have been trying to use the sugarcrm gem through console but always in the end get the message Invalid session id. Here is my example request:
$ rails c
Loading development environment (Rails 3.1.0.rc1)
irb(main):001:0> SugarCRM.connect(url, username, password)
=> SugarCRM::Namespace0
irb(main):002:0> SugarCRM.connection.debug = true
=> true
irb(main):003:0> SugarCRM.reload!
Reloading...
=> true
irb(main):004:0> SugarCRM.current_user
get_module_fields: Request:
{
"session": "m3m592mv97fs5t9shsh341hm21",
"module_name": "Users"
}
login: Request:
{
"user_auth": {
"user_name": "admin",
"password": "f6defee0f09a42cedaf73deb450bf5db",
"version": 2
},
"application": "sugarcrm_rubygem"
}
login: JSON Response:
{"id"=>"u0p45oen7snoclc2j339q6kcd5",
"module_name"=>"Users",
"name_value_list"=>
{"user_id"=>{"name"=>"user_id", "value"=>"1"},
"user_name"=>{"name"=>"user_name", "value"=>"admin"},
"user_language"=>{"name"=>"user_language", "value"=>"en_us"},
"user_currency_id"=>{"name"=>"user_currency_id", "value"=>"-99"},
"user_currency_name"=>
{"name"=>"user_currency_name", "value"=>"US Dollars"}}}
get_module_fields: Request:
{
"session": "m3m592mv97fs5t9shsh341hm21",
"module_name": "Users"
}
get_module_fields: JSON Response:
{"module_name"=>"Users",
"module_fields"=>
{"id"=>
{"name"=>"id", "type"=>"id", "label"=>"ID", "required"=>1, "options"=>[]},
"user_name"=>
{"name"=>"user_name",
"type"=>"user_name",
"label"=>"User Name",
"required"=>0,
"options"=>[]},
"user_hash"=>
{"name"=>"user_hash",
"type"=>"varchar",
"label"=>"Password",
"required"=>0,
"options"=>[]},
"system_generated_password"=>
{"name"=>"system_generated_password",
"type"=>"bool",
"label"=>"System Generated Password",
"required"=>1,
"options"=>[]},
"pwd_last_changed"=>
{"name"=>"pwd_last_changed",
"type"=>"datetime",
"label"=>"password last changed",
"required"=>0,
"options"=>[]},
"authenticate_id"=>
{"name"=>"authenticate_id",
"type"=>"varchar",
"label"=>"Authentication Id",
"required"=>0,
"options"=>[]},
"sugar_login"=>
{"name"=>"sugar_login",
"type"=>"bool",
"label"=>"Is Sugar User",
"required"=>0,
"options"=>[],
"default_value"=>"1"},
"first_name"=>
{"name"=>"first_name",
"type"=>"name",
"label"=>"First Name",
"required"=>0,
"options"=>[]},
"last_name"=>
{"name"=>"last_name",
"type"=>"name",
"label"=>"Last Name",
"required"=>1,
"options"=>[]},
"full_name"=>
{"name"=>"full_name",
"type"=>"name",
"label"=>"Full Name",
"required"=>0,
"options"=>[]},
"name"=>
{"name"=>"name",
"type"=>"varchar",
"label"=>"Full Name",
"required"=>0,
"options"=>[]},
"reports_to_id"=>
{"name"=>"reports_to_id",
"type"=>"id",
"label"=>"Reports to ID:",
"required"=>0,
"options"=>[]},
"reports_to_name"=>
{"name"=>"reports_to_name",
"type"=>"relate",
"label"=>"Reports to",
"required"=>0,
"options"=>[]},
"is_admin"=>
{"name"=>"is_admin",
"type"=>"bool",
"label"=>"Is Administrator",
"required"=>0,
"options"=>[],
"default_value"=>"0"},
"external_auth_only"=>
{"name"=>"external_auth_only",
"type"=>"bool",
"label"=>"External Authentication",
"required"=>0,
"options"=>[],
"default_value"=>"0"},
"receive_notifications"=>
{"name"=>"receive_notifications",
"type"=>"bool",
"label"=>"Notify on Assignment",
"required"=>0,
"options"=>[],
"default_value"=>"1"},
"description"=>
{"name"=>"description",
"type"=>"text",
"label"=>"Description",
"required"=>0,
"options"=>[]},
"date_entered"=>
{"name"=>"date_entered",
"type"=>"datetime",
"label"=>"Date Created:",
"required"=>1,
"options"=>[]},
"date_modified"=>
{"name"=>"date_modified",
"type"=>"datetime",
"label"=>"Date Modified:",
"required"=>1,
"options"=>[]},
"modified_user_id"=>
{"name"=>"modified_user_id",
"type"=>"assigned_user_name",
"label"=>"Modified By ID",
"required"=>0,
"options"=>[]},
"modified_by_name"=>
{"name"=>"modified_by_name",
"type"=>"assigned_user_name",
"label"=>"Modified By ID",
"required"=>0,
"options"=>[]},
"created_by"=>
{"name"=>"created_by",
"type"=>"assigned_user_name",
"label"=>"Assigned to:",
"required"=>0,
"options"=>[]},
"created_by_name"=>
{"name"=>"created_by_name",
"type"=>"assigned_user_name",
"label"=>"Assigned to:",
"required"=>0,
"options"=>[]},
"title"=>
{"name"=>"title",
"type"=>"varchar",
"label"=>"Title",
"required"=>0,
"options"=>[]},
"department"=>
{"name"=>"department",
"type"=>"varchar",
"label"=>"Department",
"required"=>0,
"options"=>[]},
"phone_home"=>
{"name"=>"phone_home",
"type"=>"phone",
"label"=>"Home Phone",
"required"=>0,
"options"=>[]},
"phone_mobile"=>
{"name"=>"phone_mobile",
"type"=>"phone",
"label"=>"Mobile",
"required"=>0,
"options"=>[]},
"phone_work"=>
{"name"=>"phone_work",
"type"=>"phone",
"label"=>"Work Phone",
"required"=>0,
"options"=>[]},
"phone_other"=>
{"name"=>"phone_other",
"type"=>"phone",
"label"=>"Other Phone",
"required"=>0,
"options"=>[]},
"phone_fax"=>
{"name"=>"phone_fax",
"type"=>"phone",
"label"=>"Fax",
"required"=>0,
"options"=>[]},
"status"=>
{"name"=>"status",
"type"=>"enum",
"label"=>"Status",
"required"=>0,
"options"=>
{"Active"=>{"name"=>"Active", "value"=>"Active"},
"Inactive"=>{"name"=>"Inactive", "value"=>"Inactive"}}},
"address_street"=>
{"name"=>"address_street",
"type"=>"varchar",
"label"=>"Address Street",
"required"=>0,
"options"=>[]},
"address_city"=>
{"name"=>"address_city",
"type"=>"varchar",
"label"=>"Address City",
"required"=>0,
"options"=>[]},
"address_state"=>
{"name"=>"address_state",
"type"=>"varchar",
"label"=>"Address State",
"required"=>0,
"options"=>[]},
"address_country"=>
{"name"=>"address_country",
"type"=>"varchar",
"label"=>"Address Country",
"required"=>0,
"options"=>[]},
"address_postalcode"=>
{"name"=>"address_postalcode",
"type"=>"varchar",
"label"=>"Address Postal Code",
"required"=>0,
"options"=>[]},
"deleted"=>
{"name"=>"deleted",
"type"=>"bool",
"label"=>"Deleted",
"required"=>0,
"options"=>[]},
"portal_only"=>
{"name"=>"portal_only",
"type"=>"bool",
"label"=>"Portal API User",
"required"=>0,
"options"=>[],
"default_value"=>"0"},
"employee_status"=>
{"name"=>"employee_status",
"type"=>"varchar",
"label"=>"Employee Status",
"required"=>0,
"options"=>[]},
"messenger_id"=>
{"name"=>"messenger_id",
"type"=>"varchar",
"label"=>"IM Name",
"required"=>0,
"options"=>[]},
"messenger_type"=>
{"name"=>"messenger_type",
"type"=>"varchar",
"label"=>"IM Type",
"required"=>0,
"options"=>[]},
"email1"=>
{"name"=>"email1",
"type"=>"varchar",
"label"=>"Email Address",
"required"=>1,
"options"=>[]},
"is_group"=>
{"name"=>"is_group",
"type"=>"bool",
"label"=>"Group User",
"required"=>0,
"options"=>[]},
"c_accept_status_fields"=>
{"name"=>"c_accept_status_fields",
"type"=>"relate",
"label"=>"Accept Status",
"required"=>0,
"options"=>[]},
"m_accept_status_fields"=>
{"name"=>"m_accept_status_fields",
"type"=>"relate",
"label"=>"Accept Status",
"required"=>0,
"options"=>[]},
"accept_status_id"=>
{"name"=>"accept_status_id",
"type"=>"varchar",
"label"=>"Accept Status",
"required"=>0,
"options"=>[]},
"accept_status_name"=>
{"name"=>"accept_status_name",
"type"=>"enum",
"label"=>"Accept Status",
"required"=>0,
"options"=>
{"accept"=>{"name"=>"accept", "value"=>"Accepted"},
"decline"=>{"name"=>"decline", "value"=>"Declined"},
"tentative"=>{"name"=>"tentative", "value"=>"Tentative"},
"none"=>{"name"=>"none", "value"=>"None"}}}},
"link_fields"=>
{"calls"=>
{"name"=>"calls",
"type"=>"link",
"relationship"=>"calls_users",
"module"=>"",
"bean_name"=>""},
"meetings"=>
{"name"=>"meetings",
"type"=>"link",
"relationship"=>"meetings_users",
"module"=>"",
"bean_name"=>""},
"contacts"=>
{"name"=>"contacts",
"type"=>"link",
"relationship"=>"contacts_users",
"module"=>"",
"bean_name"=>""},
"reports_to_link"=>
{"name"=>"reports_to_link",
"type"=>"link",
"relationship"=>"user_direct_reports",
"module"=>"",
"bean_name"=>""},
"email_addresses"=>
{"name"=>"email_addresses",
"type"=>"link",
"relationship"=>"users_email_addresses",
"module"=>"EmailAddress",
"bean_name"=>"EmailAddress"},
"email_addresses_primary"=>
{"name"=>"email_addresses_primary",
"type"=>"link",
"relationship"=>"users_email_addresses_primary",
"module"=>"",
"bean_name"=>""},
"aclroles"=>
{"name"=>"aclroles",
"type"=>"link",
"relationship"=>"acl_roles_users",
"module"=>"",
"bean_name"=>""},
"prospect_lists"=>
{"name"=>"prospect_lists",
"type"=>"link",
"relationship"=>"prospect_list_users",
"module"=>"ProspectLists",
"bean_name"=>""},
"holidays"=>
{"name"=>"holidays",
"type"=>"link",
"relationship"=>"users_holidays",
"module"=>"",
"bean_name"=>""},
"eapm"=>
{"name"=>"eapm",
"type"=>"link",
"relationship"=>"eapm_assigned_user",
"module"=>"",
"bean_name"=>""}}}
get_module_fields: JSON Response:
{"module_name"=>"Users",
"module_fields"=>
{"id"=>
{"name"=>"id", "type"=>"id", "label"=>"ID", "required"=>1, "options"=>[]},
"user_name"=>
{"name"=>"user_name",
"type"=>"user_name",
"label"=>"User Name",
"required"=>0,
"options"=>[]},
"user_hash"=>
{"name"=>"user_hash",
"type"=>"varchar",
"label"=>"Password",
"required"=>0,
"options"=>[]},
"system_generated_password"=>
{"name"=>"system_generated_password",
"type"=>"bool",
"label"=>"System Generated Password",
"required"=>1,
"options"=>[]},
"pwd_last_changed"=>
{"name"=>"pwd_last_changed",
"type"=>"datetime",
"label"=>"password last changed",
"required"=>0,
"options"=>[]},
"authenticate_id"=>
{"name"=>"authenticate_id",
"type"=>"varchar",
"label"=>"Authentication Id",
"required"=>0,
"options"=>[]},
"sugar_login"=>
{"name"=>"sugar_login",
"type"=>"bool",
"label"=>"Is Sugar User",
"required"=>0,
"options"=>[],
"default_value"=>"1"},
"first_name"=>
{"name"=>"first_name",
"type"=>"name",
"label"=>"First Name",
"required"=>0,
"options"=>[]},
"last_name"=>
{"name"=>"last_name",
"type"=>"name",
"label"=>"Last Name",
"required"=>1,
"options"=>[]},
"full_name"=>
{"name"=>"full_name",
"type"=>"name",
"label"=>"Full Name",
"required"=>0,
"options"=>[]},
"name"=>
{"name"=>"name",
"type"=>"varchar",
"label"=>"Full Name",
"required"=>0,
"options"=>[]},
"reports_to_id"=>
{"name"=>"reports_to_id",
"type"=>"id",
"label"=>"Reports to ID:",
"required"=>0,
"options"=>[]},
"reports_to_name"=>
{"name"=>"reports_to_name",
"type"=>"relate",
"label"=>"Reports to",
"required"=>0,
"options"=>[]},
"is_admin"=>
{"name"=>"is_admin",
"type"=>"bool",
"label"=>"Is Administrator",
"required"=>0,
"options"=>[],
"default_value"=>"0"},
"external_auth_only"=>
{"name"=>"external_auth_only",
"type"=>"bool",
"label"=>"External Authentication",
"required"=>0,
"options"=>[],
"default_value"=>"0"},
"receive_notifications"=>
{"name"=>"receive_notifications",
"type"=>"bool",
"label"=>"Notify on Assignment",
"required"=>0,
"options"=>[],
"default_value"=>"1"},
"description"=>
{"name"=>"description",
"type"=>"text",
"label"=>"Description",
"required"=>0,
"options"=>[]},
"date_entered"=>
{"name"=>"date_entered",
"type"=>"datetime",
"label"=>"Date Created:",
"required"=>1,
"options"=>[]},
"date_modified"=>
{"name"=>"date_modified",
"type"=>"datetime",
"label"=>"Date Modified:",
"required"=>1,
"options"=>[]},
"modified_user_id"=>
{"name"=>"modified_user_id",
"type"=>"assigned_user_name",
"label"=>"Modified By ID",
"required"=>0,
"options"=>[]},
"modified_by_name"=>
{"name"=>"modified_by_name",
"type"=>"assigned_user_name",
"label"=>"Modified By ID",
"required"=>0,
"options"=>[]},
"created_by"=>
{"name"=>"created_by",
"type"=>"assigned_user_name",
"label"=>"Assigned to:",
"required"=>0,
"options"=>[]},
"created_by_name"=>
{"name"=>"created_by_name",
"type"=>"assigned_user_name",
"label"=>"Assigned to:",
"required"=>0,
"options"=>[]},
"title"=>
{"name"=>"title",
"type"=>"varchar",
"label"=>"Title",
"required"=>0,
"options"=>[]},
"department"=>
{"name"=>"department",
"type"=>"varchar",
"label"=>"Department",
"required"=>0,
"options"=>[]},
"phone_home"=>
{"name"=>"phone_home",
"type"=>"phone",
"label"=>"Home Phone",
"required"=>0,
"options"=>[]},
"phone_mobile"=>
{"name"=>"phone_mobile",
"type"=>"phone",
"label"=>"Mobile",
"required"=>0,
"options"=>[]},
"phone_work"=>
{"name"=>"phone_work",
"type"=>"phone",
"label"=>"Work Phone",
"required"=>0,
"options"=>[]},
"phone_other"=>
{"name"=>"phone_other",
"type"=>"phone",
"label"=>"Other Phone",
"required"=>0,
"options"=>[]},
"phone_fax"=>
{"name"=>"phone_fax",
"type"=>"phone",
"label"=>"Fax",
"required"=>0,
"options"=>[]},
"status"=>
{"name"=>"status",
"type"=>"enum",
"label"=>"Status",
"required"=>0,
"options"=>
{"Active"=>{"name"=>"Active", "value"=>"Active"},
"Inactive"=>{"name"=>"Inactive", "value"=>"Inactive"}}},
"address_street"=>
{"name"=>"address_street",
"type"=>"varchar",
"label"=>"Address Street",
"required"=>0,
"options"=>[]},
"address_city"=>
{"name"=>"address_city",
"type"=>"varchar",
"label"=>"Address City",
"required"=>0,
"options"=>[]},
"address_state"=>
{"name"=>"address_state",
"type"=>"varchar",
"label"=>"Address State",
"required"=>0,
"options"=>[]},
"address_country"=>
{"name"=>"address_country",
"type"=>"varchar",
"label"=>"Address Country",
"required"=>0,
"options"=>[]},
"address_postalcode"=>
{"name"=>"address_postalcode",
"type"=>"varchar",
"label"=>"Address Postal Code",
"required"=>0,
"options"=>[]},
"deleted"=>
{"name"=>"deleted",
"type"=>"bool",
"label"=>"Deleted",
"required"=>0,
"options"=>[]},
"portal_only"=>
{"name"=>"portal_only",
"type"=>"bool",
"label"=>"Portal API User",
"required"=>0,
"options"=>[],
"default_value"=>"0"},
"employee_status"=>
{"name"=>"employee_status",
"type"=>"varchar",
"label"=>"Employee Status",
"required"=>0,
"options"=>[]},
"messenger_id"=>
{"name"=>"messenger_id",
"type"=>"varchar",
"label"=>"IM Name",
"required"=>0,
"options"=>[]},
"messenger_type"=>
{"name"=>"messenger_type",
"type"=>"varchar",
"label"=>"IM Type",
"required"=>0,
"options"=>[]},
"email1"=>
{"name"=>"email1",
"type"=>"varchar",
"label"=>"Email Address",
"required"=>1,
"options"=>[]},
"is_group"=>
{"name"=>"is_group",
"type"=>"bool",
"label"=>"Group User",
"required"=>0,
"options"=>[]},
"c_accept_status_fields"=>
{"name"=>"c_accept_status_fields",
"type"=>"relate",
"label"=>"Accept Status",
"required"=>0,
"options"=>[]},
"m_accept_status_fields"=>
{"name"=>"m_accept_status_fields",
"type"=>"relate",
"label"=>"Accept Status",
"required"=>0,
"options"=>[]},
"accept_status_id"=>
{"name"=>"accept_status_id",
"type"=>"varchar",
"label"=>"Accept Status",
"required"=>0,
"options"=>[]},
"accept_status_name"=>
{"name"=>"accept_status_name",
"type"=>"enum",
"label"=>"Accept Status",
"required"=>0,
"options"=>
{"accept"=>{"name"=>"accept", "value"=>"Accepted"},
"decline"=>{"name"=>"decline", "value"=>"Declined"},
"tentative"=>{"name"=>"tentative", "value"=>"Tentative"},
"none"=>{"name"=>"none", "value"=>"None"}}}},
"link_fields"=>
{"calls"=>
{"name"=>"calls",
"type"=>"link",
"relationship"=>"calls_users",
"module"=>"",
"bean_name"=>""},
"meetings"=>
{"name"=>"meetings",
"type"=>"link",
"relationship"=>"meetings_users",
"module"=>"",
"bean_name"=>""},
"contacts"=>
{"name"=>"contacts",
"type"=>"link",
"relationship"=>"contacts_users",
"module"=>"",
"bean_name"=>""},
"reports_to_link"=>
{"name"=>"reports_to_link",
"type"=>"link",
"relationship"=>"user_direct_reports",
"module"=>"",
"bean_name"=>""},
"email_addresses"=>
{"name"=>"email_addresses",
"type"=>"link",
"relationship"=>"users_email_addresses",
"module"=>"EmailAddress",
"bean_name"=>"EmailAddress"},
"email_addresses_primary"=>
{"name"=>"email_addresses_primary",
"type"=>"link",
"relationship"=>"users_email_addresses_primary",
"module"=>"",
"bean_name"=>""},
"aclroles"=>
{"name"=>"aclroles",
"type"=>"link",
"relationship"=>"acl_roles_users",
"module"=>"",
"bean_name"=>""},
"prospect_lists"=>
{"name"=>"prospect_lists",
"type"=>"link",
"relationship"=>"prospect_list_users",
"module"=>"ProspectLists",
"bean_name"=>""},
"holidays"=>
{"name"=>"holidays",
"type"=>"link",
"relationship"=>"users_holidays",
"module"=>"",
"bean_name"=>""},
"eapm"=>
{"name"=>"eapm",
"type"=>"link",
"relationship"=>"eapm_assigned_user",
"module"=>"",
"bean_name"=>""}}}
get_entry_list: Request:
{
"session": "u0p45oen7snoclc2j339q6kcd5",
"module_name": "Users",
"query": "users.user_name = 'admin'",
"order_by": "date_entered",
"offset": "",
"select_fields": ["id","user_name","user_hash","system_generated_password","pwd_last_changed","authenticate_id","sugar_login","first_name","last_name","full_name","name","reports_to_id","reports_to_name","is_admin","external_auth_only","receive_notifications","description","date_entered","date_modified","modified_user_id","modified_by_name","created_by","created_by_name","title","department","phone_home","phone_mobile","phone_work","phone_other","phone_fax","status","address_street","address_city","address_state","address_country","address_postalcode","deleted","portal_only","employee_status","messenger_id","messenger_type","email1","is_group","c_accept_status_fields","m_accept_status_fields","accept_status_id","accept_status_name"],
"link_name_to_fields_array": [],
"max_results": "1",
"deleted": 0
}
get_entry_list: JSON Response:
{"name"=>"Invalid Session ID",
"number"=>11,
"description"=>"The session ID is invalid"}
=> {"name"=>"Invalid Session ID", "number"=>11, "description"=>"The session ID is invalid"}
Every request i send turns out the above response. Its been 3 days now. Looking for some quick response. Am i missing some thing here. I tried to see why it was logging in again once it was successful. Turned out that first request gets the exception End of File reached in send! method of connection.
Looking for some help
Regards
Is there a module object "copy" or "clone" functionality?
Something like...
opp = SugarCRM::Opportunity.first
opp2 = opp.clone
Hello,
I am also having problems with queries with custom fields. I saw an issue on this that was closed a few weeks ago and am not sure if this is the same.
I have version 0.9.8 of sugarcrm
I have a custom field called: account_number_c
I am doing:
SugarCRM::Account.all({:conditions => {:account_number_c => "10000000"}})
And get
undefined method `account_number_c' for "Database failure. Please refer to sugarcrm.log for details.":String (NoMethodError)
In the log I see:
[FATAL] Error running count query for Account List: Query Failed: SELECT count(*) c FROM accou
nts LEFT JOIN accounts_cstm ON accounts.id = accounts_cstm.id_c LEFT JOIN users jt0 ON
jt0.id= accounts.modified_user_id AND jt0.deleted=0
AND jt0.deleted=0 LEFT JOIN users jt1 ON
jt1.id= accounts.created_by AND jt1.deleted=0
AND jt1.deleted=0 LEFT JOIN users jt2 ON
jt2.id= accounts.assigned_user_id AND jt2.deleted=0
AND jt2.deleted=0 LEFT JOIN accounts jt3 ON
jt3.id= accounts.parent_id AND jt3.deleted=0
AND jt3.deleted=0 LEFT JOIN campaigns jt4 ON
jt4.id= accounts.campaign_id AND jt4.deleted=0
AND jt4.deleted=0 LEFT JOIN users jt5 ON
jt5.id= accounts.modified_user_id AND jt5.deleted=0
AND jt5.deleted=0 where (.account_number_c = '10000000') AND accounts.deleted=0: MySQL error 1064: You have an error in your SQL syntax; check the manual that corres
ponds to your MySQL server version for the right syntax to use near '= '10000000') AND accounts.deleted=0' at line 13
Any help would be much appreciated. The gem is awesome.
Thanks!
The error comes when I do an account search by id
The feature set of this gem has grown immensely. I think we need to clean up the documentation and examples a bit.
We should also add examples for adding attachments to a record.
Any way to trigger password resets emails to users or send them on user creation? If I shouldn't be adding requests here, apologies.
Thanks
I am getting "false" when attempting this. Is this functionality in there, or does it just think I am doing a query that is returning no results?
(Edit: filed as SugarCRM bug 43342)
To reproduce:
If the same opportunity is retrieved directly, the field is returned properly (with the corresponding value).
It seems the issue comes from get_relationships: the case_number_c field isn't included in the response. (As I recall, it was properly returned in 5.5).
Chicks, can you confirm?
(This bug will have to be filed with SugarCRM, I wanted to confirm first.)
Removing the & allows the save to happen.
irb(main):086:0> a = SugarCRM::Account.new
irb(main):087:0> a.name = "COHEN, WEISS & SIMON LLP"
=> "COHEN, WEISS & SIMON LLP"
irb(main):088:0> a.save
=> false
irb(main):089:0> a.errors
=> #<Set: {}>
irb(main):090:0> a.name = "COHEN, WEISS SIMON LLP"
=> "COHEN, WEISS SIMON LLP"
irb(main):091:0> a.save
=> true
irb(main):092:0>
Hello - thanks for the Gem - very useful indeed.
I can happily search through contacts & accounts. But am having a couple of problems when things get a bit more complex.
1, Unable to access certain Modules.
Sugar::Account.find.. => this works
Sugar::TRANN_Trans.find.. => this does not work
SugarCRM.connection.get_fields("TRANN_Trans").inspect => this works
Both of which are returned as per SugarCRM.modules.
2, Just not getting how to use relationships.
I need to
I've read the documentation, I can see how to create records, but I'm a bit lost as how to traverse relationships,
Any chance of a couple of examples as per the above?
Thanks again for the Gem.
excelfile = File.read(File.join(File.dirname(__FILE__),"test_excel.xls"))
exceldoc = SugarCRM::Document.new
exceldoc.active_date = Date.today
exceldoc.document_name = "test_excel.xls"
exceldoc.filename = "test_excel.xls"
exceldoc.revision = 0
exceldoc.uploadfile = Base64.encode64(excelfile)
exceldoc.save!
The call is successful, but file is not readable in SugarCRM (and isn't uploaded: cache/uploads doesn't contain the file).
Given the filename contains binary garbage instead of the provided name, it's possible the REST API is expecting parameters in a certain order, and completely ignoring the key-value concept. (I seem to recall we ran into this issue before.)
Chicks, can you check with one of the engineers in which order we should be passing the parameters to create a Document instance with the set_entry REST API call?
Getting no results after successfully creating an Opportunity. I've tried the typical Repair and Relationship rebuild options. Not sure how to debug this...
irb(main):020:0> s = SugarCRM::Opportunity.new
...filling out required fields...
irb(main):032:0> s.save
=> true
irb(main):035:0> SugarCRM::Opportunity.first
=> false
irb(main):036:0> SugarCRM::Opportunity.all
=> []
Also...
Other modules such as Accounts DO work...
irb(main):037:0> SugarCRM::Account.first
=> #<SugarCRM::Account account_type: "", annual_revenue: "", assigned_user_id: "1", assigned_user_name: "CRM Support", billing_address_city: "", billing_address_country: "", billing_address_postalcode: "", billing_address_state: "", billing_address_street: "", billing_address_street_2: nil, billing_address_street_3: nil, billing_address_street_4: nil, campaign_id: "", campaign_name: "", cdb_updated_at_c: "", created_by: "1", created_by_name: "CRM Support", date_entered: "2010-11-29 19:51:25", date_modified: "2010-12-31 15:53:56", deleted: false, description: "", email1: "", email_opt_out: false, employees: "", id: "51f296dd-0efb-817b-cc26-4cf40442e865", industry: "", invalid_email: false, modified_by_name: "CRM Support", modified_user_id: "1", name: "Boo Industries", ownership: "", parent_id: "", parent_name: "", phone_alternate: "", phone_fax: "", phone_office: "", rating: "", shipping_address_city: "", shipping_address_country: "China", shipping_address_postalcode: "", shipping_address_state: "", shipping_address_street: "", shipping_address_street_2: nil, shipping_address_street_3: nil, shipping_address_street_4: nil, sic_code: "", team_count: "1", team_id: "2c4a6ca3-7e8e-4d63-3e07-4cd30c089e30", team_name: "CRM Support", team_set_id: "2c4a6ca3-7e8e-4d63-3e07-4cd30c089e30", ticker_symbol: "", view_website_c: "", website: "http://">
One of the guys at work asked for this today. Documenting here.
Hi all, when using set_note_attachment, I get an invalid session error coming from the sugarcrm side. Here is my example code:
SugarCRM.connect(Cust::SUGAR_URL, Cust::SUGAR_USERNAME, Cust::SUGAR_PASSWORD)
...
File.open(path, 'w') {|f| f.write(data_bytes) }
file = File.read("/tmp/hello.pdf")
n = SugarCRM::Note.new
n.name = "blah"
n.team_name = 'global'
n.team_count = 1
n.save
SugarCRM.connection.set_note_attachment(n.id, "hello.pdf", file)
At this point, an error occurs in the sugarcrm log:
[4517][-none-][ERROR] 11: Invalid Session ID
The session ID is invalid
I can't work out why it's doing it. The json that gets sent appears to be valid, and get_note_attachment works fine. I then created a standalone app without using the sugarcrm gem and called set_note_attachment directly and this worked fine, so as far as I can tell, it seems to be an issue with the sugarcrm gem. Testing on sugarcrm version 6.1.
Any ideas? Thank you for any help...
From head:
SugarCRM::Account.new.associations
=> [, , , , , , , , , , , , , , , , , , , , , , , , , ]
Is there an example of how to use the gem to attach a file?
Adding a Custom Module "Sid1ContactType" to an Opportunity. Everything seems to go OK, until the save of the opportunity, which returns false. Inspecting errors on the opportunity returns an empty set. Verified that this type of join works through the frontend.
irb(main):004:0> ct = SugarCRM::Sid1ContactType.new
=> #<SugarCRM::Sid1ContactType assigned_user_id: nil, assigned_user_name: nil, created_by: nil, created_by_name: nil, date_entered: nil, date_modified: nil, deleted: false, description: nil, id: nil, modified_by_name: nil, modified_user_id: nil, name: nil, opportunities_sid1_contact_types_name: nil, sid1_contact_types_contacts_name: nil, sid1_contact_types_opportunities_name: nil, team_count: nil, team_id: nil, team_name: nil, team_set_id: nil, types_c: nil>
irb(main):005:0> ct.required_attributes
=> [:types_c]
irb(main):006:0> ct.types_c = "a_loc"
=> "a_loc"
irb(main):008:0> ct.save
=> true
irb(main):009:0> o = SugarCRM::Opportunity.first
=> #<SugarCRM::Opportunity account_id: nil, account_name: "Slender Broadband Inc", amount: "75000", amount_usdollar: "75000", assigned_user_id: "seed_chris_id", assigned_user_name: "Chris Olliver", campaign_id: "", campaign_name: nil, created_by: "1", created_by_name: "Sidera Administrator", currency_id: "-99", currency_name: "", currency_symbol: "", date_closed: "2011-11-06", date_entered: "2011-01-25 18:20:54", date_modified: "2011-01-29 21:39:18", deleted: false, description: "", id: "1a7a1422-c5b1-2e13-0d0e-4d3f142d850b", lead_source: "Other", modified_by_name: "Sidera Administrator", modified_user_id: "1", name: "Slender Broadband Inc - 1000 units", next_step: "", opportunity_type: "", probability: 70, sales_stage: "Perception Analysis", sid1_contact_types_opportunities_name: "", team_count: "3", team_id: "East", team_name: "East ", team_set_id: "539b4447-b5c3-c71e-78bc-4d3f142190fa">
irb(main):011:0> o.valid?
=> true
irb(main):012:0> o.sid1_contact_types
=> #<SugarCRM::AssociationCollection:0x7fb5c62fa5e8 @collection=[], @owner=#<SugarCRM::Opportunity account_id: nil, account_name: "Slender Broadband Inc", amount: "75000", amount_usdollar: "75000", assigned_user_id: "seed_chris_id", assigned_user_name: "Chris Olliver", campaign_id: "", campaign_name: nil, created_by: "1", created_by_name: "Sidera Administrator", currency_id: "-99", currency_name: "", currency_symbol: "", date_closed: "2011-11-06", date_entered: "2011-01-25 18:20:54", date_modified: "2011-01-29 21:39:18", deleted: false, description: "", id: "1a7a1422-c5b1-2e13-0d0e-4d3f142d850b", lead_source: "Other", modified_by_name: "Sidera Administrator", modified_user_id: "1", name: "Slender Broadband Inc - 1000 units", next_step: "", opportunity_type: "", probability: 70, sales_stage: "Perception Analysis", sid1_contact_types_opportunities_name: "", team_count: "3", team_id: "East", team_name: "East ", team_set_id: "539b4447-b5c3-c71e-78bc-4d3f142190fa">, @Association=:sid1_contact_types_opportunities, @original=[], @loaded=true>
irb(main):013:0> o.sid1_contact_types << ct
=> #<SugarCRM::AssociationCollection:0x7fb5c62fa5e8 @collection=[#<SugarCRM::Sid1ContactType assigned_user_id: nil, assigned_user_name: nil, created_by: nil, created_by_name: nil, date_entered: nil, date_modified: nil, deleted: false, description: nil, id: "b99eaab1-4bc6-9ed2-52a2-4d4489f4891e", modified_by_name: nil, modified_user_id: nil, name: nil, opportunities_sid1_contact_types_name: nil, sid1_contact_types_contacts_name: nil, sid1_contact_types_opportunities_name: nil, team_count: nil, team_id: nil, team_name: nil, team_set_id: nil, types_c: "a_loc">], @owner=#<SugarCRM::Opportunity account_id: nil, account_name: "Slender Broadband Inc", amount: "75000", amount_usdollar: "75000", assigned_user_id: "seed_chris_id", assigned_user_name: "Chris Olliver", campaign_id: "", campaign_name: nil, created_by: "1", created_by_name: "Sidera Administrator", currency_id: "-99", currency_name: "", currency_symbol: "", date_closed: "2011-11-06", date_entered: "2011-01-25 18:20:54", date_modified: "2011-01-29 21:39:18", deleted: false, description: "", id: "1a7a1422-c5b1-2e13-0d0e-4d3f142d850b", lead_source: "Other", modified_by_name: "Sidera Administrator", modified_user_id: "1", name: "Slender Broadband Inc - 1000 units", next_step: "", opportunity_type: "", probability: 70, sales_stage: "Perception Analysis", sid1_contact_types_opportunities_name: "", team_count: "3", team_id: "East", team_name: "East ", team_set_id: "539b4447-b5c3-c71e-78bc-4d3f142190fa">, @Association=:sid1_contact_types_opportunities, @original=[], @loaded=true>
irb(main):014:0> o.save
=> false
irb(main):016:0> o.errors
=> #<Set: {}>
irb(main):027:0> SugarCRM::User.first
NoMethodError: undefined method session' for #<Class:0x7fa608e49700> from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.3/lib/active_record/base.rb:1008:in
method_missing'
from /usr/lib/ruby/gems/1.8/gems/sugarcrm-0.9.11/lib/sugarcrm/base.rb:52:in connection' from /usr/lib/ruby/gems/1.8/gems/sugarcrm-0.9.11/lib/sugarcrm/finders/finder_methods.rb:89:in
find_by_sql'
from /usr/lib/ruby/gems/1.8/gems/sugarcrm-0.9.11/lib/sugarcrm/finders/finder_methods.rb:6:in find_initial' from /usr/lib/ruby/gems/1.8/gems/sugarcrm-0.9.11/lib/sugarcrm/base.rb:35:in
find'
from /usr/lib/ruby/gems/1.8/gems/sugarcrm-0.9.11/lib/sugarcrm/base.rb:58:in `first'
from (irb):27
This is an issue with SugarCRM and has been assigned bug number 42414. Details below:
get_relationships: Request:
{
"session": "8e02276e1c093c134aa5763b85d599ca",
"module_name": "Documents",
"module_id": "",
"link_field_name": "revisions",
"related_module_query": "",
"related_fields": ["id"],
"related_module_link_name_to_fields_array": [],
"deleted": 0
}
SugarCRM::UnhandledResponse: Database failure. Please refer to sugarcrm.log for details.
from ./sugarcrm/connection/connection.rb:128:in `process_response'
from ./sugarcrm/connection/connection.rb:104:in `handle_response'
from ./sugarcrm/connection/connection.rb:79:in `send!'
from ./sugarcrm/connection/api/get_relationships.rb:27:in `get_relationships'
from ./sugarcrm/associations/association_collection.rb:116:in `load_associated_records'
from ./sugarcrm/associations/association_collection.rb:30:in `load'
from ./sugarcrm/associations/association_collection.rb:14:in `initialize'
from ./sugarcrm/associations/association_methods.rb:85:in `new'
from ./sugarcrm/associations/association_methods.rb:85:in `query_association'
from (eval):3:in `revisions'
from (irb):14
sugarcrm.log contains:
Mon Feb 21 20:00:52 2011 [7206][1][FATAL] Query Failed: SELECT documents.id , documents.assigned_user_id FROM documents where ( document_revisions.document_id= '' AND document_revisions.deleted=0) AND documents.deleted=0: MySQL error 1054: Unknown column 'document_revisions.document_id' in 'where clause'
I've confirmed this in 6.1.2 and 6.2.0 beta.
I am running a Rails application service that will handle requests to update data in SugarCRM. How can I test to make sure that the SugarCRM session is valid, and if it is not, reconnect?
Thanks!
Is it possible to set the timeout for the Sugar call ?
if I run :
c = SugarCRM::Contact.find_by_last_name 'Rossi'
or any other call, and my connection is down, I will get a timeout error after a very long time !
How can I set this time ?
(anyway, I am running sugar calls in background :) )
thank you
Alexdesi
I am narrowing these problems with relationships a bit I think. Given this test below, I get different results in repeating the test multiple times. About half the time it works and makes the association, half the time it bombs out. Pasted the output of the multiple runs below the code. Maybe this helps?
require 'test_helper'
class SugarContactTypeTest < ActiveSupport::TestCase
context "a SugarCRM::Sid1ContactType " do
setup do
@contact_type = SugarCRM::Sid1ContactType.new
@contact_type.types_c = "z_loc"
@contact_type.save
puts @contact_type.id
@contact = SugarCRM::Contact.first
@opportunity = SugarCRM::Opportunity.find("11213eea-4212-4901-2a13-4d457e9b2b04")
end
should "be able to add a contact and an opportunity" do
assert @contact_type.associate!(@contact)
assert @opportunity.associate!(@contact_type)
puts @contact_type.id
end
end
end
cfrugard@cfrugard-laptop:~/projects/sugar/test$ ruby unit/sugar_contact_type_test.rb
Loaded suite unit/sugar_contact_type_test
Started
bca50141-a4fc-a335-a5b7-4d4722816012
E
Finished in 1.357529 seconds.
1 tests, 1 assertions, 0 failures, 1 errors
cfrugard@cfrugard-laptop:~/projects/sugar/test$ ruby unit/sugar_contact_type_test.rb
Loaded suite unit/sugar_contact_type_test
Started
a370086a-95d1-0cfa-71cb-4d4722231a02
E
Finished in 1.432595 seconds.
1 tests, 1 assertions, 0 failures, 1 errors
cfrugard@cfrugard-laptop:~/projects/sugar/test$ ruby unit/sugar_contact_type_test.rb
Loaded suite unit/sugar_contact_type_test
Started
7ba708b9-798b-1b56-e47e-4d47221f0812
7ba708b9-798b-1b56-e47e-4d47221f0812
.
Finished in 1.350518 seconds.
1 tests, 2 assertions, 0 failures, 0 errors
cfrugard@cfrugard-laptop:~/projects/sugar/test$ ruby unit/sugar_contact_type_test.rb
Loaded suite unit/sugar_contact_type_test
Started
4b4d9830-1808-ac3f-5940-4d472227da6f
4b4d9830-1808-ac3f-5940-4d472227da6f
.
Finished in 1.346763 seconds.
1 tests, 2 assertions, 0 failures, 0 errors
cfrugard@cfrugard-laptop:~/projects/sugar/test$ ruby unit/sugar_contact_type_test.rb
Loaded suite unit/sugar_contact_type_test
Started
9e9f57d6-1738-d68c-d471-4d47222d27cf
9e9f57d6-1738-d68c-d471-4d47222d27cf
.
Finished in 1.38408 seconds.
1 tests, 2 assertions, 0 failures, 0 errors
cfrugard@cfrugard-laptop:~/projects/sugar/test$ ruby unit/sugar_contact_type_test.rb
Loaded suite unit/sugar_contact_type_test
Started
9f689f17-0081-88f5-efe7-4d4722aa5a27
E
Finished in 1.443279 seconds.
1 tests, 1 assertions, 0 failures, 1 errors
cfrugard@cfrugard-laptop:~/projects/sugar/test$ ruby unit/sugar_contact_type_test.rb
Loaded suite unit/sugar_contact_type_test
Started
7b7cae09-e6f0-4992-126b-4d4722ecc104
E
Finished in 1.335436 seconds.
1 tests, 1 assertions, 0 failures, 1 errors
cfrugard@cfrugard-laptop:~/projects/sugar/test$ ruby unit/sugar_contact_type_test.rb
Loaded suite unit/sugar_contact_type_test
Started
a314e02e-227c-1d77-7cd9-4d47225eb3bb
a314e02e-227c-1d77-7cd9-4d47225eb3bb
.
Finished in 1.371292 seconds.
1 tests, 2 assertions, 0 failures, 0 errors
cfrugard@cfrugard-laptop:~/projects/sugar/test$ ruby unit/sugar_contact_type_test.rb
Loaded suite unit/sugar_contact_type_test
Started
a0ca6a09-80c2-3564-7b39-4d4723d1fff3
a0ca6a09-80c2-3564-7b39-4d4723d1fff3
.
Finished in 1.434615 seconds.
1 tests, 2 assertions, 0 failures, 0 errors
cfrugard@cfrugard-laptop:~/projects/sugar/test$ ruby unit/sugar_contact_type_test.rb
Loaded suite unit/sugar_contact_type_test
Started
c95c0645-b062-4b92-b4e5-4d4723b4c420
c95c0645-b062-4b92-b4e5-4d4723b4c420
.
Finished in 1.407025 seconds.
1 tests, 2 assertions, 0 failures, 0 errors
cfrugard@cfrugard-laptop:~/projects/sugar/test$ ruby unit/sugar_contact_type_test.rb
Loaded suite unit/sugar_contact_type_test
Started
8391e3fd-4a2e-4538-9dd5-4d47230a21fe
8391e3fd-4a2e-4538-9dd5-4d47230a21fe
.
Finished in 1.41687 seconds.
1 tests, 2 assertions, 0 failures, 0 errors
cfrugard@cfrugard-laptop:~/projects/sugar/test$ ruby unit/sugar_contact_type_test.rb
Loaded suite unit/sugar_contact_type_test
Started
7f1c99ea-8156-8207-a126-4d47239ffe74
E
Finished in 1.328008 seconds.
1 tests, 1 assertions, 0 failures, 1 errors
I have gone in through Studio and made the "date_closed" field no longer required. Seems no matter what I do, the gem still sees it as a required attribute. I have also done the quick repair and rebuild.
This is most likely a SugarCRM bug, but wanted to document it here.
Steps to reproduce:
SugarCRM.connection.get_relationships(
"Accounts", SugarCRM::Account.first.id, "modified_user_link")
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
I've been chasing some random timeout issues with the gem, and I think some of them might be related to issues with ruby 1.8's timeout implementation. The basic gist is here: http://blog.headius.com/2008/02/rubys-threadraise-threadkill-timeoutrb.html
The Excon gem looks promising, since it's what Fog uses and it supports persistant connections.
Just ran unit tests against HEAD. When using Dynamic Finders to search Users, the result returned is always the admin or currently logged in user. This works as expected in ruby 1.9.2
1.8.7:
SugarCRM::User.find_by_first_name("Test")
#<SugarCRM::User user_name: "admin", accept_status_id: nil, accept_status_name: nil, address_city: "", address_country: "", address_postalcode: "", address_state: "", address_street: "", authenticate_id: "", c_accept_status_fields: " ...", created_by: "", created_by_name: "", date_entered: "2011-01-29 01:20:08", date_modified: "2011-01-29 01:47:40", deleted: false, department: "", description: "", email1: "[email protected]", employee_status: "Active", external_auth_only: false, first_name: "", full_name: nil, id: "1", is_admin: true, is_group: false, last_name: "Administrator", m_accept_status_fields: " ...", messenger_id: "", messenger_type: "", modified_by_name: "", modified_user_id: "1", name: nil, phone_fax: "", phone_home: "", phone_mobile: "", phone_other: "", phone_work: "", portal_only: false, pwd_last_changed: "", receive_notifications: false, reports_to_id: "", reports_to_name: "", status: "Active", sugar_login: true, system_generated_password: false, title: "Me", user_hash: "0d107d09f5bbe40cade3de5c71e9e9b7">
1.9.2:
SugarCRM::User.find_by_first_name("Test")
#<SugarCRM::User user_name: "test_user", accept_status_id: nil, accept_status_name: nil, address_city: "", address_country: "", address_postalcode: "", address_state: "", address_street: "", authenticate_id: "", c_accept_status_fields: " ...", created_by: "1", created_by_name: "", date_entered: "2011-01-29 01:40:20", date_modified: "2011-01-29 01:40:20", deleted: false, department: "", description: "", email1: "[email protected]", employee_status: "", external_auth_only: false, first_name: "Test", full_name: nil, id: "336b9088-9f3a-feab-1303-4d4370d19b24", is_admin: false, is_group: false, last_name: "User", m_accept_status_fields: " ...", messenger_id: "", messenger_type: "", modified_by_name: "", modified_user_id: "1", name: nil, phone_fax: "", phone_home: "", phone_mobile: "", phone_other: "", phone_work: "", portal_only: false, pwd_last_changed: "", receive_notifications: true, reports_to_id: "", reports_to_name: "", status: "Active", sugar_login: true, system_generated_password: false, title: "", user_hash: "">
When an empty resultset should be returned, (an empty array), the array returned contains one element, [false]
SugarOpportunity.all({:conditions => {:synced_c => "falsfe"}})
=> [false]
Not sure if this is intended, but the .all method on a Module (SugarCRM::Opportunity, for example) returns a single record when the query returns a single record, rather than an array with one record. I think all methods should always return arrays, even when they are empty. Using version 0.9.4
hey i am getting error when sugarcrm gem usng i rails application
like this
SugarCRM::MultipleSessions (There are multiple active sessions: use the session namespace instead of SugarCRM):
gem "sugarcrm", "0.9.11"
rails version = 3.0.3
how to use namespace session for SugarCRM?
require 'sugarcrm'
=> true
s = SugarCRM::Base.establish_connection("http://sugarcrm",'admin','password',{:debug => false})
=> #<SugarCRM::Connection:0xa9f7e8c @pass="password", @user="admin", @session="1anv8casnovv0d7h8plh1m33q3", @ssl=false.............
SugarCRM::User.find(id)
(irb):5: warning: Object#id will be deprecated; use Object#object_id
Errno::EPIPE: Broken pipe
s.get_entry_list("Users","users.user_name = 'admin'")
Errno::EPIPE: Broken pipe
s.connected?
=> true
s.logged_in?
=> true
s.get_entry_list("Users","users.user_name = 'admin'")
Errno::EPIPE: Broken pipe
Getting an "unknown column" MYSQL error when querying against a custom field.
SugarCRM::Opportunity.all({:conditions => {:synced_c => "false"}})
JSON::ParserError: 665: unexpected token at 'MySQL error 1054: Unknown column 'opportunities.synced_c' in 'where clause''
Of course, a custom field called "synced" would wind up in a opportunities_cstm table.
Problem:
Base#find currently returns ALL results - this can result in slow performance or memory limits when querying large datasets.
Solution:
Update #find to return a result set enumerator that utilizes SugarCRM's entry_list => offset functionality. This is essentially how database cursors work - it should track the total number of results, the current offset, and the results per page / max_results.
The fog gem does this really well - we can steal some examples from there.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.