Hi, using the JavaScript Client API I automatically navigate from the dashboard to a new case form and try to pre-populate its customer Id value.
I use for that purpose the Xrm.Navigation.openForm method:
var entityFormOptions = {}; entityFormOptions["entityName"] = 'incident'; var formParameters = {}; formParameters["formid"] = formIdCase; // formIdCase already contains the case form Id that I need. formParameters["customerid"] = contactId; // contactId already contains the ID of the contact. formParameters["customeridname"] = contactFullName; // Contact Full name previously retrieved with the Contact ID. formParameters["customeridtype"] = 'contact'; Xrm.Navigation.openForm(entityFormOptions, formParameters).then( function (success) { console.log('Success'); }, function (error) { console.log(error); } );
The navigation part works always fine and I can see the customer ID (lookup value) pre-populated with no problem.
The error happens when I try to save this new case (I mean when I click on the "Save" button in the case/incident form), I got the following error:
"An error occurred while validating input parameters: Microsoft.OData.ODataException: Does not support untyped value in non-open type.
at System.Web.OData.Formatter.Deserialization.DeserializationHelpers.ApplyProperty(ODataProperty property, IEdmStructuredTypeReference resourceType, Object resource, ODataDeserializerProvider deserializerProvider, ODataDeserializerContext readContext)
at System.Web.OData.Formatter.Deserialization.ODataResourceDeserializer.ApplyStructuralProperties(Object resource, ODataResourceWrapper resourceWrapper, IEdmStructuredTypeReference structuredType, ODataDeserializerContext readContext)
at Microsoft.Crm.Extensibility.CrmODataEntityDeserializer.ApplyStructuralProperties(Object resource, ODataResourceWrapper resourceWrapper, IEdmStructuredTypeReference structuredType, ODataDeserializerContext readContext)
at System.Web.OData.Formatter.Deserialization.ODataResourceDeserializer.ReadResource(ODataResourceWrapper resourceWrapper, IEdmStructuredTypeReference structuredType, ODataDeserializerContext readContext)
at System.Web.OData.Formatter.ODataMediaTypeFormatter.ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)"
However, this error only occurs when using the Customer Service Hub. When using the classic D365 interface the case is saved with no problem.
I know why I get that error because using the DevTools in the browser, I can see that I get 400 bad request because after clicking "Save" in the case form the following request payload is being sent:
{ "title": "Test case 1", "processid": "0ffbcde4-61c1-4355-aa89-aa1d7b2b8792", "routecase": false, "prioritycode": 2, "blockedprofile": false, "firstresponsesent": false, "isescalated": false, "statuscode": 1, "statecode": 0, "ownerid@odata.bind": "/systemusers(29ef7816-8f31-4cb6-ad8f-772147b5a0b1)", "customeridtype": "contact", "customeridname": "Brian LaMee", "customerid_contact@odata.bind": "/contacts(4da0e5b9-88df-e311-b8e5-6c3be5a8b200)" }
The two Key/value pairs in red (customeridtype and customeridname), in theory, shouldn't been sent because when I manually open a new case form, associate a customer and then save the case I don't see those values in the request payload.
I tried not to use customeridtype and customeridname in the Xrm.Navigation.openForm method but without those parameters (in addition to the customerid value) I cannot see the client name populated in the right "customer ID" field in the case form.
Strange things are:
- That does not happen when using the classic D365 interface.
- It only happens when using the Customer Service Hub interface.
- And more surprising that the only way that it works in the Customer Service Hub interface is if I open the new case form as a popup window (adding as form option entityFormOptions["openInNewWindow"] = true;)
So I wonder how it's the right way to populate a new case using Xrm.Navigation.openForm for the Customer Service Hub interface?
Any help would be greatly appreciated.
*This post is locked for comments