Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible bug in function 'populateFormattedValues(object)' #19

Closed
danielejdm opened this issue Dec 1, 2017 · 3 comments
Closed

Possible bug in function 'populateFormattedValues(object)' #19

danielejdm opened this issue Dec 1, 2017 · 3 comments
Assignees

Comments

@danielejdm
Copy link

danielejdm commented Dec 1, 2017

Hi Alexandr.

I was retrieving multiple records of a custom entity with the version which uses Callbacks.

My code is like the following:
var dynamicsWebApi = new DynamicsWebApi({ webApiVersion: '8.2' });

var filter = 'new_myfield eq <a_value>';

var select = ['new_field_1', 'new_field_2', 'new_field_3', 'new_field_2'];

dynamicsWebApi.retrieveMultiple('new_myentity', function (result) {
//My Logic
}, function (err) {
Xrm.Utility.alertDialog(err.message)
}, select, filter);

  • new_field_1, new_field_2, new_field_3, new_field_4 are all of type "Single Line of Text" (String)

I was retrieving a record which had new_field_2, new_field_3, new_field_4 empty (no value for the fields).

In run-time, entering the function 'populateFormattedValues(object)', the object has a null value for each of the corresponding keys:

function populateFormattedValues(object) {
var keys = Object.keys(object);

        for (var i = 0; i < keys.length; i++) {
            //Below object[keys[i]] is null for the empty fields on CRM
            if (object[keys[i]].constructor === Array) {
                for (var j = 0; j < object[keys[i]].length; j++) {
                    object[keys[i]][j] = populateFormattedValues(object[keys[i]][j]);
                }
            }
 ...

As a consequence, an exception is thrown because the code is trying to evaluate the property "constructor" of a null object.

I fixed the issue by adding a skipping step for the null elements, as shown below:

function populateFormattedValues(object) {
var keys = Object.keys(object);

        for (var i = 0; i < keys.length; i++) {
             if (object[keys[i]] == null)
                    continue;

            if (object[keys[i]].constructor === Array) {
                for (var j = 0; j < object[keys[i]].length; j++) {
                    object[keys[i]][j] = populateFormattedValues(object[keys[i]][j]);
                }
            }
 ...

After this fixing, the code is running properly, returning the correct object with parameters.

I would suggest you to make a deeper check and, in case, fix the code as I did or in a better way, and then publish the fixed version of the library.

Anyhow, congratulations for the very good job!

@AleksandrRogov
Copy link
Owner

Hi @danielejdm ,
Thank you for submitting this issue I will take a look at the problem asap.

@AleksandrRogov AleksandrRogov self-assigned this Dec 1, 2017
@AleksandrRogov
Copy link
Owner

What version are you using? I see that it has been fixed in v.1.3.1. #13

@danielejdm
Copy link
Author

danielejdm commented Dec 1, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants