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

Error in CreateRequest when a lookup field is null/undefined in target object #47

Open
khoait opened this issue Sep 5, 2023 · 9 comments · Fixed by #48 · May be fixed by #52
Open

Error in CreateRequest when a lookup field is null/undefined in target object #47

khoait opened this issue Sep 5, 2023 · 9 comments · Fixed by #48 · May be fixed by #52

Comments

@khoait
Copy link

khoait commented Sep 5, 2023

Hi,

I'm using dataverse-ify version 2.0.7. I'm trying to send a batch request using the executeMultiple function. When the target object contains a lookup field with undefined/null value, I get the below error.

Error identified in Payload provided by the user for Entity :'(entity name removed)', For more information on this error please follow this help link https://go.microsoft.com/fwlink/?linkid=2195293 
----> InnerException : Microsoft.Crm.CrmException: Invalid property '(lookup field name removed)' was found in entity 'Microsoft.Dynamics.CRM.(entity name removed)'. 
---> Microsoft.OData.ODataException: Does not support untyped value in non-open type.

I also checked the normal create function and got the same error. The target object looks like this:

{
  logicalName: "new_entityname",
  new_name: "some name",
  new_lookupfield: null
}
@khoait
Copy link
Author

khoait commented Sep 5, 2023

I just tested with create request Web API in Postman. Turns out setting null to a lookup field we need to use the Schema Name instead of the Logical Name. It's quite inconvenient when they are different, usually upper case vs lower case like this:

Display Name: Lookup Field
Schema name: new_LookupField
Logical name: new_lookupfield

so the payload should look like this:

{
  logicalName: "new_entityname",
  new_name: "some name",
  new_LookupField: null
}

Can we have some logic to check for this scenario and construct the payload correctly?

@khoait
Copy link
Author

khoait commented Sep 5, 2023

Proposed a fix in a PR

@scottdurow
Copy link
Owner

Hi @khoait - I completely missed this PR - sorry it's take me over a year to get to it! I merged in and the nullvalues integration test started to fail:

expect(account1Retrieved2.preferredsystemuserid).toBeUndefined();

Perhaps this issue is specific to batch requests?

@scottdurow scottdurow reopened this Dec 5, 2024
@khoait
Copy link
Author

khoait commented Dec 5, 2024

Thanks @scottdurow ! It happens to a single create request as well. I'll review the tests.

@khoait khoait linked a pull request Dec 10, 2024 that will close this issue
@khoait
Copy link
Author

khoait commented Dec 10, 2024

@scottdurow I added unit tests and passed all tests. please have a look.

@scottdurow
Copy link
Owner

Ah - ha! So it's the case sensitivity of the lookup field. Awesome job in spotting and fixing this!

@khoait
Copy link
Author

khoait commented Dec 10, 2024

yeah! it was very tricky when I first encountered the error.

I came up with a convention within the team to always modify the logical name to lowercase whenever we create a new field to keep it consistent for sdk and odata.

I hope the fix will be available soon! Cheers!

@scottdurow
Copy link
Owner

I'll get this merged and published asap!
I want to move v2 out of beta by the end of the year. Do you have anything that you could share to improve the documentation for dataverse-ify?

@khoait
Copy link
Author

khoait commented Dec 11, 2024

That's great to hear! Thanks @scottdurow !
First thing comes to mind is adding quick installation in the Readme. I'll create another issue/discussion with more details.

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