I am using Dynamics 365 Web API with VBA to update a specific entity record. However, I don't have the primary key GUID but I do have another a combination of other field values that would identify a unique record. Is there a way to change the Request.Resource
line to use the other fields?
This code works if I provide the specific primary key GUID but I won't have the GUID when it needs to be updated.
Dim crm As New crm
Dim Request As New WebRequest
Dim Response As WebResponse
Dim dict As New Scripting.Dictionary
Request.Resource = "productpricelevels(F01E6888-7643-EE11-BDF4-00224808D9DA)"
Request.Format = WebFormat.Json
Request.ResponseFormat = Json
Request.Method = WebMethod.HttpPatch
'== field to update
dict.Add "amount", 4
Request.Body = WebHelpers.ConvertToJson(dict)
' Response from query
Set Response = crm.Query(Request)
If Response.StatusCode = WebStatusCode.NoContent Then
Debug.Print ("Success")
...
This should be possible via alternate keys
which you have to define yourself.
It should look like this:
Request.Resource = "productpricelevels(name='fish and chips',fishtype='hoki')"
Reference: Use an alternate key to reference a record