<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Efficy Overflow Q&amp;A - Recent questions tagged add</title>
<link>https://overflow.efficy.io/?qa=tag/add</link>
<description>Powered by Question2Answer</description>
<item>
<title>Get only what's change during the edit context</title>
<link>https://overflow.efficy.io/?qa=4023/get-only-whats-change-during-the-edit-context</link>
<description>&lt;p&gt;Hello Efficy Team, &lt;/p&gt;

&lt;p&gt;I got a complex process where I need to &lt;em&gt;do something&lt;/em&gt; with the &quot;new element&quot; of a detailDataSet, or the deleted elements of the detailDataSet during the edit context.&lt;/p&gt;

&lt;p&gt;What is the best way retrieve only those element ? &lt;/p&gt;

&lt;p&gt;Here is what I did : &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    var k_project = Efficy.getEditKey(editHandle);
var relationTable = Efficy.entityCatalog.getRelationEntityTableName(ntProj, TEntityHandle);
var kElement = Efficy.entityCatalog.keyFieldName(TEntityHandle);

var dsDetails = Efficy.sqlQueryDataSet('select * from ' + relationTable + ' where k_project = :param1', k_project, 45);
var newDetails = Efficy.getDetailDataSet(editHandle, TEntityHandle);

var changesInTheEditContext = [];

if(dsDetails || !dsDetails.isEmpty()) {

    // the project is already committed. We need to get only the &quot;new&quot; one
    // for that, we filter the &quot;new one&quot; based on the &quot;old one&quot;

    var existing = [];
    dsDetails.first();
    while (!dsDetails.eof()) {
        existing.push(dsDetails.fieldByName(kElement).asFloat);
        dsDetails.next();
    }

    // ho yeah it is ugly. But seems that &quot;not in ()&quot; does not work
    newDetails.filter = kElement +' &amp;lt;&amp;gt; ' + existing.join(' AND ' +  kElement +  ' &amp;lt;&amp;gt; ');
    newDetails.FilterOptions = existing.length;
    newDetails.Filtered = true;

}

// then we get, for each &quot;new one&quot;, useful information's : entity, key, name

if(newDetails.isEmpty() || !newDetails) return false;
newDetails.first();

while(!newDetails.eof()) {

    changesInTheEditContext.push({
        entity : Efficy.entityCatalog.getEntityName(TEntityHandle),
        key : newDetails.fieldByName(kElement).asFloat,
        name : getName(newDetails.fieldByName(kElement).asFloat, TEntityHandle),
        operation : 'add'
    })

    newDetails.next();
}

newDetails.Filtered = false;

// we also need to detect the opposite : a contact deleted during the edit context
// we use the same ticks, but in the opposite (current detailDataSet filter the SQL)

if(dsDetails || !dsDetails.isEmpty()) {

    var fromRelationTable = [];

    newDetails.first();
    while (!newDetails.eof()) {

        fromRelationTable.push(newDetails.fieldByName(kElement).asFloat);
        newDetails.next();

    }

    // ho yeah it is ugly. But seems that &quot;not in ()&quot; does not work
    dsDetails.filter = kElement +' &amp;lt;&amp;gt; ' + fromRelationTable.join(' AND ' +  kElement +  ' &amp;lt;&amp;gt; ');
    dsDetails.FilterOptions = fromRelationTable.length;
    dsDetails.Filtered = true;

    if(dsDetails.isEmpty() || !dsDetails) return false;
    dsDetails.first();

    while(!dsDetails.eof()) {

        changesInTheEditContext.push({
            entity : Efficy.entityCatalog.getEntityName(TEntityHandle),
            key : dsDetails.fieldByName(kElement).asFloat,
            // name : getName(newDetails.fieldByName(kElement).asFloat, TEntityHandle), -- we don't need the name, he's already displayed
            operation : 'delete'
        })

        dsDetails.next();
    }

    dsDetails.Filtered = true;

}

return changesInTheEditContext;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Is there, by any chance, a way to get those change in a more &quot;Efficy way&quot; than comparing two dataSet ? &lt;/p&gt;

&lt;p&gt;Regards,&lt;/p&gt;

&lt;p&gt;Loïc&lt;/p&gt;
</description>
<category>WorkFlow / Serverscript</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=4023/get-only-whats-change-during-the-edit-context</guid>
<pubDate>Tue, 12 Mar 2019 07:49:17 +0000</pubDate>
</item>
</channel>
</rss>