Params for mergefields in word docs

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.

:slight_smile: so, is it possible through the cloud APIs?

I’d like to send a URL to a word file, one URL to a CSV file to get a merged PDF file back that contains a copy of the word doc template for each record in the PDF file. It would be also fine if steps in between would be necessary, as long as it’s possible. Could you point me to the API funcitons I need to use to achieve this?

Hi Nils,


If I understand you correctly you need to get each page of the document as a separate object - is it correct? If yes than you can split the fields object by field properties (depending on what page field is placed), as you can see when you receive a list of fields you have all info about each field. After that you will be able to merge each object separately.

Also please investigate all available API methods here - http://www.groupdocs.com/docs/display/assemblyapi/API+Reference

Best regards.

sorry, I think you don’r understand what I’m up to. I’d like to use the API to get a bulk output like described here:

Use mail merge to personalize letters - Microsoft Support



Cheers



Nils

Hi Nils,


Sorry for the delay. Unfortunately there is no such API methods to achieve the same goal. But as a workaround you can call MergeTemplate methodseveral times with different datasources and same template.

Sorry for the inconvenience.

Hey Pavel,



Thanks a lot for your help! Well, I think requesting for each record wouldn’t work as we are talking about to many records. However, I will use the HTML conversion then. There is no way to get the HTML output in one file, is it?

Currently I’m getting a zip archive with webfonts, css files and the html file. it would be great if there is an option to integrate all these files into one HTML file.



Regards



Nils

Hi Nils,


Thank you for coming back. I will discuss this with our Product team and then return to you.

Best regards.