Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Javascript issue with Plugin

Posted on by 240

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.

0066.Capture.PNG

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

  • Suggested answer
    Shahbaaz Ansari Profile Picture
    Shahbaaz Ansari 6,203 on at
    RE: Javascript issue with Plugin

    Check below link for calling Plugin from javascript,

    dynamics365learning.wordpress.com/.../clone-entity-record

    Best Regards,

    Shahbaaz

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Javascript issue with Plugin

    Hi,

    Based on your screenshot, "57dbb357-e785-e811-a951-000d3ab10c56" is the id of your solution which you opened and not the id of the record for your fz_bulkoptionset .

    To get the id of the particular record, you need to open that record in a new window. You can also do this by clieking on the tilted arrow on the top right corner of the record.

    Or, if you are working on Chrome, you can download this chrome extension, which has an option to get the record id.

    chrome.google.com/.../bjnkkhimoaclnddigpphpgkfgeggokam

    Hope this helps.

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Javascript issue with Plugin

    Hello,

    Are you sure that entity with "57DBB357-E785-E811-A951-000D3AB10C56" id exists in CRM? It seems that no...

  • Suggested answer
    sandeepstw Profile Picture
    sandeepstw 4,601 on at
    RE: Javascript issue with Plugin

    Hi,

    I will suggest to create a dummy entity and attached plugin on created or update event of custom entity. Then call create method  using js. It will fire plugin.

    Hope it helps.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans