AlexaCRM / php-crm-toolkit

Dynamics CRM Toolkit for PHP
GNU Lesser General Public License v3.0
106 stars 42 forks source link

option set value 0 doesn't save on CRM #85

Open wendyrepez opened 5 years ago

wendyrepez commented 5 years ago

Hi,

I'm trying to send to CRM an option value of 0 without luck. If I send a value different than 0, I can see it correctly on CRM. But this doesn't happen when I send 0. Can you give an example or any other guidance of how should I do this? I'm using the optionValue method , but that does not work when I'm attempting to send 0

georged commented 5 years ago

Is 0 a valid value for your optionset? If not then what are you trying to do - set the value to null? Null and 0 are not the same.

wendyrepez commented 5 years ago

Hi georged, 0 is a valid value on my optionset, and that's what I'm being trying to send to CRM.

If I send any other number to those optionsets all of them work, the issue is with the 0.

Any clue about why this could happen will be appreciated.

georged commented 5 years ago

@wendyrepez that is strange, indeed. Do you get any error or operation just completes and does not save? Could it be that you have some plugins or workflows that prevent the value from saving?

wizardist commented 5 years ago

@wendyrepez make sure you are using the latest version of toolkit @ dev-master.

I tried both setting the integer value 0 and new OptionSetValue( 0, '' ), and it worked fine. Could you share with us the way you update values?

wendyrepez commented 5 years ago

@wendyrepez that is strange, indeed. Do you get any error or operation just completes and does not save? Could it be that you have some plugins or workflows that prevent the value from saving?

Yes, It is. I don't get any error and the operation completes successfully, but the option doesn't get save on CRM.

I could give it a check it out to plugins or workflows but this behaviour occurs with all the optionsets which have 0 as value.

georged commented 5 years ago

@wendyrepez as @wizardist mentioned, we did test it and found no issues. I assume your toolkit is up to date. Can you please:

Thanks George

wendyrepez commented 5 years ago

Hi @georged,

We are using Dynamics 365/CRM on its 9.1 version

Here I left you the fragment of code, that seems to be causing no efect on CRM:

if($inputName=='new_sexo' || $inputName=='new_laborandoactualmente' || $inputName=='new_espep' || $inputName=='new_motivopepbenfinal' || $inputName=='new_porvinculacionfamiliar' || $inputName=='new_suma_toleranciadelclientealriesgo'|| $inputName=='new_tipodeorganizacionoempresa' || $inputName=='new_nivelacademico' || $inputName=="new_suma_plazoqueanticipadelosfondosinvertido"){ $value = ($data['value']=="0" ? 0 : $data['value']); $lead->$inputName = optionValue($value,''); }

The data always come to the function as string and those lines are wrap on a foreach . All of those fields receive all values except 0 .

Hope this can give you an idea. Let me know if you have any other doubt or need more information.

Thanks in advance, @georged and @wizardist

georged commented 5 years ago

@wendyrepez why are you casting "0" to 0 but not any other values?

wendyrepez commented 5 years ago

Hi @georged,

That was just a try, even if I don't cast the value, the method doesn't take effect for 0, the operation gets completed successfully but the value doesn't get save.

georged commented 5 years ago

Hi @wendyrepez

we are unable to reproduce the issue. All our tests involving optionsets with the value 0 pass.

What you can do is instantiate the client with the logger attached, i.e.

new Client( $settings, $cache, $logger )

where $logger is an instance of a PSR-3 compliant logger, e.g. Monolog.

Logger will "see" all details of the requests including SOAP that gets sent out and the responses. That should help you to identify the issue.

Thanks George