HI,
I tried with this https://nishantrana.me/2015/07/04/using-action-to-trigger-plugin-in-crm-20132015/
I created a button and added javascript code to trigger plugin with process.But its getting error
<s:Envelope xmlns:s =" http://schemas.xmlsoap.org/soap/envelope/ " > <s:Body > <s:Fault > <faultcode > s:Client </faultcode > <faultstring xml:lang =" en-US " > fz_bulkoptionset With Id = 57dbb357-e785-e811-a951-000d3ab10c56 Does Not Exist </faultstring > <detail > <OrganizationServiceFault xmlns =" http://schemas.microsoft.com/xrm/2011/Contracts " xmlns:i =" http://www.w3.org/2001/XMLSchema-instance " > <ActivityId > 3049fd27-14f3-4e6a-babd-195258424b0b </ActivityId > <ErrorCode > -2147220969 </ErrorCode > <ErrorDetails xmlns:a =" http://schemas.datacontract.org/2004/07/System.Collections.Generic " > … </ErrorDetails > <Message > fz_bulkoptionset With Id = 57dbb357-e785-e811-a951-000d3ab10c56 Does Not Exist </Message > <Timestamp > 2018-07-13T08:06:36.9119581Z </Timestamp > <ExceptionRetriable > false </ExceptionRetriable > <ExceptionSource i:nil =" true " / > <InnerFault i:nil =" true " / > <OriginalException i:nil =" true " / > <TraceText i:nil =" true " / > </OrganizationServiceFault> </detail> </s:Fault> </s:Body> </s:Envelope>
fz_bulkoptionset With Id = 57dbb357-e785-e811-a951-000d3ab10c56 Does Not Exist but for fz_bulkoptionset entity its the id i checked in url when we click on entity i saw id in link.
Here the code for That
Process Name:fz_BulkImportGlobalOptionset
Javascript Code
function generatebulkimport() { try { var entityId = "57DBB357-E785-E811-A951-000D3AB10C56"; var entityName = "fz_bulkoptionset"; var requestName = "fz_BulkImportGlobalOptionset"; var xml = "<s:Envelope xmlns:s=\"schemas.xmlsoap.org/.../envelope\"><s:Body><Execute xmlns=\"schemas.microsoft.com/.../Services\" xmlns:i=\"www.w3.org/.../XMLSchema-instance\"><request xmlns:a=\"schemas.microsoft.com/.../Contracts\"><a:Parameters xmlns:b=\"schemas.datacontract.org/.../System.Collections.Generic\"><a:KeyValuePairOfstringanyType><b:key>Target</b:key><b:value i:type=\"a:EntityReference\"><a:Id>"+entityId+"</a:Id><a:LogicalName>"+entityName+"</a:LogicalName><a:Name i:nil=\"true\"/></b:value></a:KeyValuePairOfstringanyType></a:Parameters><a:RequestId i:nil=\"true\"/><a:RequestName>"+requestName+"</a:RequestName></request></Execute></s:Body></s:Envelope>"; var xmlHttpRequest = new XMLHttpRequest(); xmlHttpRequest.open("POST", Xrm.Page.context.getClientUrl() +"/XRMServices/2011/Organization.svc/web", false); xmlHttpRequest.setRequestHeader("SOAPAction","schemas.microsoft.com/.../Execute"); xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); xmlHttpRequest.setRequestHeader("Accept", "application/xml, text/xml, */*"); xmlHttpRequest.setRequestHeader("Content-Length", xml.length); xmlHttpRequest.send(xml); var resultXml = xmlHttpRequest.responseText; alert(resultXml); } catch(err) { alert(err.message); } }
My Plugin Code
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Metadata; using Microsoft.Xrm.Sdk.Messages; using Microsoft.Xrm.Sdk.Query; namespace Bulkoptionsetimport { public class Class1 : IPlugin { public void Execute(IServiceProvider serviceProvider) { // Obtain the execution context from the service provider. IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService)); // Get a reference to the Organization service. IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = factory.CreateOrganizationService(context.UserId); try { //OrganizationRequest req = new OrganizationRequest("fz_BulkImportGlobalOptionset"); //req["Target"] = new EntityReference("fz_bulkoptionset", new Guid ("57DBB357-E785-E811-A951-000D3AB10C56")); //////Read configuration //OrganizationResponse response = service.Execute(req); //Read configuration QueryExpression optionsetconfig = new QueryExpression() { EntityName = "fz_bulkoptionset", ColumnSet = new ColumnSet(true), Criteria = { Conditions = { //new ConditionExpression("fz_name", ConditionOperator.Equal, "Configurations"), //new ConditionExpression("statecode", ConditionOperator.Equal, 0) } } }; EntityCollection _Records = service.RetrieveMultiple(optionsetconfig); foreach (Entity _Entity in _Records.Entities) { InsertOptionValueRequest insertOptionValueRequest = new InsertOptionValueRequest { Value = Convert.ToInt16(_Entity.Attributes["fz_optionset"]), OptionSetName = _Entity.Attributes["fz_name"].ToString(), Label = new Label(_Entity.Attributes["fz_optionsetlabel"].ToString(), 1033) }; //execute the request InsertOptionValueResponse optionResponse = (InsertOptionValueResponse)service.Execute(insertOptionValueRequest); } } catch (Exception ex) { tracingService.Trace("accountPlugin: {0}", ex.ToString()); throw; } } } }
*This post is locked for comments