last day (15 days later) » 

07:32
0
A: CRM 365: How to clear lookup through PATCH operation together with other changes?

Guido PreiteThe syntax to clear a lookup value is to set it as null, so your code should be entity["[email protected]"] = null; this is the code generated by Dataverse REST Builder with XHR syntax (the Guid has been changed to match the one provided by the user but with the original Guid it works...

Then I get an exception: An error occurred while validating input parameters: Microsoft.OData.ODataException: The 'odata.bind' instance or property annotation has a null value. In OData, the 'odata.bind' instance or property annotation must have a non-null string value.
This is my JSON for PATCH operation: {"[email protected]":null,"new_status":1,"new_is‌​_qualified":false,"b‌​irthdate":"1990-02-0‌​2T21:00:00Z","firstn‌​ame":"Test.FirstName‌​.Updated","middlenam‌​e":"Test.MiddleName.‌​Updated","lastname":‌​"Test.LastName.Updat‌​ed","mobilephone":"+‌​7-333-444-55-77","ne‌​w_appeal":null}
thanks for your tests. Tomorrow I will do some tests and let you know, probably I need to update my tool as well to handle this scenario
@AndreyBushman I just did a test (parentaccountid of the account table) and I was able to set it and after clear it by just assigning null to the odata.bind property. This is my code for reference; var record = {}; record["[email protected]"] = null; if you can test with my tool Dataverse REST Builder just to set only this property (you add the column but don't assign a value). Maybe the error is coming from another field in your PATCH operation?
I added UPD section in my question. Can you show me your JS-code generated by Dataverse REST Builder? I want to compare it with code generated by CRM REST Builder.
@AndreyBushman I updated my answer, practically the only difference is how the instance url is fetched, I use the new way Xrm.Utility.getGlobalContext().getClientUrl() instead of the old one Xrm.Page.context.getClientUrl(). Try to output the values of these two clienturls and see if there is a difference. As I understood from your update you are probably onpremise and connecting inside XrmToolBox with a method that is not supported by DRB (for this you get the message to download the managed solution).
Hm... I replaced Xrm.Page.context.getClientUrl() by Xrm.Utility.getGlobalContext().getClientUrl() but it didn't help: I get "Bad Request" still. But I got allowing to install the managed solution Dataverse REST Builder on our Dev CRM. I will install it today and try to use your tool. If it will no help then I can write video with this problem with step by step.
If I run your code then I haven't error (bad request) but the attribute wasn't cleared.
Oh... No. You write message to console instead of alert window. So, I get bad request error in console message. Magic not happened.
07:32
@AndreyBushman I am out of ideas. When you get approval to install the managed solution of Dataverse REST Builder then you can try with it.
I imported and published Dataverse REST Builder into Dev CRM but I can't find button for start it. How can I do it?
you need to open the apps of your instance, like customurl/main.aspx?forceUCI=1&pagetype=apps
there you will see all the apps installed inside the instance including DRB
07:49
I can't find "execute" button. :)
you go any syntax tab (in your case XHR as you are using XMLHttpRequest) and from there you have the option to move to Editor, inside the Editor you can execute
I copied generated code from Xrm.WebApi tab to Editor tab:
// NOTE: updateRecord is available in offline mode, if you need this functionality change the call to Xrm.WebApi.offline.updateRecord
// https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/xrm-webapi/offline
var record = {};
record["[email protected]"] = null; // Lookup

Xrm.WebApi.online.updateRecord("account", "32ac43be-24e6-ec11-998d-005056918c2c", record).then(
function success(result) {
var updatedId = result.id;
console.log(updatedId);
},
function(error) {
If I run it then I get the same error on the Result tab:
"Execution Start: 2022-06-07 10:54:24"
"An error occurred while validating input parameters: Microsoft.OData.ODataException: The 'odata.bind' instance or property annotation has a null value. In OData, the 'odata.bind' instance or property annotation must have a non-null string value.\r\n at Microsoft.OData.JsonLight.ODataJsonLightDeserializer.ReadAndValidateAnnotationStringValue(String annotationName)\r\n at Microsoft.OData.JsonLight.ODataJsonLightDeserializer.ReadAndValidateAnnotationStringValueAsUri(String annotationName)\r\n at Microsoft.OData.JsonLight.ODataJsonLightResourceDeser
it can be related to the fact your are running OnPremise, let me do a quick check
can you try to remove the odata.bind from the code inside the editor?
so it should be like
record["parentaccountid"] = null;
and execute again
in my online instance works in both ways, with and without odata.bind
08:06
I have tried to do it before I created my question on stackoverflow. :)
it doesn't clear the lookup.
then I think it's a bug with the current OnPremise version you have, did you install the latest rollup? if is on the latest rollup I can ping Microsoft to check, but if isn't on the latest rollup they will ask you to update it first to the latest version
btw, you can remove your previous screenshot as it contains the url of your instance
Microsoft Dynamics 365
Версия 2104 (9.1.9.8) (база данных 9.1.9.8) (локальная версия)
It is from "About Product".
at least I found there is this service update that is newer https://support.microsoft.com/en-us/topic/service-update-1-10-for-microsoft-dynamics-crm-on-premises-9-1-ea420f27-925d-4ea0-a8cf-bd668571497c
If you don't want to update (and I totally understand) then your only way is to open a support ticket to Microsoft
08:21
Ok. Thank you for your attemption to help me. I will to do like I do now it is implemented in my code : update all attributes except clearable lookups through PATCH request, then for each clearable lookup I execute DELETE request for clearing its $ref.
I wite a simple .Net 6 client to work with CRM 365.
if you are using .net you can use the official SDK, don't need to use the web api if you wish
the new version also support .net core/.net 5/6, the previous one only supported .net framework from 4.6.2 to 4.8
> the new version also support .net core/.net 5/6
I saw some nuget packages about it, but I can't connect to CRM with them. But I can do it with NTLM Authentication. It will be greate if I can use official SDK.

My application will be hosted inside of docker containers. Can you show me example which SDK you use for .net 6 and how you connect to on-premise?
for OnPremise I don't have examples (it's a long time I don't deal with OnPremise) all the instances I work with are Online, sorry
Ok. Thank you.
08:42
Can you write me CRM SDK nuget package names for .net 6 you using?

last day (15 days later) »