private ParameterCollection ExecuteCustomAction(IPluginExecutionContext context, IOrganizationServiceFactory serviceFactory, IOrganizationService serviceAdmin, IOrganizationService service, ITracingService tracing) { var outputs = new ParameterCollection(); //YOUR CUSTOM ACTION BEGIN HERE var function = (string)context.InputParameters?["function"]; var input = (string)context.InputParameters?["input"]; var output = string.Empty; switch (function) { case "ConvertFetchXmlToWebApi": output = ConvertFetchXmlToWebAPI.Process(serviceAdmin, service, tracing, input); break; case "ReturnObjectFetchXMLToJs": output = ReturnObjectFetchXMLToJs.Process(serviceAdmin, service, tracing, input); break; default: output = string.Empty; break; } outputs.Add(new KeyValuePair <string, object>("output", output)); return(outputs); }
private static void DebugConvertFetchXmlToWebAPI() { var fetchData = new { accountid = "{60E1C27F-DD03-EC11-B6E5-000D3AA2E9C5}", industrycode = "5" /* Building Supply Retail */, name = "L%", transactioncurrencyid = "{F89D2C96-C802-EC11-B6E5-000D3AA2EB72}", isocurrencycode = "VND", contactid = "{74E1C27F-DD03-EC11-B6E5-000D3AA2E9C5}", parentcustomerid = "{60E1C27F-DD03-EC11-B6E5-000D3AA2E9C5}", transactioncurrencyid2 = "{F89D2C96-C802-EC11-B6E5-000D3AA2EB72}" }; var fetchXml = $@" <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'> <entity name='account'> <attribute name='name'/> <attribute name='primarycontactid'/> <attribute name='telephone1'/> <attribute name='accountid'/> <attribute name='industrycode'/> <attribute name='statuscode'/> <attribute name='statecode'/> <attribute name='donotpostalmail'/> <attribute name='numberofemployees'/> <attribute name='createdon'/> <attribute name='accountnumber'/> <attribute name='stageid'/> <order attribute='name' descending='false'/> <filter type='and'> <filter type='and'> <filter type='or'> <condition attribute='accountid' operator='eq' value='{fetchData.accountid}'/> <condition attribute='industrycode' operator='eq' value='{fetchData.industrycode}'/> </filter> <filter type='and'> <condition attribute='name' operator='not-null'/> <condition attribute='name' operator='like' value='{fetchData.name}'/> </filter> </filter> </filter> <link-entity name='transactioncurrency' from='transactioncurrencyid' to='transactioncurrencyid' link-type='inner' alias='am'> <attribute name='isocurrencycode'/> <filter type='and'> <condition attribute='transactioncurrencyid' operator='eq' value='{fetchData.transactioncurrencyid}'/> <condition attribute='isocurrencycode' operator='eq' value='{fetchData.isocurrencycode}'/> </filter> </link-entity> <link-entity name='account' from='accountid' to='parentaccountid' visible='false' link-type='outer' alias='a_57511732b5534cfbbcf2d280f9f8c6f1'> <attribute name='accountnumber'/> <attribute name='name'/> <attribute name='createdby'/> </link-entity> <link-entity name='contact' from='contactid' to='primarycontactid' link-type='inner' alias='ba'> <attribute name='lastname'/> <attribute name='fullname'/> <attribute name='firstname'/> <filter type='and'> <condition attribute='contactid' operator='eq' value='{fetchData.contactid}'/> <condition attribute='parentcustomerid' operator='eq' value='{fetchData.parentcustomerid}'/> <condition attribute='transactioncurrencyid' operator='eq' value='{fetchData.transactioncurrencyid2}'/> </filter> </link-entity> </entity> </fetch> "; var input = new { FetchXml = fetchXml, Url = $"https://org47503bc8.crm5.dynamics.com/api/data/v9.2" }; var json = SimpleJson.SerializeObject(input); var output = ConvertFetchXmlToWebAPI.Process(AppSettings.Service, null, null, json); var t = string.Empty; }