Optimize CRM performace by using Data Return
This blog will help you to reduces multiple calls to sever and reduces loading time of CRM forms.
There are scenarios where you want to retrieve an entity right after you create or update it. With December 2016 update (online and on-premise) this capability has been added. You can compose your POST request so that data from the created record will be returned with a status of 201 (Created). To get this result, you must use the return=representation preference in the request headers. Note if you don’t define the return type as representation then the status for creation will be 204 .
To control which properties are returned, append the $select query option to the URL to the entity set. The $expand query option will be ignored if used.
This is the header that needs to be configured for Create
Request
POST [Organization URI]/api/data/v9.0/accounts?$select=name,creditonhold,address1_latitude,description,revenue,accountcategorycode,createdon HTTP/1.1
OData-MaxVersion: 4.0
OData-Version: 4.0
Accept: application/json
Content-Type: application/json; charset=utf-8
Prefer: return=representation
{
“name”: “Sample Account”,
“creditonhold”: false,
“address1_latitude”: 47.639583,
“description”: “This is the description of the sample account”,
“revenue”: 5000000,
“accountcategorycode”: 1
}
Response
HTTP/1.1 201 Created
Content-Type: application/json; odata.metadata=minimal
Preference-Applied: return=representation
OData-Version: 4.0
{
“@odata.context”: “[Organization URI]/api/data/v9.0/$metadata#accounts/$entity”,
“@odata.etag”: “W/\”536530\””,
“accountid”: “d6f193fc-ce85-e611-80d8-00155d2a68de”,
“accountcategorycode”: 1,
“description”: “This is the description of the sample account”,
“address1_latitude”: 47.63958,
“creditonhold”: false,
“name”: “Sample Account”,
“createdon”: “2016-09-28T22:57:53Z”,
“revenue”: 5000000.0000,
“_transactioncurrencyid_value”: “048dddaa-6f7f-e611-80d3-00155db5e0b6”
}
Header for Update with return value
To retrieve data from an entity you are updating you can compose your PATCH request so that data from the created record will be returned with a status of 200 (Update). To get his result, you must use the return=representation preference in the request headers. Note if you don’t define the return type as representation then the status for creation will be 1223.
Request
PATCH [Organization URI]/api/data/v9.0/accounts(00000000-0000-0000-0000-000000000001)?$select=name,creditonhold,address1_latitude,description,revenue,accountcategorycode,createdon HTTP/1.1 OData-MaxVersion: 4.0 OData-Version: 4.0 Accept: application/json Content-Type: application/json; charset=utf-8 Prefer: return=representation {“name”:”Updated Sample Account”}
Define all the attribute you want returned under $select.
Response
HTTP/1.1 200 OK Content-Type: application/json; odata.metadata=minimal Preference-Applied: return=representation OData-Version: 4.0
{
“@odata.context”: “[Organization URI]/api/data/v9.0/$metadata#accounts/$entity”, “@odata.etag”: “W/\”536537\””, “accountid”: “00000000-0000-0000-0000-000000000001”, “accountcategorycode”: 1, “description”: “This is the description of the sample account”, “address1_latitude”: 47.63958, “creditonhold”: false, “name”: “Updated Sample Account”, “createdon”: “2016-09-28T23:14:00Z”, “revenue”: 5000000.0000, “_transactioncurrencyid_value”: “048dddaa-6f7f-e611-80d3-00155db5e0b6”
}
This works for 8.2 and 9.x as well
For more details : https://msdn.microsoft.com/en-us/library/mt770366.aspx
This was originally posted here.
 
		
 
                 
                 
             Like
Like Report
Report
*This post is locked for comments