<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Efficy Overflow Q&amp;A - Recent questions tagged copydetails2</title>
<link>https://overflow.efficy.io/?qa=tag/copydetails2</link>
<description>Powered by Question2Answer</description>
<item>
<title>How can I use CopyDetails2 to copy all fields of a relation?</title>
<link>https://overflow.efficy.io/?qa=2764/how-can-i-use-copydetails2-to-copy-all-fields-of-a-relation</link>
<description>&lt;p&gt;As a follow up of my other question: &lt;a rel=&quot;nofollow&quot; href=&quot;https://overflow.efficy.com/?qa=2741/how-to-automatically-add-serie-products-linked-to-document&quot;&gt;https://overflow.efficy.com/?qa=2741/how-to-automatically-add-serie-products-linked-to-document&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;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. &lt;/p&gt;

&lt;p&gt;So I've got 2 questions now:&lt;br&gt;
1. How can I succesfully copy all details from the template, including the QUANTITY, PRICE  and K&lt;em&gt;SORT?&lt;br&gt;
2. Is it a problem that K&lt;/em&gt;RELATION in DOCU&lt;em&gt;PROD is used more than once, as long as the K&lt;/em&gt;DOCUMENT and K_PRODUCT is different?&lt;/p&gt;

&lt;p&gt;Would be perfect if there is a solution for this. Thanks for your help!&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Database.CopyDetails2(editHandle, 31, templateKey, [ntProd], false, false);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;My Complete code in editCmd.js&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;function docuAddProducts() {
    $.ajax({
        //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(&quot;dialog?_macrofile=MacroAjax&amp;amp;_macro=RunScript&amp;amp;file=Winkelwagentje;libjson&amp;amp;func=docuAddProducts&amp;amp;editHandle={editHandle}&quot;),
        type: &quot;GET&quot;,
        success: function (html, textStatus, jqXHR) {
            if (IsNotEfficyErrorHtml(html, function(errorMsg) {alert(errorMsg)})) {
                CebPerform(&quot;CEB_STATE&quot;);
            }
        }
    });
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And my complete code in the serverscript&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;function docuAddProducts() { 
var editHandle = StrToFloatDef(Request.Argument(&quot;editHandle&quot;), 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);
    Database.CloseContext(oppoContext);
    return;
}

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

}

function docuProdCopyDetails(dienst){
    var SQL = &quot;select K_DOCU_TEMPLATE from LK_OPPO_DIENST where K_OPPO_DIENST = :Param1&quot;; //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 &amp;gt; 0) {
        try {
            Database.CopyDetails2(editHandle, 31, templateKey, [ntProd], false, false); //31 = Documents
        }
        catch (error) {
        }               
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;}&lt;/p&gt;
</description>
<category>WorkFlow / Serverscript</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=2764/how-can-i-use-copydetails2-to-copy-all-fields-of-a-relation</guid>
<pubDate>Thu, 23 Nov 2017 10:25:59 +0000</pubDate>
</item>
</channel>
</rss>