Below is the code for Web API to Retrieve Record by entity ID along with helper function. The signature of the function is same as you might have seen in SDK.REST.js library. However, I have added two additional parameters:
- isAsync- Boolean. If isAsync is set to true, the request would be executed Asynchronously. In SDK.REST.js, it was hard-coded and sent as true.
- impersonatedUserId- Guid of the User. If you would like to execute the JS, in context of other user, you can pass the user id. To run in the logged-in user's context, pass the parameter as NULL.
- _getFormattedValue - When you want to retrieve the OptionSet Label/Lookup text, you can use the _getFormattedValue function specified in the library.
- _getLookupEntityLogicalName -For regarding type of lookup, where you would like to know entity name, you can use _getLookupEntityLogicalName function.
Web API retrieveRecord code along with helper function:
After looking at Demo function, you will notice few Differences compared to SDK.REST.retrieveRecord library:
- While passing entity name, you need to pass as plural. Like for Account, pass accounts; for Opportunity, pass opportunities etc.
- To retrieve lookup attributes, prefix the attribute name with "_" and suffix with "_value". Like in the demo function, for transactioncurrencyid attribute, I am passing _transactioncurrencyid_value.
- To retrieve the OptionSetLabel, use getFormattedValue function
- To retrieve the lookup entity logical name, use getLookupEntityLogicalName function.
Please feel free to post your feedback/queries in the comments.
I would be posting more functions (retrieveMultiple, createRecord, updateRecord, executeCustomFunction etc.) in the upcoming posts.