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

GorbushovSew

XRumer...
In addition, XRumer bypasses text protection against robots - questions like “How much will 2 + 2?”, “Name the capital of Russia”, etc.
The program knows more than 170,000 answers to such questions, all arithmetic is automatically calculated, and the knowledge base is updated monthly.
A set of unique technologies allows you to achieve very good and interesting results.
High-tech functions such as the Antispam thematic distribution system (a message is sent to each forum in accordance with the topics of this forum, regardless of language and region), the Question-Answer system and others - distinguish XRumer from other similar complexes, creating opportunities for real Smart and even socially useful mailing.
For Xrumer Acquisition Issues - http://bit.ly/2KDtGl7

Captcha recognition / automatic captcha input
Surely almost everyone came across an inscription when registering on any site: "Enter the number you see" and a distorted picture. This CAPTCHA (CAPTCHA, pictocode, ticket) is a graphic protection designed to distinguish between people and programs.
For Xrumer Acquisition Issues - http://bit.ly/2lgBzxz

<a href=http://www.sommarhus.nu/9/comment-page-1/#comment-51476>automatic captcha recognition</a> <a href=http://rybolovnyj-magazin.ru/blog/mikrodzhigovaya-lovlya-na-rekah-i-vodohranilischah#comment_166797>XRumer</a> <a href=http://guestbook.ent-moreira.izihost.com/index.php?&mots_search=&lang=francais&skin=&&seeMess=1&seeNotes=1&seeAdd=0&code_erreur=Zp7EoCIZRw>XRumer</a> 36e2799

GorbushovSew

Robertknike

http://bit.ly/30jI5Z6 - Urgently need a friend
http://bit.ly/2PW5ZH3 - Dating

http://bit.ly/2vBTcCL - health products
http://bit.ly/2KlgMqG - Adult Video Chat
http://bit.ly/3aGPqXD - Wheel of fortune
http://bit.ly/2VTRas9 - dating
http://bit.ly/3cJdafe - super prize draw
http://bit.ly/3cAQVIB - dating

Robertknike

DennisCot

http://bit.ly/39RLXW2 The easiest way to earn Bitcoins? Just change your browser to CryptoTab and receive payments to your balance every 10 minutes. You will get BTC for simply using it, even if just having CryptoTab browser window open. It takes less than 1 minute to start earning - http://bit.ly/38Wex7z

DennisCot

DennisCot

http://bit.ly/39RLXW2 It’s already a month as I’ve been using new browser. CryptoTab browser, to be exact. Do you want me to ask why? I’ll tell you. It doesn’t just browse well, but allows you to earn Bitcoin with ease! Learn more, follow the link - http://bit.ly/38Wex7z

DennisCot

DennisCot

http://bit.ly/39RLXW2 Friends, let me share with you a cool browser with built-in mining features, I've been using it few weeks now and results are great! You get paid in Bitcoins and payments come directly to your Bitcoin wallet. Download it here - http://bit.ly/38Wex7z

DennisCot

Brantrix

Hello! I like your site and uncontested communication. Thank. I desire be overpowering my thoughts here.

<a href=http://www.3ec0f4c78de5021b18.com>www.3ec0f4c78de5021b18.com</a>

Brantrix

BezgodovSew

http://bit.ly/2tpE9u7 - research paper services cheap College Admission Essay Writing Service –
Your New Secret Weapon
http://bit.ly/2tpE9u7 - need help with essay writing


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

[url=http://keinlebenohnekunst.de/node/4?page=13884#comment-694292]Research methodology dissertation[/url] [url=http://vmestecard-reg.ru/#comment-1220]Buy a literature review paper[/url] [url=http://jsshbx.com/english/lyb.asp]Academic writers online[/url] f1a4bdb

BezgodovSew