javascript-api icon indicating copy to clipboard operation
javascript-api copied to clipboard

custom fields are not updating from script

Open vsatishkumar91 opened this issue 12 years ago • 7 comments

I am using AgileCRM for creating contacts from agile javascript. I need two custom fields in my contact information. So I created two custom fields, one is list and another one is text. From the website I am able to update my custom fields, But when I am trying to create a contact with custom fields, those are not updating. Scenario : I created two fields one is Department as list with values (developing; supporting, Auditing; production;DBA) and another one is Employee code as text When I try to add contact I just use below code : var contact = {}; contact.email = "[email protected]"; contact.first_name = "Test"; contact.last_name = "Contact"; contact.company = "abc corp"; contact.title = "lead"; contact.phone = "+1-541-754-3010"; contact.website = "http://www.example.com"; var address = {"city":"new delhi", "state":"delhi", "country":"india"}; contact.address = JSON.stringify(address); contact.tags = "tag1, tag2"; _agile.create_contact(contact, { success: function (data) { console.log("success"); }, error: function (data) { console.log("error"); } }); Then it is working fine. But if I modify code as var contact = {}; contact.email = "[email protected]"; contact.first_name = "Test"; contact.last_name = "Contact"; contact.company = "abc corp"; contact.title = "lead"; contact.phone = "+1-541-754-3010"; contact.Department = " developing "; contact.phone = "Tech12SE021" contact.website = "http://www.example.com"; var address = {"city":"new delhi", "state":"delhi", "country":"india"}; contact.address = JSON.stringify(address); contact.tags = "tag1, tag2"; _agile.create_contact(contact, { success: function (data) { console.log("success"); }, error: function (data) { console.log("error"); } }); It is not updating in my contact. Now I change my custom fields to compulsory, then also it is not updating, and also It is not displaying any error message for absent of compulsory fields. Any help would be greatly appreciated!

vsatishkumar91 avatar Aug 18 '14 04:08 vsatishkumar91

Hi Satish,

  • Right now, we do not support adding custom fields to contact using the _agile.create_contact API.
  • However you can add a new custom field or update an existing custom field using the

_agile.set_property API call documented at

