4

I wrote this question up at RubyZoho's forum, but it's languishing there, and it's such a simple question it deserves a wider audience.

I have used RubyZoho to upload a new Lead record to the Zoho CRM API, and now I want to upload a Task with its "related to" field set to that Lead.

Configuring RubyZoho:

RubyZoho.configure do |config|
  config.api_key = Setting.plugin_redmine_tigase['zoho_authorization_token']
  config.crm_modules = [
      'Leads',
      'Tasks'
  ]
  config.ignore_fields_with_bad_names = true
  config.cache_fields = true
end

Creating the lead:

  lead = RubyZoho::Crm::Lead.new
  lead.first_name = splut.first
  lead.last_name = splut.last
  lead.full_name = params[:name]
  lead.company = params[:company]
  lead.email = params[:mail]
  lead.description = description
  lead.save

Creating the Task:

  found = RubyZoho::Crm::Lead.find_by_email(params[:mail])
  lead = found.first
  task = RubyZoho::Crm::Task.new
  task.related_to = lead.id
  task.subject = params[:subject]
  task.description = description
  task.save

I tried task.related_to = lead.leadid, and got a Task record with a blank "related to" in the Zoho website. And when I try task.related_to = 'Lead'; task.relatedtoid = lead.leadid, I get a undefined method relatedtoid=, naturally because the variable has no setter.

So what am I missing? how do I do this simple thing?

Phlip
  • 5,253
  • 5
  • 32
  • 48

1 Answers1

1

If you look at the documentation it has a section on this

https://www.zoho.com/creator/help/script/creating-a-record-in-zoho-crm.html#create-lead

taskInfo = {
"Task Owner" : input.Owner_Name,
"SMOWNERID" : input.Owner_ID,
"Subject" : input.Subject,
"Description" : input.Description,
"SEMODULE" : "Accounts",
"SEID" : input.Account_ID,
"CONTACTID" : input.Contact_ID};
crmResp = zoho.crm.create("Tasks", taskInfo);

SMOWNERID is the ID of the Owner

SEMODULE can be Accounts or Leads or Cases

SEID is the ID of the Record given in the SEMODULE

CONTACTID is the ID of the contact record

Also if you look at the ruby_zoho_rspec for creating new task

https://github.com/amalc/rubyzoho/blob/950ffe369252f8fad3e7ae67ebddec859c84e19b/spec/ruby_zoho_spec.rb

it 'should save an task record related to an account' do
VCR.use_cassette 'zoho/task_related_to_account' do
  a = RubyZoho::Crm::Account.all.first
  e = RubyZoho::Crm::Task.new(
      :task_owner => a.account_owner,
      :subject => "Task should be related to #{a.account_name} #{Time.now}",
      :description => 'Nothing',
      :smownerid => "#{a.smownerid}",
      :status => 'Not Started',
      :priority => 'High',
      :send_notification_email => 'False',
      :due_date => '2014-02-16 16:00:00',
      :start_datetime => Time.now.to_s[1, 19],
      :end_datetime => '2014-02-16 16:00:00',
      :related_to => "#{a.account_name}",
      :seid => "#{a.accountid}",
      :semodule => 'Accounts'
  )
  r_expected = e.save
  r = RubyZoho::Crm::Task.find_by_activityid(r_expected.id)
  r.first.subject[0..20].should eq(r_expected.subject[0..20])
end

So that should help you out link it by specifying SEMODULE and SEID

Tarun Lalwani
  • 142,312
  • 9
  • 204
  • 265