[New post] Dynamics CRM: Effective Way Calling Custom Web API in Javascript Development
temmyraharjo posted: " Finally, I found how to call Custom Action from Xrm.WebApi.execute function. The funny thing is, the method has already been in place for a long time. I just realized how to call it after I have the curiosity to get the EnvironmentVariable"
So for this blog post demonstration, we will call 2 Custom Actions (GetEnvironmentVariable and GetTeamEmailRequest) that I already prepared (you can download the unmanaged solutions that you can find here). The idea of "effective" is still the same as the previous blog post about the effective way of calling Custom Web API series: we (as the developer) need to have a collection of classes that represent the Custom API that we create. So we don't need the hassle to remember all the requests by ourself and we can pass the collections to your teams to be reused by them.
The Code
So here is the sample code for the 2 Custom API that I created:
From the above code, the things that you must understand are:
The object name of the parameterTypes must same as the variable name of the method and must be the same as the Custom API Parameter name. You can check all this information from metadata URL like the below picture:
The typeName, you can copy-paste from what you found in metadata.
The operationType definition are:
Action : 0
Functions: 1
CRUD: 2
*If you set the operationType wrongly, then your function will be not triggered.
How to Execute?
When we want to execute the requests, we just need to execute them using the below code:
var req = new Insurgo.CustomApi.GetTeamsEmailRequest('Testing Team', true); Xrm.WebApi.execute(req).then(success => success.json()).then(success => console.log(success)); var req1 = new Insurgo.CustomApi.GetEnvironmentVariable('msdyn_IncidentShouldValidatePrimaryContact'); Xrm.WebApi.execute(req1).then(success => success.json()).then(success => console.log(success));
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.