Save company data on extra fields in service "Before Save Company Trigger".

Hi,

I thought it was possible to save data on extra fields in service when using the before save company trigger in CRM.

This is not working, did we changed something! See example below....

#setLanguageLevel 3;

EventData ed = getEventData();

// Load contact values
Integer contactId = ed.getInputValue("ContactEntity.ContactId").toInteger();

// Load user
Integer userId = getVariable("activeUser").toInteger();

// Get values from included scripts
#include "get_company_values";
getCompanyValues(contactId);

#include "get_visit_address";
getVisitAddress(contactId);

#include "get_phone_number";
getPhoneNumber(contactId);

#include "get_email_address";
getEmailAddress(contactId);

if (contactId > 0)
{
  Company comp;
  comp.load(contactId);
  comp.setValue("x_update_counter", "1");
  comp.setValue("x_updated_by_user", userId.toString());
  comp.setValue("x_sales_contact_id", companySalesContactId);
  comp.setValue("x_customer_status_id", companyStatusId);
  comp.setValue("x_visit_address_line1", visitAddressLine1);
  comp.setValue("x_visit_address_line2", visitAddressLine2);
  comp.setValue("x_visit_address_line3", visitAddressLine3);
  comp.setValue("x_visit_address_zipcode", visitZipCode);
  comp.setValue("x_visit_address_county", visitCounty);
  comp.setValue("x_visit_address_state", visitState);
  comp.setValue("x_visit_address_city", visitCity);
  comp.setValue("x_country", companyCountry);
  comp.setValue("x_phone_number", phoneNumber);
  comp.setValue("x_email_address", emailAddress);
  comp.save();
}

RE: Save company data on extra fields in service "Before Save Company Trigger".

Hi Brian,

Not sure if something might be missing from your script code, have you tried to trace the trigger?

In my online demo I am able to save to extra fields on Before Save company trigger.

/Michel

By: Michel Krohn-Dale 20 Aug 2019

RE: Save company data on extra fields in service "Before Save Company Trigger".

Hi Michel,

My trace says nothing, it looks like the company data has been saved.

I think this stopped working after update 8.5 R02 (updated 28-5-2019) in CRM Online.

By: Brian Mulder 20 Aug 2019

RE: Save company data on extra fields in service "Before Save Company Trigger".

Hi,

My script is much simpler than yours but it is indeed updating company.

I guess when you say that trace says nothing, that you verify that it is infact running thru whole script to the end?

 

By: Michel Krohn-Dale 20 Aug 2019

RE: Save company data on extra fields in service "Before Save Company Trigger".

Exactly, the script is running till the end. No errors visible.

By: Brian Mulder 20 Aug 2019

RE: Save company data on extra fields in service "Before Save Company Trigger".

It seems that it is not working on company fields created before 28-5-2019. When writing data to new created fields it works as expected. Maybe it's needed to do an research of customer's database?

By: Brian Mulder 20 Aug 2019

RE: Save company data on extra fields in service "Before Save Company Trigger".

Hi,

Could you try to do the following:

  1. Extract the company-saving part of your script and run it as a separate script (no trigger) so that it can be debugged. 
  2. Verify that the two fields are still behaving different: the old one does not update, the new one updates.
  3. Go to rms.fcgi?action=debug and enable alle checkboxes related to database queries
  4. Run your script
  5. Check the warning log and see what queries are actually run against the database

Sverre

By: Sverre Hjelm 21 Aug 2019