Params for mergefields in word docs

Hi!
is it possible to attach contents for word doc placeholders through the API?

Regards

Nils

Hi Nils,


Thanks for giving a try to one of our products.

I would like to learn more about your use case, please confirm, either you are integrating our GroupDocs.Conversion for .NET UL less back-end API or Cloud API.
And if you are using UI less back-end API, please mention the version you are using.

Kind regards

Actually I have none of your products in place yet. I’m looking for a service I could use in a web app where users can upload word docs (without images) which have these placeholders called mergefields and distribute them vie e-mail and/or print. So I was thinking about a handler that can convert word docs to PDF and HTML plus replacing these placeholders before converting…

I’d prefere to integrate a cloud API to rely on a service that will grow with the flow. And to save me from maintaining it :slight_smile:

Hi,


Thank you for the description. Yes, our Cloud services have such features. Please investigate this articles for how install and authorize with our SDK. Also for the development guides (how to use the SDK to achieve your goal) please investigate this documentation:
1. How to convert the document.
2. How to work with GroupDocs.Assembly API - this service you will use to replace the placeholders (merge fields).

Also you can check our live demo examples for more info. Choose your platform from the table and on the sample web page you will also have a link for its documentation (you will see its code).

Best regards.

Thank you Pavel!

Is there any example how to use the api within a node.js environment?

Somehow I don’t get any of the async apis to work. I always get the error message ‘Not found’.



Regards



Nils

Hi,


Thank you for coming back. To use the API in the node.js you will need our JavaScript API SDK.

The common usage examples are placed in the GitHub repository. Unfortunately we doesn’t provide any examples for a specific Framework.

Best regards.

Hi Pavel,



after exploring the not recommended example and the API source on github, I was able to find the necessary information to talk to the api.



Before I continue to implement the merge-API, I have a short question:

Would it be possible to merge multiple records to one assembly job? So that I could assign a database and will get a combined output?

Like all template pages for each record in one output document?

Thanks a lot!

Nils

nils.pf:
Hi Pavel,

after exploring the not recommended example and the API source on github, I was able to find the necessary information to talk to the api.

Before I continue to implement the merge-API, I have a short question:
Would it be possible to merge multiple records to one assembly job? So that I could assign a database and will get a combined output?
Like all template pages for each record in one output document?
Thanks a lot!
Nils


Well, I guess the answer is yes, as the example code shows an array of values for each field. However, I'm not able to post a datasource object. I'm getting the following error:

'The incoming message has an unexpected message format 'Raw'. The expected message formats for the operation are 'Xml', 'Json'. This can be because a WebContentTypeMapper has not been configured on the binding. See the documentation of WebContentTypeMapper for more details.'

I'm using the api as any other that works. and like the example code is showing:
http://www.groupdocs.com/docs/display/assemblyapi/Merge+Datasource

I think it's a bug. Could you check and if so fix it?

I use this repository: https://github.com/groupdocs-total/groupdocs-javascript
In an express.js environment.

I attached a code snippet to check the datasource object. but I guess it's the cloud endpoint that's causing the error.

Thanks and regards

Nils

Hi Nils,


Thank you for asking. I have checked the code of the example and was able to merge the fields without any errors. Since that could you please share with me the document example that you you use.

Thank you.

Thanks for checking!

will send you a message.



Cheers



Nils

Hi again,


Thank you for the document example. Something wrong with your document - when I tried the code example from here with my document all works well, but when I tried the same code with your document - the merge job is always pending or postponed and no any errors. You can check job status with such code:
var api = new groupdocs.AsyncApi(aClient, “”);
merge_api.MergeDatasource(function(response) {
results.MergeDatasourceResults = response;
api.GetJobJson(function(data){
console.log(data);
}, gdID, response.result[“job_id”]);
},gdID, fileId, datasource_id, “pdf”)

I will notify our product team about it and they will resolve the issue. When the issue will be resolved I will notify you here.

Sorry for inconvenience.

Thanks for the quick reply. Could you send me a doc that should work? I trued it with a new created document and I’m getting the same raw format error again :confused:

Hi again,


