How to populate a docusign template using a C# dictionary? - c#

How can I populate a docusign template using a C# dictionary via the docusign .Net client?
I read somewhere a docusign template with custom html but could not find any examples online.

the Envelope object has a couple of fields you will need:
TemplateId - is like an EnvelopeId a GUID for a unique template
TemplateRoles - is a collection of TemplateRole objects that represents the roles/recipients for this template.
In order to get this information for a given template - you would need to call use the Template class and call the GetTemplate() method/API to get all information for a template. this would include the roles/recipients (As well a more things in the json, which we just pass back as is) here is the important things:
var recipients = json["recipients"];
var subject = (string)json["emailSubject"];
var blurb = (string)json["emailBlurb"];
I can share a bit more code of looping through the recipients and adding them to the TemplateRoles if you want. Let me know if this is the direction you want to go and how else I can help.

Related

Reading task enterprise custom field values from mpp file using mpxj

I'm trying to read task details from a mpp file using net.sf.mpxj library. However, when trying to read custom fields, I get a byte array which I do not know what to do with! It is not the exact value of the custom field from that specific task. Can anyone tell me what to do?
ProjectReader reader = new MPPReader();
ProjectFile project = reader.read(#"C:\EPM\test2.mpp");
foreach (net.sf.mpxj.Task task in project.Tasks)
{
var Value = task.GetFieldByAlias("My Custom Field Name");
}
The "Value" will be a byte array and I do not know how to get the real value from it.
UPDATED ANSWER:
As of MPXJ 10.7.0 you can retrieve correctly typed values for enterprise custom fields. You'll also find a CustomFieldDataType attribute as part of the CustomField class which indicates what type you'll be retrieving.
(One interesting "gotcha" is that if your MPP file contains an enterprise custom field which is based on a lookup table, i.e. the user can only select from a fixed set of values, the user-visible text is NOT stored in the MPP file. You'll only get back a GUID representing the value the user has selected. Microsoft Project itself has this same issue... if you open the MPP file when you're not connected to Project Server, these values will appears as blanks...)
ORIGINAL ANSWER:
The main problem is unfortunately that MPXJ doesn't currently offer the same level of support for Enterprise Custom Fields as it does for other fields. While it is able to identify Enterprise Custom Fields and the aliases they've been given, at the moment it is only able to read the raw bytes representing the field data.
Enterprise Custom Fields are not as commonly used as other field types so there hasn't been as much time invested in locating the definitions of these fields in the MPP file. The field definition will contain the type information necessary to convert from the raw bytes to the expected data type.
Improved support for Enterprise Custom Fields is on the "to do" list for MPXJ.

How to apply a multi-document template

The general process
Documents are uploaded to DocuSign creating a new Envelope.
Templates are applied to this Envelope.
Recipients are updated to make sure there is no mixup with signers from the template
The Envelope is sent to the signers.
Intended use of templates
The primary use of templates is to allow users to upload documents and use all other information from templates like fields and other setting for the uploaded documents. Signers can also be freely set and overwrite the ones defined in the template.
For applying templates we use https://developers.docusign.com/docs/esign-rest-api/reference/envelopes/envelopetemplates/applytodocument/
The Template
The template consist of 2 documents. The first document has 3 pages and the second document has 2 pages.
There is one signer. A signature box is added to the last page of both documents.
The Problem
Test scenario: The exact same documents as in the template. This results in the signature box on the second document is not set.
Test scenario: Use the 3 page file for both documents. This results in the signature box being put on page 3 of both documents. So it looks like the assignment works only from document 1 to all the other documents
Test scenario: Use different 3 page documents that match the template for both documents. The result is the same as in the 2. test scenario.
What I tried
The described scenarios are based on this (simplyfied) code for applying the templates:
//variables envAPI (class EnvelopesApi), accountId, templateId and envelope (class Envelope) are already set
DocumentTemplateList templateList = new DocumentTemplateList();
templateList.DocumentTemplates = new List<DocumentTemplate>();
templateList.DocumentTemplates.Add(new DocumentTemplate()
{
TemplateId = templateId,
DocumentId = "1"
});
envAPI.ApplyTemplateToDocument(accountId, envelope.EnvelopeId, "1", templateList);
templateList = new DocumentTemplateList();
templateList.DocumentTemplates = new List<DocumentTemplate>();
templateList.DocumentTemplates.Add(new DocumentTemplate()
{
TemplateId = templateId,
DocumentId = "2"
});
envAPI.ApplyTemplateToDocument(accountId, envelope.EnvelopeId, "2", templateList);
//some recipient checking is done here
envAPI.Update(accountId, envelope.EnvelopeId, envelope);
I also tried using more entries in templateList.DocumentTemplates but that only caused INVALID_REQUEST_BODY errors.
I realized the DocumentID property of the documents in the templates are very different after the first file. My test template has 1 for the first document and the ID of the second document is a very large number. Using this large number also causes INVALID_REQUEST_BODY errors.
Is this actually correct and the error is somewhere else? Because it looks like it should work this way. Or is the problem located somewhere else?
The workflow that you are trying is a perfect place to use a composite template. The recommendation is use one composite template per document. In one POST envelopes call you can swap out the documents on the templates with documents at runtime and apply server (saved) templates to the documents. You can add recipients, drop recipients by not including them, and also add tabs or write values to tabs at runtime. See:
https://www.docusign.com/blog/dsdev-from-the-trenches-composite-templates
https://www.docusign.com/blog/dsdev-why-use-composite-templates
To answer my own question: This doesn't work. At least not this way.
Yes, composite templates are one way of dealing with this requirement but then again, why do multi-document templates even exist?
So the answer is quite simple: Do it the other way around.
To use a multi-document template properly, the template needs to be the starting point. Use a template and replace the files to create an evenlope instead of creating an envelope first and then applying templates to the envelope.

How to set drop down list control in Word document using c#?

I am having issues with setting a drop down list control in ms word document using Novacode-Docx. e.g. Gender from drop down list.
I have got some text replacement but that's easy. I have done that. Just the drop down list I am struggling with.
If there is any solution in c# other than using Novacode-Docx I am happy to implement that.
I haven't included any code for the reason that I don't know how to set or get the drop down list values from Ms word document using c#. I have tried google but didn't get any thing related to drop down list.
Here is a sample DropDown.
I have used Drop down list from Developer option and used the properties to add items to it.
Here is the actual List
To access the list of a content control dropdown use the Add method. I have no idea whether the library you're using provides access to that. The following code sample is standard C#:
object oLstEntryValue = "1";
object oLstEntryIndex = 1;
ContentControl.DropdownListEntries.Add("entry caption", ref oLstEntryValue, ref oLstEntryIndex);
The last two parameters are optional, so you can also pass Type.Missing if you don't want/need to specify them.

How to perform structured searches in Google Sheets API that return scalar values in C#

I'm using the Google Sheets API from C#. How do you create structured queries that return scalar values using the c# API?
The code I'm trying looks is listed below (though I have also tried using a SpreadsheetQuery (where I can successfully implement WHERE searches). With this code, I'm always getting zero entries returned.
public int MaxId(string tableName)
{
//Get the Worksheet
var worksheet = GetTable(tableName);
AtomLink listFeedLink = worksheet.Links.FindService(GDataSpreadsheetsNameTable.ListRel, null);
ListQuery query = new ListQuery(listFeedLink.HRef.ToString());
//This line doesn't seem to get processed correctly.
query.Query = "select max(id)";
ListFeed feed = this._spreadsheetHelper._service.Query(query);
var entriesC = feed.Entries.Count;
//TODO
return -1;
}
The same problem seems to exist in Java... As mentioned in Faraz's answer, you can use Google's query language to do database-like queries against Google spreadsheets, with the following caveats:
the URLs are no longer spreadsheets.google.com/a/google.com/tq?key=<document key>&tq=<query>, but https://docs.google.com/spreadsheets/d/<document key>/gviz/tq?tq=<query>
I had problems with IllegalArgumentException(“Trying to set foreign cookie”) when using the new URLs – see related question Google sites API, IllegalArgumentException("Trying to set foreign cookie") after RedirectRequiredException
the response is json embedded in javascript with a MIME type set to application/javascript, which isn't recognized by the API (so far as I can tell), sooo...
you have to create the new type and add it to the service object
create a parser to convert the response to the API's recognized Feed/Entry types ( a hack since the Entrys won't actually correspond to any cells in the worksheet ) along with some code to strip out the enclosing javascript
also note that other response formats are available using the tqx=out:<output type> parameter. Formats I was able to get were out:html and out:csv. out:tsv-excel is also documented but I couldn't get it to work. None of these formats are recognized by the API either...
I would much prefer an official, Google-supported solution (if there is one) to coding all this up myself, so I'm awaiting a fuller answer. If rolling your own is the only way to go, though, please point out if there's a right way to do it.
Google offers query mechanism, but not the way it works for SQL.
Have a look at this: Google Query Language Reference

Rendering Dynamic asp.net webpage into string invoked from another page

The question basically drill's down to these two C# 2.0, ASP.NET 2.0 webpages.
viewtemplate.aspx
generatetemplate.aspx
Purpose of these:
viewtemplate.aspx - Displays Email template defined in 'generatetemplate.aspx', with client assigned data pulled from database
generatetemplate.aspx - Is the actual page that contains place holders for client to put data.
[i named it so because that's the file i will be generating email to be sent from]
Requirement:
I will be requesting the generatetemplate.aspx from viewtemplate.aspx
, get the rendered output of generatetemplate.aspx and then send that output as email to the recipients.
It is the rendering part which i don't know how to do.
Note:
I will be calling generatetemplate.aspx from viewtemplate.aspx with query string so that generatetemplate.aspx will Pull value from database and then render rather than rendering with default values
You wish to get the rendered HTML output of running the page? You can download it from an HTTP request like a browser would with the WebClient class.
string generated = new WebClient().DownloadString("generatetemplate.aspx?myparams=params");
"generated" will then contain rendered output that you can do whatever you like with.
if I got question right, this is looks dodgy a bit.
I've used XSL + XML for such case. So you just prepare data in XML format, than applying XSL layout and thats it.

Categories

Resources