web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

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

(0) ShareShare
ReportReport
Posted on by 17,078

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

I have the same question (0)
  • Nithya Gopinath Profile Picture
    17,078 on at

    Any suggestions on this issue?

  • Nithya Gopinath Profile Picture
    17,078 on at

    Is there any alternative way to SetWordTemplate using code?

  • Verified answer
    Markus_Moser Profile Picture
    65 on at

    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
    17,078 on at

    This code solved my issue.

    Thanks, Markus Moser.

  • MS CRM DYNAMICS Profile Picture
    592 on at

    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?)

  • Ashwini Shashidhara Profile Picture
    27 on at

    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
    592 on at

    Hi Nithya,

    Can we call SetWordTemplate without Process js  from Js?

  • Suyati Trial Profile Picture
    10 on at

    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

  • Suggested answer
    Pradeep Rai Profile Picture
    5,489 Moderator on at

    Please use below link:

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

  • Tulio Profile Picture
    10 on at
    [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!

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans