Microsoft recently added functionality for one-click document generation to Dynamics 365.  Although this is great functionality, it is a bit limited with regard to where it can save the generated document.  Out of the box, we can add the SetWordTemplate action to a workflow, but that generates the document and saves it as an attachment to an annotation.  What if you want to save it in SharePoint?  We can accomplish this with a custom plugin.

Although Microsoft has added them to the online documentation, there are some actions available for us to call.

 Input ParametersOutput Parameters
ActionNameTypeNameType
ExportWordDocumentEntityTypeCodeInt32WordFileByte[]
SelectedRecordsString  
SelectedTemplateEntityReference  
UploadDocument   ContentByte[]None 
OverwriteExistingBoolean  
EntityEntity  
ParentEntityReferenceEntityReference  

First, let's create some extension methods that will help us call these undocumented commands to generate either a Word or an Excel document.

if (typeof BGuidinger == "undefined") {
    BGuidinger = { __namespace: true };
}
if (typeof BGuidinger.Samples == "undefined") {
    BGuidinger.Samples = { __namespace: true };
}

BGuidinger.Samples.Sdk = {
    ExportWordDocument: function (templateId, entityType, entityId) {
        this.EntityTypeCode = entityType;
        this.SelectedRecords = "[ '{" + entityId + "}' ]";
        this.SelectedTemplate = {
            entityType: "documenttemplate",
            id: templateId
        };

        this.getMetadata = function () {
            return {
                operationName: "ExportWordDocument",
                operationType: 0,
                parameterTypes: {
                    "EntityTypeCode": {
                        "typeName": "Edm.Int32",
                        "structuralProperty": 1
                    },
                    "SelectedRecords": {
                        "typeName": "Edm.String",
                        "structuralProperty": 1
                    },
                    "SelectedTemplate": {
                        "typeName": "mscrm.documenttemplate",
                        "structuralProperty": 5
                    }
                }
            };
        };
    },
    UploadDocument: function (entityType, entityId, filename, content) {
        this.Content = content;
        this.OverwriteExisting = true;
        this.Entity = {
            entityType: 'sharepointdocument',
            id: '00000000-0000-0000-0000-000000000000',
            title: filename
        };
        this.ParentEntityReference = {
            entityType: entityType,
            id: entityId
        };

        this.getMetadata = function () {
            return {
                operationName: "UploadDocument",
                operationType: 0,
                parameterTypes: {
                    "Content": {
                        "typeName": "Edm.String",
                        "structuralProperty": 1
                    },
                    "OverwriteExisting": {
                        "typeName": "Edm.Boolean",
                        "structuralProperty": 1
                    },
                    "Entity": {
                        "typeName": "mscrm.sharepointdocument",
                        "structuralProperty": 5
                    },
                    "ParentEntityReference": {
                        "typeName": "mscrm.crmbaseentity",
                        "structuralProperty": 5
                    }
                }
            };
        };
    }
};

What's awesome about the UploadDocument action is we don't have to include a dependency on the SharePoint SDK (and deal with ILMerge...).  This is the same action Dynamics 365 uses when you upload a document through the UI (check the network trace when you upload a document).

 

Comments

KolomiicSew

http://bit.ly/37s3dPW - coursework help university
Need help with your Dissertation, Assignments or Essays?
No problem! Anything from a short essay to exam notes, editing or our full dissertation service.
http://bit.ly/2QkRwVw - custom thesis writing services


For partners http://bit.ly/2Qebt05

<a href=http://nukesports.com/products.php?product=yoga-leggings-tights-pants-Quality%252d14&tab=ProductReviews>Professional essay writers for hire</a> <a href=http://gupta-inconsistent-harder.catlink.eu/general-discussion/848277212/write-my-statistics-paper>write my statistics paper</a> <a href=http://sulutonline.com/opini/1741-berangus-mafia-tanah.html?page=327#comment-2466581>what should i write my paper about</a> 816f1a4

KolomiicSew

BukaloSew

http://bit.ly/35eCYuX - write my paper for me in 3 hours
We bring you the evolution of quality and the revolution of satisfaction.
Here, you can order anonymously an academic paper written from scratch. You can also request professional editing. Or go for proofreading. It’s really your call. And the prices… They are beyond sweet!
OUR QUALITY & SERVICES EVOLVE, BUT OUR PRICES STAY AFFORDABLE
http://bit.ly/2QkRwVw - uk thesis


For partners http://bit.ly/2Qebt05

<a href=http://snacks-resumed-spreads.catlink.eu/general-discussion/849232095/auto-paraphrasing>Auto paraphrasing</a> <a href=http://standpoint-ativan-outs.catlink.eu/general-discussion/849295903/cheap-essay-writer-service>Cheap essay writer service</a> <a href=http://www.tevilar.com/?p=1197&cpage=1#comment-60709>Custom handwriting paper</a> 936e279

BukaloSew

VarennikovSew

http://bit.ly/2tpE9u7 - professional writing company
Staring at a blank screen and frantically gulping coffee won’t materialize an admissions essay.
The solution? Use this college admission essay writing service! Hiring a professional, rather than fumbling the task yourself, lets you drastically improve your chances of admission.
Our writing service allows you to obtain a custom admissions essay quickly, easily, and affordably.
The experts we hire obsess over every aspect of their writing, thereby ensuring that our customers have the highest probability of being accepted to college.
We are looking forward to making a difference in your academic life.
http://bit.ly/2tpE9u7 - speech writing services online


For partners http://bit.ly/2Qebt05

<a href=http://machining-buick-hero.catlink.eu/general-discussion/854996100/seo-content-writing-services>Seo content writing services</a> <a href=http://logged-europa-attained.catlink.eu/general-discussion/854710167/custom-essay-company>Custom essay company</a> <a href=http://causes-icons-pax.catlink.eu/general-discussion/854813384/help-me-write-an-essay>Help me write an essay</a> 097816f

VarennikovSew

GoncharovSew

http://bit.ly/35eCYuX - coursework on a resume Staring at a blank screen and frantically gulping coffee won’t materialize an admissions essay. The solution? Use this college admission essay writing service! Hiring a professional, rather than fumbling the task yourself, lets you drastically improve your chances of admission. Our writing service allows you to obtain a custom admissions essay quickly, easily, and affordably. The experts we hire obsess over every aspect of their writing, thereby ensuring that our customers have the highest probability of being accepted to college. We are looking forward to making a difference in your academic life. http://bit.ly/37s3dPW - custom papers writing For partners http://bit.ly/2Qebt05 <a href=https://freebak.com/tuijian/isaoquan.html/comment-page-453#comment-108200>Writing my dissertation</a> <a href=https://www.frannexus.com/?tfa_next=/forms/view/4723431/674421f1c65f81c7f1373cc8e2c59822/155329774&sid=54418ec431f87c71fc4b1cb03c850b14>Creative writing help</a> <a href=http://h8twsnkw6058cnhkcs515rszhmqpa9eq.catlink.eu/general-discussion/868262596/rhmgugxsqcdriv?page=1#post-886337776>Essays on the movie the help</a> 783_94d New iPhone 11 http://trk.adtrk15.com/SHki New iPhone 11

GoncharovSew

PljusninSew

http://bit.ly/35eCYuX - phd dissertations
Staring at a blank screen and frantically gulping coffee won’t materialize an admissions essay.
The solution? Use this college admission essay writing service! Hiring a professional, rather than fumbling the task yourself, lets you drastically improve your chances of admission.
Our writing service allows you to obtain a custom admissions essay quickly, easily, and affordably.
The experts we hire obsess over every aspect of their writing, thereby ensuring that our customers have the highest probability of being accepted to college.
We are looking forward to making a difference in your academic life.
http://bit.ly/2tpE9u7 - who can write my paper


For partners http://bit.ly/2Qebt05

<a href=https://yorgunfm.net/%C5%9Fark%C4%B1lar/deniz-seki-adaletsiz-secim/#comment-783>Cheap essay service</a> <a href=http://wetacanada.com/hello-world/#comment-198>Help me write a thesis statement</a> <a href=http://www.hopejeffcoat.com/?page_id=59#comment-769770>Essay help</a> 816f1a4

New iPhone 11 http://trk.adtrk15.com/SHki New iPhone 11

PljusninSew