0 votes

As a follow up of my other question: https://overflow.efficy.com/?qa=2741/how-to-automatically-add-serie-products-linked-to-document

I used CopyDetails2 in my serverscript to copy the linked products from one document 'template' to another document. The copy is coming from an existing template document with PRODUCTS, PRICES and QUANTITIES.The only problem I've got now is to also copy the column QUANTITY. Now it only copy's the standard settings for every product.

So I've got 2 questions now:
1. How can I succesfully copy all details from the template, including the QUANTITY, PRICE and KSORT?
2. Is it a problem that K
RELATION in DOCUPROD is used more than once, as long as the KDOCUMENT and K_PRODUCT is different?

Would be perfect if there is a solution for this. Thanks for your help!

Database.CopyDetails2(editHandle, 31, templateKey, [ntProd], false, false);

My Complete code in editCmd.js

function docuAddProducts() {
        //deze regel gaat er nog vanuit dat de VM wordt gevulv vanuit een opportunity. Zo aanpassen dat dit flexibel wordt, ook voor projecten.
        url: format("dialog?_macrofile=MacroAjax&_macro=RunScript&file=Winkelwagentje;libjson&func=docuAddProducts&editHandle={editHandle}"),
        type: "GET",
        success: function (html, textStatus, jqXHR) {
            if (IsNotEfficyErrorHtml(html, function(errorMsg) {alert(errorMsg)})) {

And my complete code in the serverscript

function docuAddProducts() { 
var editHandle = StrToFloatDef(Request.Argument("editHandle"), 0);
var Oppo = Database.GetMainDetail(editHandle, ntOppo);
var Proj = Database.GetMainDetail(editHandle, ntProj);
var dienst = 0

if (Oppo != 0){ 
    var oppoContext = Database.OpenConsultContext(ntOppo);
    var oppoDS = Database.Consult(oppoContext, Oppo, true);
    var dienst = oppoDS.FieldByName('F_DIENST').AsString;
    docuProdCopyDetails (dienst);

if (Proj !=0){
    var projContext = Database.OpenConsultContext(ntProj);
    var projDS = Database.Consult(projContext, Proj, true);
    var dienst = projDS.FieldByName('F_DIENST').AsString;
    docuProdCopyDetails (dienst);


function docuProdCopyDetails(dienst){
    var SQL = "select K_DOCU_TEMPLATE from LK_OPPO_DIENST where K_OPPO_DIENST = :Param1"; //per dienst wordt 1 VM aangewezen als template
    var tempContext = Database.OpenTemporaryContext();
    var tempDS = Database.ExecuteSystemSQLQuery(0, tempContext, SQL, dienst, true, true, 0);
    var templateKey = tempDS.FieldByName('K_DOCU_TEMPLATE').Value; //templateKey = de k_document van de template VM met het winkelwagentje per dienst
    if (templateKey > 0) {
        try {
            Database.CopyDetails2(editHandle, 31, templateKey, [ntProd], false, false); //31 = Documents
        catch (error) {


asked in WorkFlow / Serverscript by (210 points)

Please log in or register to answer this question.

1,167 questions
1,425 answers
325 users