Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Getting the error: The request SetWordTemplate cannot be invoked from the Sandbox.

Posted on by 17,074

Hi Guys,

I have written a plugin code to set word template as shown below.

public void SetWordTemplate(IOrganizationService orgService, Entity docTemplate, string entityName, Guid recordId)
        {
            OrganizationRequest request = new OrganizationRequest("SetWordTemplate");
            request["Target"] = new EntityReference(entityName, recordId);
            request["SelectedTemplate"] = new EntityReference(docTemplate.LogicalName, docTemplate.Id);
            var response = orgService.Execute(request);
        }

While debugging the plugin using plugin profiler, it is woking fine and no errors are detected. The document template is getting attached to the notes in the record.

I am calling this plugin in a global action and on click of a ribbon button, I am calling the javascript to call this custom action.

But if I stop profiling the plugin step and click on the ribbon button, javascript is called and it invokes the action but I get a pop up as follows.

The request SetWordTemplate cannot be invoked from the Sandbox.

Also, the document template is not getting attached to the notes in the record.

Can anybody guide me to solve this issue?

Any help is appreciated.

*This post is locked for comments

  • Tulio Profile Picture
    Tulio 10 on at
    RE: Getting the error: The request SetWordTemplate cannot be invoked from the Sandbox.
    [quote user="Nithya Gopinath"]

    Hi Guys,

    I have written a plugin code to set word template as shown below.

    public void SetWordTemplate(IOrganizationService orgService, Entity docTemplate, string entityName, Guid recordId)
            {
                OrganizationRequest request = new OrganizationRequest("SetWordTemplate");
                request["Target"] = new EntityReference(entityName, recordId);
                request["SelectedTemplate"] = new EntityReference(docTemplate.LogicalName, docTemplate.Id);
                var response = orgService.Execute(request);
            }

    While debugging the plugin using plugin profiler, it is woking fine and no errors are detected. The document template is getting attached to the notes in the record.

    I am calling this plugin in a global action and on click of a ribbon button, I am calling the javascript to call this custom action.

    But if I stop profiling the plugin step and click on the ribbon button, javascript is called and it invokes the action but I get a pop up as follows.

    The request SetWordTemplate cannot be invoked from the Sandbox.

    Also, the document template is not getting attached to the notes in the record.

    Can anybody guide me to solve this issue?

    Any help is appreciated.

    [/quote]

    How your code stayed after use whats Markus Moser send?

    Can you share, please?

    Thank you!

  • Suggested answer
    Pradeep Rai Profile Picture
    Pradeep Rai 5,490 Super User 2024 Season 2 on at
    RE: Getting the error: The request SetWordTemplate cannot be invoked from the Sandbox.

    Please use below link:

    https://carldesouza.com/calling-an-dynamics-365-action-from-javascript/

  • Suyati Trial Profile Picture
    Suyati Trial 10 on at
    RE: Getting the error: The request SetWordTemplate cannot be invoked from the Sandbox.

    Hi,

    I am not able to trigger the plugin action using this js.I am stuck at the 1st line itself.So can I get an alternative for this

  • MS CRM DYNAMICS Profile Picture
    MS CRM DYNAMICS 580 on at
    RE: Getting the error: The request SetWordTemplate cannot be invoked from the Sandbox.

    Hi Nithya,

    Can we call SetWordTemplate without Process js  from Js?

  • RE: Getting the error: The request SetWordTemplate cannot be invoked from the Sandbox.

    Hello team,

    Am getting below error when calling setwordtemplate using custom workflow. Please guide.

    Code Snippet:

    OrganizationRequest req = new OrganizationRequest("SetWordTemplate");

                   req["Target"] =

                      new EntityReference("new_testbhp", new Guid(recordGuid));

                   req["SelectedTemplate"] =

                      new EntityReference("documenttemplate", new Guid(docTemplateGuid));

                   service.Execute(req);

    Exception in custom workflow

    Message: The request SetWordTemplate cannot be invoked from the Sandbox.

      at Microsoft.Crm.Sandbox.SandboxCodeUnit.ProcessException(Exception originalException, IExecutionContext context, SandboxClient client, SandboxCallTracker callTracker, Boolean isSafeToRetry, DateTime performanceExecutionStartTime, SandboxTracker tracker, Guid parentExecutionId, CrmException& crmException, String& assemblyContents)

      at Microsoft.Crm.Sandbox.SandboxCodeUnit.<>c__DisplayClass24_0.<Execute>b__0()

      at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute(ILogger logger, EventId eventId, ActivityType activityType, Action action, IEnumerable`1 additionalCustomProperties)

      at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute(ILogger logger, XrmTelemetryActivityType activityType, Action action)

      at Microsoft.Xrm.RemotePlugin.CrmProvider.RemotePlugin.Execute(IServiceProvider serviceProvider)

      at Microsoft.Xrm.RemotePlugin.CrmProvider.RemotePluginContainer.Execute(IServiceProvider serviceProvider)

      at Microsoft.Crm.Workflow.Services.ProxyCustomActivity.Execute(CodeActivityContext executionContext)

    -- End stack trace --

  • MS CRM DYNAMICS Profile Picture
    MS CRM DYNAMICS 580 on at
    RE: Getting the error: The request SetWordTemplate cannot be invoked from the Sandbox.

    Hi Nithya,

    If I will call action then action called custom workflow. How I can attach the document to notes in custom workflow. (Custom workflow having same issue like plugin?)

  • Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: Getting the error: The request SetWordTemplate cannot be invoked from the Sandbox.

    This code solved my issue.

    Thanks, Markus Moser.

  • Verified answer
    Markus_Moser Profile Picture
    Markus_Moser 65 on at
    RE: Getting the error: The request SetWordTemplate cannot be invoked from the Sandbox.

    We implemented the message on the client side, in this example with a static document template.

    The code works fine in a CRM Online environment.

    function generateWordDocument()
    {
        Process.callAction("SetWordTemplate",
            [
                {
                    key: "Target",
                    type: Process.Type.EntityReference,
                    value: new Process.EntityReference(Xrm.Page.data.entity.getEntityName(), Xrm.Page.data.entity.getId())
                },
                {
                    key: "SelectedTemplate",
                    type: Process.Type.EntityReference,
                    value: new Process.EntityReference("documenttemplate", "{587AACE7-A53C-E711-8107-5065F38AEA61}")
                }
            ],
            onWordDocumentGenerated
        );
    }
    
    function onWordDocumentGenerated()
    {
        Xrm.Page.ui.setFormNotification("Document generated!", "INFO", "documentGenerated");
    }

    You can also use a workflow to do the processing: https://community.dynamics.com/crm/b/crminogic/archive/2016/02/17/set-word-template-through-workflow-in-dynamics-crm-2016

  • Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: Getting the error: The request SetWordTemplate cannot be invoked from the Sandbox.

    Is there any alternative way to SetWordTemplate using code?

  • Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: Getting the error: The request SetWordTemplate cannot be invoked from the Sandbox.

    Any suggestions on this issue?

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