(https://github.com/agilecrm/javascript-api/blob/master/README.md#25-set-contact-property)

(or)

_agile.update_contact API call documented at

(https://github.com/agilecrm/javascript-api/blob/master/README.md#24-update-contact)

  • If you need to add or update a custom field during contact creation, you can always call any of

the above mentioned API, in the success callback of _agile.create_contact as done below :

var contact = {
};
contact.email = '[email protected]';
contact.first_name = 'Test';
contact.last_name = 'Contact';
contact.company = 'abc corp';
contact.title = 'lead';
contact.phone = '+1-541-754-3010';
contact.Department = 'developing';
contact.phone = 'Tech12SE021'
contact.website = 'http://www.example.com';
var address = {
  'city': 'new delhi',
  'state': 'delhi',
  'country': 'india'
};
contact.address = JSON.stringify(address);
contact.tags = 'tag1, tag2';

// set email is mandatory for all agile api calls related to contact
if (contact.email)
_agile.set_email(contact.email);

_agile.create_contact(contact, {
  success: function (data) {
    console.log('contact success');
    _agile.set_property({
      'name': 'Departmant',
      'value': contact.Department
    }, {
      success: function () {
        console.log('custom field success');
      },
      error: function () {
        console.log('custom field error');
      }
    }, contact.email)
  },
  error: function (data) {
    console.log('contact error');
  }
});

Thanks

karthikagile avatar Aug 18 '14 10:08 karthikagile

Thanks for your valuable information.

On Mon, Aug 18, 2014 at 4:04 PM, karthikagile [email protected] wrote:

Hi Satish,

Right now, we do not support adding custom fields to contact using the _agile.create_contact API.

However you can add a new custom field or update an existing custom field using the

_agile.set_property API call documented at

( https://github.com/agilecrm/javascript-api/blob/master/README.md#25-set-contact-property )

(or)

_agile.update_contact API call documented at

( https://github.com/agilecrm/javascript-api/blob/master/README.md#24-update-contact )

  • If you need to add or update a custom field during contact creation, you can always call any of

the above mentioned API, in the success callback of _agile.create_contact as done below :

var contact = {};contact.email = '[email protected]';contact.first_name = 'Test';contact.last_name = 'Contact';contact.company = 'abc corp';contact.title = 'lead';contact.phone = '+1-541-754-3010';contact.Department = 'developing';contact.phone = 'Tech12SE021'contact.website = 'http://www.example.com';var address = { 'city': 'new delhi', 'state': 'delhi', 'country': 'india'};contact.address = JSON.stringify(address);contact.tags = 'tag1, tag2'; // set email is mandatory for all agile api calls related to contactif (contact.email)_agile.set_email(contact.email); _agile.create_contact(contact, { success: function (data) { console.log('contact success'); _agile.set_property({ 'name': 'Departmant', 'value': contact.Department }, { success: function () { console.log('custom field success'); }, error: function () { console.log('custom field error'); } }, contact.email) }, error: function (data) { console.log('contact error'); }});

Thanks

— Reply to this email directly or view it on GitHub https://github.com/agilecrm/javascript-api/issues/2#issuecomment-52475767 .

vsatishkumar91 avatar Aug 18 '14 12:08 vsatishkumar91

Dear Sir,

Thanks for your valuable information.

If I am trying to add two properties at a time in success block of create contact, it is not importing.

Am I doing any wrong?

Can you please help me. . . .

_agile.set_property({ 'name': 'Department', 'value': "Production" }, { success: function () { console.log('custom field success'); }, error: function () { console.log('custom field error'); } }, contact.email); _agile.set_property({ 'name': 'empcode', 'value': "1234" }, { success: function () { console.log('custom field success'); }, error: function () { console.log('custom field error'); } }, contact.email);

On Mon, Aug 18, 2014 at 5:31 PM, satish kumar V [email protected] wrote:

Thanks for your valuable information.

On Mon, Aug 18, 2014 at 4:04 PM, karthikagile [email protected] wrote:

Hi Satish,

Right now, we do not support adding custom fields to contact using the _agile.create_contact API.

However you can add a new custom field or update an existing custom field using the

_agile.set_property API call documented at

( https://github.com/agilecrm/javascript-api/blob/master/README.md#25-set-contact-property )

(or)

_agile.update_contact API call documented at

( https://github.com/agilecrm/javascript-api/blob/master/README.md#24-update-contact )

  • If you need to add or update a custom field during contact creation, you can always call any of

the above mentioned API, in the success callback of _agile.create_contact as done below :

var contact = {};contact.email = '[email protected]';contact.first_name = 'Test';contact.last_name = 'Contact';contact.company = 'abc corp';contact.title = 'lead';contact.phone = '+1-541-754-3010';contact.Department = 'developing';contact.phone = 'Tech12SE021'contact.website = 'http://www.example.com';var address = { 'city': 'new delhi', 'state': 'delhi', 'country': 'india'};contact.address = JSON.stringify(address);contact.tags = 'tag1, tag2'; // set email is mandatory for all agile api calls related to contactif (contact.email)_agile.set_email(contact.email); _agile.create_contact(contact, { success: function (data) { console.log('contact success'); _agile.set_property({ 'name': 'Departmant', 'value': contact.Department }, { success: function () { console.log('custom field success'); }, error: function () { console.log('custom field error'); } }, contact.email) }, error: function (data) { console.log('contact error'); }});

Thanks

— Reply to this email directly or view it on GitHub https://github.com/agilecrm/javascript-api/issues/2#issuecomment-52475767 .

vsatishkumar91 avatar Aug 19 '14 10:08 vsatishkumar91

Hi Satish

Kindly use _agile.update_contact api call in the success block of create contact to add multiple custom contact properties, _agile.set_property is limited to add a single custom contact property.

var contact = {}

contact.first_name = 'Test';
contact.last_name = 'Contact';
contact.email = '[email protected]';
contact.company = 'abc corp';
contact.title = 'lead';
contact.phone = '+1-541-754-3010';
contact.website = 'http://www.example.com';

var address = {
  'city': 'new delhi',
  'state': 'delhi',
  'country': 'india'
};

contact.address = JSON.stringify(address);
contact.tags = 'tag1, tag2';

var custom_contact_properties = {};
custom_contact_properties['Department'] = 'Production';
custom_contact_properties['empcode'] = '1234';

if (contact.email)
_agile.set_email(contact.email);
_agile.create_contact(contact, {
  success: function (data) {
    console.log('contact success');
    _agile.update_contact(custom_contact_properties, {
      success: function (data) {
        console.log('custom contact property success');
      },
      error: function (data) {
        console.log('custom contact property error');
      }
    }, contact.email);
  },
  error: function (data) {
    console.log('contact error');
  }
})

thanks.

karthikagile avatar Aug 19 '14 11:08 karthikagile

Thanks for your valuable information.

It saves my time greatly.

On Tue, Aug 19, 2014 at 4:51 PM, karthikagile [email protected] wrote:

Hi Satish

Kindly use _agile.update_contact api call in the success block of create contact to add multiple custom contact properties, _agile.set_property is limited to add a single custom contact property.

var contact = {}

contact.first_name = 'Test';contact.last_name = 'Contact'; contact.email = '[email protected]'; contact.company = 'abc corp';contact.title = 'lead';contact.phone = '+1-541-754-3010'; contact.website = 'http://www.example.com'; var address = { 'city': 'new delhi', 'state': 'delhi', 'country': 'india'}; contact.address = JSON.stringify(address);contact.tags = 'tag1, tag2'; var custom_contact_properties = {};custom_contact_properties['Department'] = 'Production';custom_contact_properties['empcode'] = '1234';

if (contact.email)_agile.set_email(contact.email);_agile.create_contact(contact, { success: function (data) { console.log('contact success');

_agile.update_contact(custom_contact_properties, {
  success: function (data) {
    console.log('custom contact property success');
  },
  error: function (data) {
    console.log('custom contact property error');

  }
}, contact.email);

}, error: function (data) { console.log('contact error'); }})

thanks.

— Reply to this email directly or view it on GitHub https://github.com/agilecrm/javascript-api/issues/2#issuecomment-52619750 .

vsatishkumar91 avatar Aug 20 '14 04:08 vsatishkumar91

Please update your documentation to reflect this. The information about setting custom fields should be moved from section 2.5 to 2.4 in your documentation. It is currently wrong and does not work as documented.

aDaneInSpain avatar Jul 30 '15 09:07 aDaneInSpain

Hi @aDaneInSpain

  • We can set custom fields related to contact (i.e custom contact properties) using both _agile.update_contact documented under section 2.4 (https://github.com/agilecrm/javascript-api/blob/master/README.md#24-update-contact) and _agile.set_property documented under section 2.5 (https://github.com/agilecrm/javascript-api/blob/master/README.md#25-set-contact-property)
  • _agile.update_contact allows to set multiple custom fields in single API call, but does not support type, whereas _agile.set_property can be used to set single custom field with type
  • Documentation of section 2.5 does not apply to section 2.4 as _agile.update_contact does not support type to be added. Please use them as per your requirement.

karthikagile avatar Jul 30 '15 10:07 karthikagile