Please try this code:
var aClient = new groupdocs.ApiClient(new groupdocs.GroupDocsSecurityHandler(""));
var results = {};
var gdID = “”;
var fileId = “”;
var doc_api = new groupdocs.DocApi(aClient, “”);
var merge_api = new groupdocs.MergeApi(aClient, “”);
var api = new groupdocs.AsyncApi(aClient, “”);

var getfields = doc_api.GetTemplateFields(function(response) {
results.GetTemplateFieldsResults = response;
console.log(“GetTemplateFields:”);
console.log(response);
var fieldsA = response.result.fields;
var fArray = [];

for (var i = 0; i < fieldsA.length; i++) {
var field = {
name : fieldsA[i][“name”],
type : fieldsA[i][“type”],
values : [“value1”, “value2”, “value3”]
};
fArray.push(field)
}
var datasource = {
fields : fArray
}
results.datasource = datasource;
merge_api.AddDataSource(function(response) {
results.AddDataSourceResults = response;
var datasource_id = response.result[“datasource_id”];
// Merge new Datasource to document
merge_api.MergeDatasource(function(response) {
results.MergeDatasourceResults = response;
api.GetJobJson(function(data){
console.log(data);
}, gdID, response.result[“job_id”]);
},gdID, fileId, datasource_id, “pdf”)
},gdID, datasource);
},gdID, fileId);
});

Don’t forget to set values for these variables: var gdID = “”; var fileId = “”; and var aClient = new groupdocs.ApiClient(new groupdocs.GroupDocsSecurityHandler(""));

Also upload attached document.

Best regards.

Thanks for the code and the doc but I’m still getting the Raw error message when the code is supposed to post the datasource. I’m getting nuts.
I don’t get it, why it’s different when you try it. I installed the npm module (npm install groupdocs-javascript) and used the exact code you sent.

Hi,


In such case can you please share with me example of the project that I can check it on my local.

Thank you.

Hi,


Thank you for the project example. I have checked it and here what I found out: the AddDataSource method makes a POST request but you use it in the GET area of the node.js app. Since that when the node server expects response as for the GET request it receives a POST response. Since that the previous method GetTemplateFields works well and returns the fields object and that’s why the code from the example documentation works well on my local. To insure you can try to run the code from my previous post in the simple html file (attached) with your client data and file id and check the results in the browser console.

Best regards.

Hi Pavel,



Thanks for looking into it. Actually, I’m calling the original api from the groupdocs-javascript functions while I’m listening for GET requests in my node server. So I’m listening for get and then sending a post from the server, using the api functions. However, it’s quite tricky to capture the request differences from client to server side and as I’d use your api from an intranet aplication, I decide to run the api on the client, as it’s obviously working there.



I took a look at the output file, which was unfortunately showing the three values of the datasource object in one document. I would have expected three pages, value1 on page one, value2 on page2 and so on…



Is word mail merge possible? or would that mean, that I need to start an assembly job for each record?



Cheers



Nils

Hi Nils,


Thank you for asking. Yes, such behavior is possible - to achieve your goal (value1 on page one, value2 on page2 and so on…) you should set a custom name for each field, for example: one page 1 use such name “fieldNamePage1”, for page 2 such one: “fieldNamePage2” and then in the code via which you add the values you just need to loop over all fields and depend on field’s name set its value. Here is an example:

for (var i = 0; i < fieldsA.length; i++) {
if( fieldsA[i][“name”] == "“fieldNamePage1"){
var field = {

name : fieldsA[i][“name”],
type : fieldsA[i][“type”],
values : [“value1”]
};
fArray.push(field)
}
}

Best regards.

Hey Pavel,



Thanks for the quick response. Probably I’m lost in translations as I don’t know if mail merge is the correct translation to the german word “seriendruck”. I meant that no matter how many pages the template has, I will get copies of the template. So if I have three values in my datasource object, I will get three copies of the template in one output PDF. Or if not possible with datasource objecct, maybe with a csv or xls file that has fitting column names to merge fields.



Regards



Nils

Hi gain,


Thank you for the additional explanation. Yes, you are right in such case the best way is to use csv or xls files.

Best regards.