<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Efficy Overflow Q&amp;A - Recent questions tagged serverscripts</title>
<link>https://overflow.efficy.io/?qa=tag/serverscripts</link>
<description>Powered by Question2Answer</description>
<item>
<title>OpenUrlSecure timeout</title>
<link>https://overflow.efficy.io/?qa=5453/openurlsecure-timeout</link>
<description>&lt;p&gt;Hi,&lt;br&gt;
I use the openUrlSecure and like in edn, I try to add a timeOut integer but the response is always the same, the error below:&lt;br&gt;
Message: &quot;&quot;TCoreSessionScriptAPI.OpenURLSecure&quot; called with incorrect number of arguments (8)&quot;&lt;br&gt;
the efficy version is 11.3.21086.0 2020-05-04&lt;br&gt;
If i remove the last param (timeout) is working.&lt;br&gt;
But for this client i need a timeout in case of the service is down to display a message.&lt;br&gt;
ex: var response = Efficy.openUrlSecure(url, soap envelope, header, '', '', '', '', 5000)&lt;/p&gt;

&lt;p&gt;regards&lt;/p&gt;
</description>
<category>Efficy Partners</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=5453/openurlsecure-timeout</guid>
<pubDate>Tue, 26 May 2020 08:39:03 +0000</pubDate>
</item>
<item>
<title>Unable to launch custom page from workflow</title>
<link>https://overflow.efficy.io/?qa=4990/unable-to-launch-custom-page-from-workflow</link>
<description>&lt;p&gt;Hello,&lt;/p&gt;

&lt;p&gt;After an upgrade from 10SP2 to 11.2, i am experiencing issues with the workflow of a client.&lt;/p&gt;

&lt;p&gt;Triggered by BeforeCommitCont, the following command was to be executed : UserSession.ExecuteCommand(&quot;displayCustomActions('{0}', '{1}', '{2}', '{3}');&quot;.format(entity, key, (addrChangeInfo) ? JSON.stringify(addrChangeInfo) : null, true)))&lt;/p&gt;

&lt;p&gt;Since the upgrade, this doesn't seem to work. We are still able to use this functionality to trigger an alert, but launching a function defined in custom.js doesn't seem to work anymore.&lt;/p&gt;

&lt;p&gt;This function is used to launch an custom page that shows possible links based on the addrChangeInfo parameter. There is quite a lot of functionality behind this to populate this parameter and also to determine if the pop-up should be showed. So the fastest way to resolve this would be to keep the current functionality (by making custom.js available again in the workflow?).&lt;/p&gt;

&lt;p&gt;If that isn't possible, what scenario could be used to copy this behavior? I tried with storing the addrChangeInfo in the database and to launch the function in front-end, but i am unable to trigger this between BeforeCommit and AfterCommit.&lt;/p&gt;

&lt;p&gt;Any ideas on how to solve this? Any other examples that you know of?&lt;br&gt;
Let me know if you need more information.&lt;/p&gt;

&lt;p&gt;Regards,&lt;br&gt;
Ken&lt;/p&gt;
</description>
<category>WorkFlow / Serverscript</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=4990/unable-to-launch-custom-page-from-workflow</guid>
<pubDate>Tue, 05 Nov 2019 13:13:22 +0000</pubDate>
</item>
<item>
<title>launch template from Publ or Prof Consult! Efficy 11.2</title>
<link>https://overflow.efficy.io/?qa=4876/launch-template-from-publ-or-prof-consult-efficy-11-2</link>
<description>&lt;p&gt;Hello,&lt;/p&gt;

&lt;p&gt;I want to launch a template threw a &lt;strong&gt;consult commande&lt;/strong&gt; From &lt;strong&gt;Publications Consult&lt;/strong&gt; page, i've created this function to take the directly the &lt;strong&gt;template key in parameters&lt;/strong&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;const launchTemplateFromConsult = (template) =&amp;gt; {
var extraParam = format('template=$0&amp;amp;Key={key}&amp;amp;{entity}= 
                {key}&amp;amp;copydetail={entity};{key};Comp;Cont,Proj;Oppo', template);
EditNewWithScript2('Docu', extraParam, 'serverscripts/Create', 
                'CreateInstantDoc');
};
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;My problem is that when the document is created the copy detail function does not work properly like &lt;strong&gt;(contacts or companies are not copied)&lt;/strong&gt;, i don't know if there is some thing missing&lt;/p&gt;

&lt;p&gt;I've also add this 2 lines in the Create.js in the &lt;strong&gt;CreateInstantDoc&lt;/strong&gt; function to copy the details that i need,&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;var Publ = Efficy.getMainDetail(DocuContext, ntPubl)
Efficy.copyDetails2(DocuContext, ntPubl, Publ, [ntComp, ntCont, ntProj, ntOppo], false, false)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;but the function steel not working.&lt;/p&gt;

&lt;p&gt;Could you help me please?&lt;/p&gt;

&lt;p&gt;Thanks&lt;/p&gt;
</description>
<category>Efficy/ Client side</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=4876/launch-template-from-publ-or-prof-consult-efficy-11-2</guid>
<pubDate>Wed, 09 Oct 2019 09:25:57 +0000</pubDate>
</item>
<item>
<title>Efficy 11: Different ways to call a serverside script (which is the best one)</title>
<link>https://overflow.efficy.io/?qa=4171/efficy-different-ways-call-serverside-script-which-the-best</link>
<description>&lt;p&gt;Hi guys,&lt;/p&gt;

&lt;p&gt;We can call a serverscript in multiple ways (and we can find both in the standard).&lt;br&gt;
For now (Efficy 11.2), and for the futur, Is there a way better than the others ? Is there a depracate way ?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Utils.runServerJsAjax&lt;/li&gt;
&lt;li&gt;Utils.runScriptAjax2&lt;/li&gt;
&lt;li&gt;$.ajax({&lt;br&gt;
url: ...,&lt;br&gt;
method: ...,&lt;br&gt;
data: ...&lt;br&gt;
}).done(function (html) {&lt;br&gt;
...&lt;br&gt;
});&lt;/li&gt;
&lt;/ul&gt;
</description>
<category>Efficy/ Client side</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=4171/efficy-different-ways-call-serverside-script-which-the-best</guid>
<pubDate>Thu, 25 Apr 2019 14:11:07 +0000</pubDate>
</item>
<item>
<title>Import html template from file in serverscript</title>
<link>https://overflow.efficy.io/?qa=3856/import-html-template-from-file-in-serverscript</link>
<description>&lt;p&gt;Hi,&lt;/p&gt;

&lt;p&gt;After speak with the Efficy support, I have to use a serverscript to generate html.&lt;br&gt;
This serverscript will be call in a macro with a RunScript.&lt;/p&gt;

&lt;p&gt;I prefer not to put so many html directly in the serverscript, I find that it is not a &quot;good practice&quot; and make the script less readable..&lt;br&gt;
&lt;strong&gt;Is there a way to import html from a page in server script with &lt;em&gt;Efficy 10.2&lt;/em&gt; ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Example :&lt;br&gt;
&lt;strong&gt;serverscripts/Example.js&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;/* function called by &amp;lt;%RunScript(...)%&amp;gt; */
function GetCustomHtmlTable() {
  var EditHandle = Request.ContextHandle,
      HtmlTemplate = &quot;IMPORT HTML FROM HTML FILE ? like pages/grid/HtmlTemplate.htm ?&quot;

  /* some code to get the rights values */
  var name = Database.GetFieldValue(EditHandle, 'NAME'), // in this example : 'My custom header'
      description = 'some text',
      otherData = 'otherData...'

  /* Generate html and return it */
  return ParseTemplate(HtmlTemplate, name, description, otherData);
}

/* this function replace each %s in the template by the others params value in args */
function ParseTemplate(template) {
  var args = [].slice.call(arguments, 1),
      i = 0;

  return template.replace(/%s/g, function() {
      return args[i++];
  });
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;HtmlTemplate.htm&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;div class=&quot;CustomClasses&quot;&amp;gt;
  &amp;lt;div class=&quot;header&quot;&amp;gt;%s&amp;lt;/div&amp;gt;
  &amp;lt;div class=&quot;body&quot;&amp;gt;%s&amp;lt;/div&amp;gt;
  &amp;lt;div class=&quot;footer&quot;&amp;gt;%s&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;This will return :&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;div class=&quot;CustomClasses&quot;&amp;gt;
  &amp;lt;div class=&quot;header&quot;&amp;gt;My custom header&amp;lt;/div&amp;gt;
  &amp;lt;div class=&quot;body&quot;&amp;gt;some text&amp;lt;/div&amp;gt;
  &amp;lt;div class=&quot;footer&quot;&amp;gt;otherData...&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>WorkFlow / Serverscript</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=3856/import-html-template-from-file-in-serverscript</guid>
<pubDate>Fri, 11 Jan 2019 22:18:33 +0000</pubDate>
</item>
<item>
<title>OpenUrlSecure How can I get the response body when not success</title>
<link>https://overflow.efficy.io/?qa=3731/openurlsecure-how-can-get-the-response-body-when-not-success</link>
<description>&lt;p&gt;Hi, &lt;/p&gt;

&lt;p&gt;apparently, the response.body of a openUrlSecure call is empty when the success != true.&lt;br&gt;
is that a feature or an anomaly?&lt;/p&gt;

&lt;p&gt;It seems that the body is well filled when success = true;&lt;/p&gt;

&lt;p&gt;point is the api i am requesting send me an error message in the body (checked it with postman)&lt;/p&gt;

&lt;p&gt;Do I have a way to workaround this?&lt;/p&gt;
</description>
<category>Efficy/ Client side</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=3731/openurlsecure-how-can-get-the-response-body-when-not-success</guid>
<pubDate>Tue, 11 Dec 2018 10:59:58 +0000</pubDate>
</item>
<item>
<title>Visual Studio 2017 / Just In Time Debugger is not being launched</title>
<link>https://overflow.efficy.io/?qa=3591/visual-studio-2017-just-in-time-debugger-not-being-launched</link>
<description>&lt;p&gt;My just in time debugger isn't launching anymore...&lt;/p&gt;

&lt;p&gt;I tried:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;debugger;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;throw new Error(&quot;Testing&quot;);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In the workflow / serverscript but none of those trigger the Visual Studio debugger.&lt;/p&gt;

&lt;p&gt;What could be the cause?&lt;/p&gt;
</description>
<category>WorkFlow / Serverscript</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=3591/visual-studio-2017-just-in-time-debugger-not-being-launched</guid>
<pubDate>Mon, 08 Oct 2018 12:00:23 +0000</pubDate>
</item>
<item>
<title>How to use filter</title>
<link>https://overflow.efficy.io/?qa=3585/how-to-use-filter</link>
<description>&lt;p&gt;Hi all,&lt;/p&gt;

&lt;p&gt;With ConsultDetail I get the Documents of an Opportunity, but I want to filter this dataset on quotes : a quote have a REFERENCE that start by 'D'.&lt;/p&gt;

&lt;p&gt;The EDN say that TDataSet.Filter is &quot;The text of the current SQL filter for the dataset.&quot; so I try to filter my dataset with REFERENCE LIKE 'D%' but Efficy throw me this error :&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;ID: WKFL-2142&lt;br&gt;
  Message: Error while executing Script &quot;OppoConvertToProj&quot; at line 52 char 13.&lt;br&gt;
  Message: &quot;L'URI à décoder contient un caractère incorrect&quot;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After some tests I know that the error is thorwn by the % . I tried to fix it in the &quot;CleanFilter&quot; (replace % by %) but I have the same error.&lt;/p&gt;

&lt;p&gt;Is it possible to filter a dataset with a like ?&lt;/p&gt;

&lt;p&gt;Here is my filter (first recordCount is correct, the second is empty)&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;// copy links to quote ==&amp;gt; CUSTOM : Create new Document (ORDER)
var OppoDocuDS = Database.ConsultDetail(QueryHandle, OppoContext, OppoKey, ntDocu, true, true, 0);
Logger.Write('OppoDocuDS.recordCount1='+OppoDocuDS.recordCount);
Logger.Write('OppoDocuDS.IsEmpty1='+OppoDocuDS.IsEmpty);

// filter dataset on quote
var Filter = &quot;REFERENCE LIKE 'D%'&quot;;
var CleanFilter = decodeURIComponent(Filter).replace(/=/gi, &quot;=&quot;).replace(/&amp;lt;/gi, &quot;&amp;lt;&quot;).replace(/&amp;gt;/gi, &quot;&amp;gt;&quot;).replace(/&amp;amp;#37;/gi, &quot;%&quot;)
OppoDocuDS.Filtered = false
if (CleanFilter != &quot;&quot;) {
    OppoDocuDS.Filter = CleanFilter
    OppoDocuDS.FilterOptions = 1
    OppoDocuDS.Filtered = true
}

Logger.Write('OppoDocuDS.recordCount2='+OppoDocuDS.recordCount);
Logger.Write('OppoDocuDS.IsEmpty2='+OppoDocuDS.IsEmpty);
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>WorkFlow / Serverscript</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=3585/how-to-use-filter</guid>
<pubDate>Tue, 02 Oct 2018 16:03:26 +0000</pubDate>
</item>
<item>
<title>Line break in script for an email template</title>
<link>https://overflow.efficy.io/?qa=3540/line-break-in-script-for-an-email-template</link>
<description>&lt;p&gt;Hello, &lt;/p&gt;

&lt;p&gt;someone knows how to make a line break in a script for the running of a runscript for an email template.&lt;/p&gt;

&lt;p&gt;I want to replace the splash in this function with a line break &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;var nature = &quot; &quot;;
    var entyDS = Efficy.GetMasterDataSet(ContextHandle, 0);
    if(!entyDS || entyDS.IsEmpty) return &quot;$$ENCODE$$&quot; + nature;
    entyDS.first();
    while(!entyDS.EOF) {
        if(entyDS.FieldByName(&quot;F_STATUT&quot;).asFloat)
            nature = entyDS.fieldByName(&quot;R_F_NATURE_NIVEAU_1&quot;).asString+' / '+entyDS.fieldByName(&quot;R_F_NATURE_NIVEAU_2&quot;).asString+' / '+entyDS.fieldByName(&quot;R_F_NATURE_NIVEAU_3&quot;).asString;
        entyDS.next();
    }
    return nature;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I thank you in advance,&lt;/p&gt;

&lt;p&gt;Sincerely, Jean.&lt;/p&gt;
</description>
<category>WorkFlow / Serverscript</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=3540/line-break-in-script-for-an-email-template</guid>
<pubDate>Thu, 13 Sep 2018 15:39:34 +0000</pubDate>
</item>
<item>
<title>Log an estimated remaining time for tasks (scheduler)</title>
<link>https://overflow.efficy.io/?qa=3483/log-an-estimated-remaining-time-for-tasks-scheduler</link>
<description>&lt;p&gt;Hi, &lt;/p&gt;

&lt;p&gt;I begin to abandon the use of datasync since I can provide a definitly better job by doing scheduled tasks&lt;/p&gt;

&lt;p&gt;I ve made a tool that allow you to log an estimated remaining time for the different tasks you will have to run. Fun fact this would probably work in a datasync as well^^.&lt;/p&gt;

&lt;p&gt;this is an exemple of how you can use it : &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;var dataToWorkOn = new Array();
//-----(Fill your array with Sql, file reading, inputStream, ...)

var chrono = new NL_chrono();

for (var i=0; i&amp;lt;dataToWorkOn.length; i++){
    //-----(do your job here)

    chrono.lap();    //-----(add a new time flag in your chrono)
    log(format(&quot;$0/$1 done. Estimated lasting time: $2&quot;, i+1, dataToWorkOn.length, chrono.forecast(dataToWorkOn.length)));
}

chrono.reset(); //-----(if you want to reuse chrono)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;the log output will look like something like that : &lt;/p&gt;

&lt;p&gt;-&amp;gt; 45 / 12598 done. Estimated lasting time: 1d 13h 12min 23s&lt;br&gt;
-&amp;gt; 46 / 12598 done. Estimated lasting time: 1d 13h 11min 19s&lt;br&gt;
-&amp;gt; 47 / 12598 done. Estimated lasting time: 1d 13h 10min 13s&lt;/p&gt;

&lt;p&gt;the forecast function will automatically calculate the remaining time depending of the total number of laps and the already achieved laps. &lt;/p&gt;

&lt;p&gt;You can of course use chrono for different purpose.&lt;br&gt;
This is the code to use it: &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    function NL_chrono(){
    this.start = new Date();
    this.laps = new Array();

    NL_chrono.prototype.stringify = function(){
        return &quot;not yet&quot;;
    }

    NL_chrono.prototype.reset = function(){
        this.start = new Date();
        this.laps = new Array();
    }

    NL_chrono.prototype.lap = function(){
        var laptime = new Date();
        var lasttime = this.start;
        if (this.laps.length &amp;gt; 0) lasttime = this.laps[this.laps.length -1].date;

        this.laps.push({
            date: laptime,
            laptime: laptime.getTime() - lasttime.getTime(),
            time: laptime.getTime() - this.start.getTime()
        });

        return this.laps[this.laps.length -1];
    }

    NL_chrono.prototype.forecast = function(_lap, _unit){
        if(this.laps.length === 0 || _lap &amp;lt; this.laps.length) return;

        var result = (_lap / this.laps.length -1) * this.laps[this.laps.length -1].time;

        switch (_unit){
            case &quot;d&quot;: result = result / (1000 * 3600 * 24); break;
            case &quot;h&quot;: result = result / (1000 * 3600); break;
            case &quot;m&quot;: result = result / (1000 * 60); break;
            case &quot;s&quot;: result = result / 1000; break;
            case &quot;ms&quot;: break;
            default: 
                result = getTimeText(result);
                break;
        }

        return result;
    }

    NL_chrono.prototype.showStats = function(_options){
        _options = _options || {};

        var result = new Array();
        _options.maxwidth = _options[&quot;maxwidth&quot;] || 60;

        var maxLapTime = this.laps[0].laptime;
        this.laps.map(function(_item){if (_item.laptime &amp;gt; maxLapTime) maxLapTime = _item.laptime;});

        var temp = &quot;&quot;;
        for (var i=0; i&amp;lt;_options.maxwidth +28; i++) temp += &quot;_&quot;;
        result.push(temp);

        result.push(format(&quot;Lap time evolution | max = $0 | total = $1 |&quot;, getTimeText(maxLapTime), getTimeText(this.laps[this.laps.length -1].time)));

        result.push(temp);
        result.push(&quot; &quot;);
        forEach(this.laps, function(_lap, _index){
            var size = Math.round(_options.maxwidth * _lap.laptime / maxLapTime);
            var bar = &quot;&quot;;
            for (var i=0; i&amp;lt;size; i++) bar += &quot;=&quot;;
            bar += format(&quot;(Lap $0: $1)&quot;, _index +1, getTimeText(_lap.laptime));
            result.push(bar);
        });
        return result;
    }

    NL_chrono.prototype.getTimeText = getTimeText;

    function getTimeText(_ms){
        var val = _ms;
        if (val == 0) return &quot;&quot;;

        var result = &quot;&quot;;
        if (val &amp;gt;= (1000 * 3600 * 24)) result = (val - val % (1000 * 3600 * 24)) / (1000 * 3600 * 24) + &quot;d &quot;
        val = val % (1000 * 3600 * 24)
        if (val != 0) {
            if (val &amp;gt;= (1000 * 3600)) result += (val - val % (1000 * 3600)) / (1000 * 3600) + &quot;h &quot;
            val = val % (1000 * 3600)
            if (val != 0) {
                if (val &amp;gt;= (1000 * 60)) result += (val - val % (1000 * 60)) / (1000 * 60) + &quot;min &quot;
                val = val % (1000 * 60)
                if (val != 0) {
                    if (val &amp;gt;= 1000) result += (val - val % 1000) / 1000 + &quot;s&quot;
                    val = val % 1000
                }
            }
        }

        return result;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;EDIT: I added a function showStats that will show you in the console a graphical representation of the time of your job : &lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://overflow.efficy.com/?qa=blob&amp;amp;qa_blobid=4182840574906439388&quot; alt=&quot;enter image description here&quot;&gt;&lt;/p&gt;

&lt;p&gt;NB the showStats function result is a string array that you ll have to log with something like : &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;forEach(chrono.showStats(), function(_stat){log(_stat);});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Cheers&lt;/p&gt;
</description>
<category>WorkFlow / Serverscript</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=3483/log-an-estimated-remaining-time-for-tasks-scheduler</guid>
<pubDate>Wed, 22 Aug 2018 09:48:41 +0000</pubDate>
</item>
<item>
<title>USe Databse in Custom.js</title>
<link>https://overflow.efficy.io/?qa=3403/use-databse-in-custom-js</link>
<description>&lt;p&gt;Hi !&lt;/p&gt;

&lt;p&gt;My Products can be a &quot;Batch&quot; :&lt;br&gt;
- PRODUCTS.FAMILY=1&lt;br&gt;
- Contains other  products&lt;/p&gt;

&lt;p&gt;I need to customize the Products grid in the Search window :&lt;br&gt;
By default all these links call AddRelation() from Efficy.js.&lt;br&gt;
But if the product is a &quot;Batch&quot;, I want to link to the Document all products linked to the batch, but not the batch.&lt;/p&gt;

&lt;p&gt;2 questions :&lt;br&gt;
- How can I pass the FAMILLY of the product to the AddRelation function ?&lt;br&gt;
- I don't know How to call a serverscript from a client-side script (like Custom.js). Can I use $.ajax from Custom.js ?&lt;/p&gt;

&lt;p&gt;Here are my customizations : (I don't know if it's good because I can't test it)&lt;br&gt;
serverscripts/Document.js :&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;function addProductsFromLot() {
    var EditHandle = StrToIntDef(Request.Argument(&quot;editHandle&quot;), 0), // Docu Edit Context
        lotKey = Request.Argument(&quot;lotKey&quot;),
        queryHandle = 0;

   var ProdContext = Database.OpenConsultContext(ntProd);
   try {
        var ProdDS = Database.ConsultDetail(queryHandle, ProdContext, lotKey, ntProd, false, true, 0);
        ProdDS.First;
        while (!ProdDS.Eof) {
            var K_PRODUCT = ProdDS.fieldByName('K_PRODUCT').asFloat;
            Database.insertDetail2(EditHandle, ntProd, K_PRODUCT, false);
            ProdDS.Next;
        }
    } finally {
        Database.CloseContext(ProdContext);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Custom.js :&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;function AddRelation(EditHandle, Bookmark, Entity, Key, Entity2, Key2, RefreshTopWindow) {
    //how to get FAMILY ?
    // 2 = Lot / Batch
    if(Entity=='Prod' &amp;amp;&amp;amp; FAMILY == 1 ) {
        $.ajax({
            url: format(&quot;dialog?_macrofile=MacroAjax&amp;amp;_macro=RunScript&amp;amp;file=Document&amp;amp;func=addProductsFromLot&amp;amp;editHandle=&quot;EditHandle+&quot;&amp;amp;lotKey=&quot;+Key),
            type: &quot;GET&quot;,
            success: function (html, textStatus, jqXHR) {
                if (IsNotEfficyErrorHtml(html, function(errorMsg) {alert(errorMsg)})) {
                    CebPerform(&quot;CEB_STATE&quot;);
                    CloseTopWindow() // --&amp;gt; will close the search Window ?
                }
            }
        });
    }
    // If not a Batch, don't need to customise
    else {
        var URL = &quot;addrelation?edithandle=&quot; + EditHandle + &quot;&amp;amp;bookmark=&quot; + Bookmark + &quot;&amp;amp;entity=&quot; + Entity + &quot;&amp;amp;key=&quot; + EscapeName(Key)
        if (Entity2) URL += &quot;&amp;amp;entity2=&quot; + Entity2 + &quot;&amp;amp;key2=&quot; + EscapeName(Key2)
        if (window.ClickFromPopup)
            LocationSet(window, URL)
        else if (!RefreshTopWindow &amp;amp;&amp;amp; OpenerExists() &amp;amp;&amp;amp; !IsDesktopWindow(top.opener.top)) {
            top.opener.EntityModified = false;
            LocationSet(top.opener, URL)
            CloseTopWindow()
        }
        else
            LocationSet(window, URL)
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Thanks a lot!&lt;/p&gt;
</description>
<category>WorkFlow / Serverscript</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=3403/use-databse-in-custom-js</guid>
<pubDate>Wed, 18 Jul 2018 13:58:44 +0000</pubDate>
</item>
<item>
<title>How to return K_MAIL when using sendExternalMail()</title>
<link>https://overflow.efficy.io/?qa=3388/how-to-return-kmail-when-using-sendexternalmail</link>
<description>&lt;p&gt;Hi all,&lt;br&gt;
I would like to do something the the newly created email in efficy 10 when I use sendExternalMail() ( - and sendMailToUsers() if also possible).&lt;br&gt;
How can I determine K_MAIL? The online docu offers nothing.&lt;/p&gt;

&lt;p&gt;Thank you&lt;/p&gt;

&lt;p&gt;Tim&lt;/p&gt;
</description>
<category>WorkFlow / Serverscript</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=3388/how-to-return-kmail-when-using-sendexternalmail</guid>
<pubDate>Thu, 12 Jul 2018 10:49:39 +0000</pubDate>
</item>
<item>
<title>how to get a file from Soap Request</title>
<link>https://overflow.efficy.io/?qa=3133/how-to-get-a-file-from-soap-request</link>
<description>&lt;p&gt;Hi all,&lt;/p&gt;

&lt;p&gt;i need to get a pdf file from a soap call to an external webservices.&lt;/p&gt;

&lt;p&gt;When i try to do it with soap ui,  i get a response like that :&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://overflow.efficy.com/?qa=blob&amp;amp;qa_blobid=12017686003718410389&quot; alt=&quot;screenshot from soapui&quot;&gt;&lt;/p&gt;

&lt;p&gt;When i click on the attachement, i can save it in .pdf, and i have a readable file.&lt;/p&gt;

&lt;p&gt;But,  i don't really know how i can do it in serverscript.&lt;/p&gt;

&lt;p&gt;i get a raw response like that.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://overflow.efficy.com/?qa=blob&amp;amp;qa_blobid=11489886934131395534&quot; alt=&quot;raw response&quot;&gt;&lt;/p&gt;

&lt;p&gt;Somebody have an idea on how to get this stream corectly from the soap response and put it in a pdf file ?&lt;/p&gt;
</description>
<category>WorkFlow / Serverscript</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=3133/how-to-get-a-file-from-soap-request</guid>
<pubDate>Tue, 08 May 2018 09:23:51 +0000</pubDate>
</item>
<item>
<title>How can we save changes from an edit form before starting a serverscript with $.ajax</title>
<link>https://overflow.efficy.io/?qa=3099/save-changes-from-edit-form-before-starting-serverscript-with</link>
<description>&lt;p&gt;We need the updated (saved) data of the client form in our serverscript, therefore a &lt;code&gt;CebPerform('CEB_APPLY')&lt;/code&gt; is programmatically executed for launching the serverscript.&lt;br&gt;
The serverscript will be started and finished successfully, but the callback success function is NOT triggered.&lt;/p&gt;

&lt;p&gt;How we can fix this?&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;CebPerform('CEB_APPLY');
var scriptFile = &quot;serverscripts/test.js&quot;
    var scriptFunc = &quot;TestServerScript&quot;
    var URL = &quot;dialog?_macrofile=MacroAjax&amp;amp;_macro=RunScript&amp;amp;File=&quot; + scriptFile + &quot;&amp;amp;Func=&quot; + scriptFunc + &quot;&amp;amp;key=&quot; + Model('key') + &quot;&amp;amp;entity=&quot; + Model('entity') + &quot;&amp;amp;editHandle=&quot; + Model('editHandle');
$.ajax({
    url: URL,
    type: &quot;GET&quot;,
    //data: ExtraParams,
    success:
    function (html, textStatus, jqXHR) {
        // this is never reached ?!
        alert(&quot;Back:&quot; + html)
        if (IsNotEfficyErrorHtml(html, function (errorMsg) {
                alert(errorMsg)
            })) {
            CebPerform('CEB_STATE');
        }
    }
})
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>WorkFlow / Serverscript</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=3099/save-changes-from-edit-form-before-starting-serverscript-with</guid>
<pubDate>Thu, 26 Apr 2018 12:36:24 +0000</pubDate>
</item>
<item>
<title>How to remove security using Efficy Functions serverside?</title>
<link>https://overflow.efficy.io/?qa=2991/how-to-remove-security-using-efficy-functions-serverside</link>
<description>&lt;p&gt;Hi, &lt;/p&gt;

&lt;p&gt;From a workflow script I try to remove securities from specified users.&lt;/p&gt;

&lt;p&gt;The documentation says that RemoveUsers only affect visible Users so it s not what I need.&lt;br&gt;
I ve try to calculate the Users I want to keep in securities and apply a SetSecurityUsers because the documentation told me that the other users will be removed from security but this doesn't work either in Efficy SP2+ &lt;br&gt;
I ve try to used a custom storedProcedure to delete the Comp_User records, but this doesn't refresh my ContextHandle so basically it s not the good behaviour either.&lt;/p&gt;

&lt;p&gt;Basically I just want to know how to remove a user from the securities of a record...&lt;/p&gt;

&lt;p&gt;Please help.&lt;/p&gt;
</description>
<category>Efficy/ Client side</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=2991/how-to-remove-security-using-efficy-functions-serverside</guid>
<pubDate>Thu, 22 Mar 2018 15:48:57 +0000</pubDate>
</item>
<item>
<title>get the result of a select statement to an array of object</title>
<link>https://overflow.efficy.io/?qa=2924/get-the-result-of-a-select-statement-to-an-array-of-object</link>
<description>&lt;p&gt;Dear developper community &lt;/p&gt;

&lt;p&gt;Just before Kristof tells me why it's not good^^ let s take a minute to celebrate my new Achievement : I finally found a way to convert Dataset to Array of Objects in javascript. please note that this is the result of delphi Recordset objects researches on the web plus lot of tests.&lt;/p&gt;

&lt;p&gt;I give you the result of my code as a tribute for the great Efficy developpers community^^.&lt;/p&gt;

&lt;p&gt;this is how it works : in my example I try to get &lt;code&gt;all the STATUS_FR and K_OPPO_STATUS from the LK_OPPO_STATUS table ENALBED and with K_OPPO_STATUS lesser than 5&lt;/code&gt;&lt;br&gt;
do you remember doing something like this : &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;var
    result = new Array(),
    qh = 0,
    context = Database.OpenTemporaryContext(),
    sql = &quot;select * from &amp;lt;#TABLE NAME=LK_OPPO_STATUS&amp;gt; where DISABLED = :param1 and K_OPPO_STATUS &amp;lt; :param2&quot;,
    params = [0, 5].join(&quot;\n&quot;),
    ds = Database.ExecuteSystemSQLQuery(qh, context, sql, params, true, true, 1);

while (!ds.EoF){

    result.push({
        status: ds.FieldByName(&quot;STATUS&quot;).AsString,
        k_oppo_status: ds.FieldByName(&quot;K_OPPO_STATUS&quot;).AsFloat      
    });

    ds.Next();
}

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

&lt;p&gt;that gave you : &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;[  
   {  
      &quot;status_fr&quot;:&quot;01. Prise de contact&quot;,
      &quot;k_oppo_status&quot;:1
   },
   {  
      &quot;status_fr&quot;:&quot;02. Qualification&quot;,
      &quot;k_oppo_status&quot;:2
   },
   {  
      &quot;status_fr&quot;:&quot;03. Démonstration&quot;,
      &quot;k_oppo_status&quot;:3
   },
   {  
      &quot;status_fr&quot;:&quot;04. Offre&quot;,
      &quot;k_oppo_status&quot;:4
   }
]
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;this time my friends is over! now you can do : &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;return jsonSelectSQL(&quot;select * from &amp;lt;#TABLE NAME=LK_OPPO_STATUS&amp;gt; where DISABLED = :param1 and K_OPPO_STATUS &amp;lt; :param2&quot;, 0, 5);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Note that at this point YOU don't need to specify anything about the fields names or number of fields.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;which will give you something like &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;[  
   {  
      &quot;k_oppo_status&quot;:1,
      &quot;k_sort&quot;:1,
      &quot;k_label&quot;:0,
      &quot;status&quot;:&quot;01. Initial Contact&quot;,
      &quot;disabled&quot;:&quot;0&quot;,
      &quot;status_fr&quot;:&quot;01. Prise de contact&quot;,
      &quot;status_nl&quot;:&quot;01. Prise de contact&quot;,
      &quot;status_es&quot;:&quot;01. Prise de contact&quot;,
      &quot;status_de&quot;:&quot;01. Prise de contact&quot;,
      &quot;status_ja&quot;:&quot;&quot;,
      &quot;status_pl&quot;:&quot;&quot;,
      &quot;status_tr&quot;:&quot;&quot;,
      &quot;status_ar&quot;:&quot;&quot;,
      &quot;f_pending&quot;:1
   },
   {  
      &quot;k_oppo_status&quot;:2,
      &quot;k_sort&quot;:2,
      &quot;k_label&quot;:0,
      &quot;status&quot;:&quot;02. Qualification&quot;,
      &quot;disabled&quot;:&quot;0&quot;,
      &quot;status_fr&quot;:&quot;02. Qualification&quot;,
      &quot;status_nl&quot;:&quot;02. Accroche&quot;,
      &quot;status_es&quot;:&quot;02. Accroche&quot;,
      &quot;status_de&quot;:&quot;02. Accroche&quot;,
      &quot;status_ja&quot;:&quot;&quot;,
      &quot;status_pl&quot;:&quot;&quot;,
      &quot;status_tr&quot;:&quot;&quot;,
      &quot;status_ar&quot;:&quot;&quot;,
      &quot;f_pending&quot;:1
   },
   {  
      &quot;k_oppo_status&quot;:3,
      &quot;k_sort&quot;:3,
      &quot;k_label&quot;:0,
      &quot;status&quot;:&quot;03. Démonstration&quot;,
      &quot;disabled&quot;:&quot;0&quot;,
      &quot;status_fr&quot;:&quot;03. Démonstration&quot;,
      &quot;status_nl&quot;:&quot;03. Démonstration&quot;,
      &quot;status_es&quot;:&quot;03. Démonstration&quot;,
      &quot;status_de&quot;:&quot;03. Démonstration&quot;,
      &quot;status_ja&quot;:&quot;&quot;,
      &quot;status_pl&quot;:&quot;&quot;,
      &quot;status_tr&quot;:&quot;&quot;,
      &quot;status_ar&quot;:&quot;&quot;,
      &quot;f_pending&quot;:1
   },
   {  
      &quot;k_oppo_status&quot;:4,
      &quot;k_sort&quot;:4,
      &quot;k_label&quot;:0,
      &quot;status&quot;:&quot;04. Offre&quot;,
      &quot;disabled&quot;:&quot;0&quot;,
      &quot;status_fr&quot;:&quot;04. Offre&quot;,
      &quot;status_nl&quot;:&quot;04. Offre&quot;,
      &quot;status_es&quot;:&quot;04. Offre&quot;,
      &quot;status_de&quot;:&quot;04. Offre&quot;,
      &quot;status_ja&quot;:&quot;&quot;,
      &quot;status_pl&quot;:&quot;&quot;,
      &quot;status_tr&quot;:&quot;&quot;,
      &quot;status_ar&quot;:&quot;&quot;,
      &quot;f_pending&quot;:1
   }
]
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;note that if you strictly want the same result as before you can do : &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;return jsonSelectSQL(&quot;select STATUS_FR, K_OPPO_STATUS from &amp;lt;#TABLE NAME=LK_OPPO_STATUS&amp;gt; where DISABLED = :param1 and K_OPPO_STATUS &amp;lt; :param2&quot;, 0, 5);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;this is the code of jsonSelectSQL : &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;function jsonSelectSQL(){

    var 
        ds = selectSQL.apply(null, arguments),
        result = new Array(),
        fields = new Array();

    ds.First();
    if (!ds.EoF) {
        for (var i=0; i&amp;lt;ds.Fields.count; i++){
            fields.push(ds.Fields(i).FieldName);
        }
    }
    while (!ds.EoF){
        var obj = {};

        for (var i=0; i&amp;lt;fields.length; i++) {
            var temp = ds.FieldByName(fields[i]).Value;
            switch(typeof(temp)){
                case &quot;string&quot;:
                    obj[fields[i].toLowerCase()] = temp;
                    break;
                case &quot;number&quot;: 
                    obj[fields[i].toLowerCase()] = Number(temp);
                    break;
                default: 
                    obj[fields[i].toLowerCase()] = temp;
                    break;
            }
        }
        result.push(obj);

        ds.Next();
    }
    return result;
}   
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;please note that you will need this code as well : &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;//------(simple closure to don't have to remember which StoreId to use)
var nextStoreId = (function(){
    var storeId = 0;
    return function(){return storeId += 1;};
})();

//------(call this with sql string and parameters and you will get the standard dataset)
function selectSQL(){
    var 
        args = arrayFrom(arguments),
        qh = 0, 
        context = Database.OpenTemporaryContext(),
        sql = args[0],
        params = args.splice(0,1),
        ds = Database.ExecuteSystemSQLQuery(qh, context, sql, params.join(&quot;\n&quot;), true, true, nextStoreId());

    return ds;
}

//-----(convert the classic arguments arraylike object as a regular javascript array)
function arrayFrom(_arg){

    var result = new Array();

    for (var i=0; i&amp;lt;_arg.length; i++){
        result.push(_arg[i]);
    }

    return result;
}   

//-----(home made splice prototype polyfill, feel free to use yours)
Array.prototype.splice = function(){
    var args = arguments;

    var result = new Array();
    var i = 0;

    if (args[0] + args[1] &amp;gt; this.length) throw new Error(&quot;custom Splice error, invalid parameters for this array&quot;);
    while (i &amp;lt; args[0]){
        result.push(this[i]);
        i++;
    }

    if (args[2])    for (var j=0; j&amp;lt;args[2].length; j++) result.push(args[2][j]);

    i = args[0] + args[1];

    while (i&amp;lt;this.length){
        result.push(this[i]);
        i++;
    }

    for (i=0; i&amp;lt;this.length; i++) this[i] = undefined;
    this.length = 0;
    for (i=0; i&amp;lt;result.length; i++) this.push(result[i]);

    return this;
}   
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;since a lot of code can be necessary I invite to use my previous achievement : be able to make some include files in serverscripts files : I have it updated so this in the header of your serverscript file will make the trick : &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;eval(function (_files){
    var root = &quot;C:/inetpub/wwwroot/efficy/&quot; + ((typeof(Request) !== &quot;undefined&quot;)? Request.CustomBaseURL: &quot;../customs/Test/&quot;);
    var result = &quot;&quot;;
    for (var i=0; i&amp;lt;_files.length; i++) result += (StrLoadBinaryFile(root + _files[i])) + &quot;\r\n&quot;;
    return result;
}([
    &quot;serverscripts/NL_server_tools.js&quot;
    ,&quot;serverscripts/NL_server.js&quot;
    ,&quot;serverscripts/json2.js&quot;
]));
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;in this example I chose to regroup all Efficy specific functions in NL&lt;em&gt;server.js&lt;br&gt;
and all the pure javascripts tools as the splice polyfill in NL&lt;/em&gt;server_tools.js&lt;br&gt;
libjson is the copy of the standard libjson library used sometimes in some scripts. (JSON.parse and stringify)&lt;/p&gt;

&lt;p&gt;Cheers. feel free to improve this code or ask for all the librairies if you need it &lt;br&gt;
please share your code afterward.&lt;/p&gt;
</description>
<category>WorkFlow / Serverscript</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=2924/get-the-result-of-a-select-statement-to-an-array-of-object</guid>
<pubDate>Fri, 09 Feb 2018 14:36:11 +0000</pubDate>
</item>
<item>
<title>how to get Current User Language from a serverside script</title>
<link>https://overflow.efficy.io/?qa=2783/how-to-get-current-user-language-from-a-serverside-script</link>
<description>&lt;p&gt;Hi,&lt;/p&gt;

&lt;p&gt;I try to get the language code of the current user in a serverscript to do something like &lt;/p&gt;

&lt;p&gt;&quot;select STATUS&lt;em&gt;&quot; + langue + &quot; from LK&lt;/em&gt;OPPO_STATUS&quot;;&lt;/p&gt;

&lt;p&gt;but if I use the Database.Language it only return &quot;9&quot;.... that seems to correspond to ... nothing...&lt;/p&gt;

&lt;p&gt;should I use a client side GetLanguage and pass the value to the server as a parameter?&lt;/p&gt;

&lt;p&gt;It sure will work but is it really the best way to do that?&lt;/p&gt;
</description>
<category>Efficy/ Client side</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=2783/how-to-get-current-user-language-from-a-serverside-script</guid>
<pubDate>Thu, 30 Nov 2017 10:35:37 +0000</pubDate>
</item>
<item>
<title>include in serverscripts with this simple trick</title>
<link>https://overflow.efficy.io/?qa=2589/include-in-serverscripts-with-this-simple-trick</link>
<description>&lt;p&gt;Hi guys, &lt;/p&gt;

&lt;p&gt;sometime in serverscripts you can wish to organize your code over several serverscripts like a tools.js library by example.&lt;/p&gt;

&lt;p&gt;in almost cases you can just do the trick from your serverscripts call like : &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;%LoadScript(&quot;mylib1.js;mylib2.js;myscriptfile.js&quot;)%&amp;gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;same goes for ajax calls.&lt;/p&gt;

&lt;p&gt;this does not correspond to a real include from a file so we can't just use this trick for scheduler.exe.&lt;/p&gt;

&lt;p&gt;I found a way to make an include like call from a serverscript that works in scheduler as well so please enjoy it (even if the solution is a bit obvious I never thought about that before so...)&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;var root = &quot;C:/inetpub/wwwroot/customs/mycustom/&quot;;
var dependencies = [
    &quot;serverscripts/mylib1.js&quot;,
    &quot;serverscripts/mylib2.js&quot;
];

for (var i=0; i&amp;lt;dependencies.length; i++){
    eval(StrLoadBinaryFile(root + dependencies[i]));
}

function myFunction(){ //-----(called by the scheduler)
    return functionFromMyLib1(); //-----(definition in mylib1.js)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;since I havn't tested it in a workflow I can only assume that it would do the trick as well.&lt;/p&gt;

&lt;p&gt;Best regards,&lt;/p&gt;
</description>
<category>Efficy/ Client side</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=2589/include-in-serverscripts-with-this-simple-trick</guid>
<pubDate>Fri, 07 Jul 2017 08:05:16 +0000</pubDate>
</item>
<item>
<title>How to save a picture (base64 encoded) in the database through serverscript?</title>
<link>https://overflow.efficy.io/?qa=2417/save-picture-base64-encoded-database-through-serverscript</link>
<description>&lt;p&gt;Hello,&lt;/p&gt;

&lt;p&gt;For a Customer who uses an external website to add contacts, etc in their Efficy (Summer 2012). Multiple calls are possible like update user, create user, create/modify actions,..&lt;/p&gt;

&lt;p&gt;All these calls are posted to the serverscripts in the guestpage. All values are read correctly but we encounter 1 problem with an image.&lt;/p&gt;

&lt;p&gt;In the arguments 'picture' is defined and expects an long string (base64 encoded).&lt;br&gt;
For example: &lt;code&gt;&quot;iVBORw0KGgoAAAANSUhEUgAAAdgAAAG6CAYAAACr5VfIAAAACXBIWXMAAC4jAAAuIwF4pT92AAAAGXRFWHRTb2Z0d2...&quot; and this goes on for a while.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;As we are in serverscripts, I could not use windows object/functions.&lt;/p&gt;

&lt;p&gt;When we save, we are using the next line.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Database.UpdateFields(ContContext, 0,  'PICTURE', picture);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Where picture is saved now is a normal string, I could not convert it to a blob, stream.&lt;br&gt;
Converting the string to the following format did not work as well.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;var picture =  &quot;data:image/png;base64, ...&quot;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In db editor I can see the 'hugeblob' of an existing picture of a contact for example, on top defined the content type and below non readable text. &lt;/p&gt;

&lt;p&gt;Has anyone already managed to save this to the database as blob?&lt;br&gt;
It would be a great help because of the external website, there are not any other feasible options.&lt;/p&gt;

&lt;p&gt;Thanks in advance.&lt;br&gt;
Kind regards,&lt;/p&gt;

&lt;p&gt;Jonas Vdb&lt;/p&gt;
</description>
<category>WorkFlow / Serverscript</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=2417/save-picture-base64-encoded-database-through-serverscript</guid>
<pubDate>Mon, 03 Apr 2017 08:19:30 +0000</pubDate>
</item>
<item>
<title>Lock remains after a CloseContext in serverscripts</title>
<link>https://overflow.efficy.io/?qa=2360/lock-remains-after-a-closecontext-in-serverscripts</link>
<description>&lt;p&gt;Hi again dear community^^, &lt;/p&gt;

&lt;p&gt;I have a serverscript that is run by the user &quot;admin&quot; through the scheduleradmin.exe and that create a company record : &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;var ec = Database.OpenEditContext(ntComp, 0, false);

            try{
                Database.UpdateFields(ec, 0, VarArrayOf([&quot;NAME&quot;]), VarArrayOf([compName])); 

                Database.CommitChanges(ec, true);

                Database.Log(&quot;created : &quot; + ds.FieldByName(&quot;K_COMPANY&quot;).AsInteger);
            }
            finally{
                Database.CloseContext(ec);
                Database.log('finally');
            }
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;but right after my code is executed within the lock timeout delay, if I go with my own user on the created company, I have the currently locked record error.&lt;/p&gt;

&lt;p&gt;Is that normal?&lt;/p&gt;
</description>
<category>Efficy/ Client side</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=2360/lock-remains-after-a-closecontext-in-serverscripts</guid>
<pubDate>Wed, 15 Mar 2017 16:12:29 +0000</pubDate>
</item>
<item>
<title>Prototypes override in serverscripts</title>
<link>https://overflow.efficy.io/?qa=2359/prototypes-override-in-serverscripts</link>
<description>&lt;p&gt;Hi, &lt;/p&gt;

&lt;p&gt;in the serverscripts contexts (like a taskscheduler) I try to use some function that are not implemented (eg : Array.prototype.splice, or indexof) by the efficy js compiler (? am I right?).&lt;/p&gt;

&lt;p&gt;anyway, i used in my script a typical prototype's override like : &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Array.prototype.splice = function (_index, _length, _elems){
    var result = new Array();
    var i = 0;

    while (i &amp;lt; _index){
        result.push(this[i]);
        i++;
    }

    if (_elems) for (var j=0; j&amp;lt;_elems.length; j++) result.push(_elems[j]);

    i = _index + _length;

    while (i&amp;lt;this.length){
        result.push(this[i]);
        i++;
    }

    this = result;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;At this point I don't even care about my code working or not, being optimized or not...&lt;/p&gt;

&lt;p&gt;Then in my code I try to call my prototype by using a classic : &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;myArray.splice(1, 2);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;but efficy throw me an error like my method doesn't exist...&lt;/p&gt;

&lt;p&gt;I can only assume that the prototype I override is not the one called by my code after the Efficy dual language compiler has done its work.&lt;/p&gt;

&lt;p&gt;Am I right in my interpretation? &lt;br&gt;
what would you recommand me to use to make those kind of overrides?  &lt;br&gt;
is it forecast to implement a real JS engine to Efficy? (please tell me you will convert efficy dll as a nodejs application)&lt;/p&gt;

&lt;p&gt;meanwhile if you need to use those kind of functionnalities this is what I ve temporarly done : &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;function splice(_array, _index, _length, _elems){
    var result = new Array();
    var i = 0;

    while (i &amp;lt; _index){
        result.push(_array[i]);
        i++;
    }

    if (_elems) for (var j=0; j&amp;lt;_elems.length; j++) result.push(_elems[j]);

    i = _index + _length;

    while (i&amp;lt;_array.length){
        result.push(_array[i]);
        i++;
    }

    return result;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;and then I call it this way : &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;myTab = splice(myTab, 1, 2);
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Efficy/ Client side</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=2359/prototypes-override-in-serverscripts</guid>
<pubDate>Wed, 15 Mar 2017 14:57:52 +0000</pubDate>
</item>
<item>
<title>Delphi Server Scripts not supported anymore since Efficy10SP1</title>
<link>https://overflow.efficy.io/?qa=2198/delphi-server-scripts-supported-anymore-since-efficy10sp1</link>
<description>&lt;p&gt;Server scripts and also scheduled scripts and datasynchro scripts?&lt;/p&gt;
</description>
<category>Efficy 10 SP2</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=2198/delphi-server-scripts-supported-anymore-since-efficy10sp1</guid>
<pubDate>Mon, 16 Jan 2017 16:09:39 +0000</pubDate>
</item>
<item>
<title>how to set a Acc_account password from script or SQL</title>
<link>https://overflow.efficy.io/?qa=2125/how-to-set-a-accaccount-password-from-script-or-sql</link>
<description>&lt;p&gt;Hi I would like to set an Acc_account password from SQL or from a Serverscript.&lt;/p&gt;

&lt;p&gt;is that even possible?&lt;/p&gt;
</description>
<category>WorkFlow / Serverscript</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=2125/how-to-set-a-accaccount-password-from-script-or-sql</guid>
<pubDate>Mon, 19 Dec 2016 16:22:24 +0000</pubDate>
</item>
<item>
<title>Calling a web service through a proxy server in serverside script</title>
<link>https://overflow.efficy.io/?qa=2064/calling-web-service-through-proxy-server-serverside-script</link>
<description>&lt;p&gt;Hi,&lt;/p&gt;

&lt;p&gt;we come across a problem that we have to call a web service through a proxy server. Has someone done this before?&lt;/p&gt;

&lt;p&gt;Best regards,&lt;br&gt;
Jeroen Floor&lt;/p&gt;
</description>
<category>WorkFlow / Serverscript</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=2064/calling-web-service-through-proxy-server-serverside-script</guid>
<pubDate>Thu, 01 Dec 2016 16:37:32 +0000</pubDate>
</item>
<item>
<title>How to found the list of columns of a DataSet ?</title>
<link>https://overflow.efficy.io/?qa=1951/how-to-found-the-list-of-columns-of-a-dataset</link>
<description>&lt;p&gt;Hi to all,&lt;/p&gt;

&lt;p&gt;I want to write a &quot;generic&quot; function to read data via a SQL request...&lt;br&gt;
The problem is that I don't know the list of columns inside the Dataset result, while the query is build +/-  dynamically...&lt;/p&gt;

&lt;pre&gt;&lt;code&gt; var mysql = &quot;select * from COMPANIES&quot;   // &amp;lt;- query unknow 
 var myDataSet = Database.ExecuteSystemSQLQuery(0, Database.OpenTemporaryContext, mysql, null, true, true, 36); //
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Is a way to obtain something like :&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;var columns = myDataSet.Columns(); //   [ 'K_COMPANY', 'NAME',... ]
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Regards&lt;br&gt;
Didier&lt;/p&gt;
</description>
<category>WorkFlow / Serverscript</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=1951/how-to-found-the-list-of-columns-of-a-dataset</guid>
<pubDate>Fri, 21 Oct 2016 08:28:35 +0000</pubDate>
</item>
<item>
<title>How to run an Efficy Query from Serverside ?</title>
<link>https://overflow.efficy.io/?qa=1945/how-to-run-an-efficy-query-from-serverside</link>
<description>&lt;p&gt;Dear All,&lt;/p&gt;

&lt;p&gt;I have to execute an Efficy Query(the one from the Efficy Interface) from a schedulescript and to get the data into a Dataset.&lt;br&gt;
I haven't find any solution yet, does anyone did such thing before ?&lt;/p&gt;
</description>
<category>WorkFlow / Serverscript</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=1945/how-to-run-an-efficy-query-from-serverside</guid>
<pubDate>Tue, 18 Oct 2016 16:17:01 +0000</pubDate>
</item>
<item>
<title>Schedule the generated (.dat) script by datasynch tool</title>
<link>https://overflow.efficy.io/?qa=1912/schedule-the-generated-dat-script-by-datasynch-tool</link>
<description>&lt;p&gt;Hello,&lt;/p&gt;

&lt;p&gt;Is there a solution to schedule the import script (.bat) generated by datasynch tool. I have tried using schedule admin tool but it generates a lot of errors.&lt;/p&gt;

&lt;p&gt;Thanks&lt;/p&gt;
</description>
<category>Utilities</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=1912/schedule-the-generated-dat-script-by-datasynch-tool</guid>
<pubDate>Mon, 03 Oct 2016 14:36:52 +0000</pubDate>
</item>
<item>
<title>SSL/TLS REST serverscripts</title>
<link>https://overflow.efficy.io/?qa=1768/ssl-tls-rest-serverscripts</link>
<description>&lt;p&gt;Hi guys,&lt;/p&gt;

&lt;p&gt;Does anyone have experience with doing REST calls in Javascript, with a private key and certificate?&lt;/p&gt;

&lt;p&gt;I got something working now on my local dev pc, but it's in .NET and Curl.&lt;br&gt;
I need something in javascript to begin with.&lt;/p&gt;

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

&lt;p&gt;Michael.&lt;/p&gt;
</description>
<category>Efficy/ Client side</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=1768/ssl-tls-rest-serverscripts</guid>
<pubDate>Mon, 18 Jul 2016 10:01:11 +0000</pubDate>
</item>
<item>
<title>In Scheduled serverscripts, is it possible to get more detail on the error?</title>
<link>https://overflow.efficy.io/?qa=1582/scheduled-serverscripts-possible-get-more-detail-the-error</link>
<description>&lt;p&gt;Today when you have a Error in the Schedule Script you will have something like this:&lt;/p&gt;

&lt;p&gt;[2016/05/03 16:04:15.858] Error: WKFL-2142 Error while executing Script &quot;Microsoft JScript runtime error&quot; at line 115 char 5.&lt;br&gt;
Message: &quot;Object doesn't support this property or method&quot;&lt;/p&gt;

&lt;p&gt;If I am doing a &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;try {
} catch (e) {
   Database.Log(e.message);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I am getting only the message &lt;strong&gt;&quot;Object doesn't support this property or method&quot;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Is there only possibility to get also the Error &lt;strong&gt;&quot;WKFL-2142 Error while executing Script &quot;Microsoft JScript runtime error&quot; at line 115 char 5.&quot;&lt;/strong&gt; ?&lt;/p&gt;

&lt;p&gt;I would like to log this information for synchronization purpose.&lt;/p&gt;
</description>
<category>WorkFlow / Serverscript</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=1582/scheduled-serverscripts-possible-get-more-detail-the-error</guid>
<pubDate>Tue, 03 May 2016 14:08:38 +0000</pubDate>
</item>
<item>
<title>Template Script Return value containing $$ENCODE$$</title>
<link>https://overflow.efficy.io/?qa=1440/template-script-return-value-containing-encode</link>
<description>&lt;p&gt;Dear All,&lt;/p&gt;

&lt;p&gt;I get the following Template Script from Efficy France and there is a particularity in it.&lt;br&gt;
It return the value $$ENCODE$$ ... so what is it?&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;/*
usage
[$RunScript(name=&quot;GetListeParticipants1&quot;, file=&quot;DMS_CRSIPP&quot;,TypeResultat=&quot;var&quot;)]
var= ['NOMPRENOMFONCTION'] 
*/
function GetListeParticipants1(ContextHandle) {
                var K_DOCU = Database.GetFieldValue(ContextHandle, 'K_DOCUMENT')

                var Type = Variables.Values('TypeResultat')

                var QueryHandle;
                var SQLQuery = &quot; SELECT CONTACTS.K_CONTACT, CONTACTS.NAME,CONTACTS.FIRSTNAME, &quot; +
                               &quot; CONT_COMP.JOBTITLE &quot;+
                               &quot; from &amp;lt;#table name = 'DOCU_CONT'&amp;gt; DOCU_CONT &quot;+
                               &quot; INNER JOIN &amp;lt;#table name = 'CONTACTS'&amp;gt; CONTACTS &quot;+
                               &quot; ON DOCU_CONT.K_CONTACT = CONTACTS.K_CONTACT &quot;+
                               &quot; LEFT OUTER JOIN &amp;lt;#table name = 'CONT_COMP'&amp;gt; CONT_COMP &quot;+
                               &quot; ON (CONTACTS.K_CONTACT = CONT_COMP.K_CONTACT AND CONT_COMP.D_END IS NULL AND CONT_COMP.MAIN = '1') &quot;+
                               &quot; LEFT OUTER JOIN &amp;lt;#table name = 'COMPANIES'&amp;gt; COMPANIES &quot;+
                               &quot; ON CONT_COMP.K_COMPANY = COMPANIES.K_COMPANY &quot; +
                               &quot; where DOCU_CONT.K_DOCUMENT = :PARAM1&quot;;

                var Result='';

                var QueryContextHandle = Database.OpenTemporaryContext;
                    var ResultDS = Database.ExecuteSystemSQLQuery(QueryHandle, QueryContextHandle, SQLQuery, K_DOCU, true, true, 0);
                    ResultDS.First;
                    while (!ResultDS.Eof) {
                        var RESULTTEMP=ResultDS.FieldByName('JOBTITLE').AsString;
                        if (Type=='NOMPRENOMFONCTION' &amp;amp;&amp;amp; RESULTTEMP &amp;lt; 64) 
                            Result = Result +ResultDS.FieldByName('NAME').AsString +' '+ResultDS.FieldByName('FIRSTNAME').AsString +'[$LF]'+ResultDS.FieldByName('JOBTITLE').AsString +'[$LF]'+'[$LF]';
                        else
                            Result = Result +ResultDS.FieldByName('NAME').AsString +' '+ResultDS.FieldByName('FIRSTNAME').AsString +'[$LF]'+ResultDS.FieldByName('JOBTITLE').AsString +'[$LF]';
                        ResultDS.Next   
                    }
                return &quot;$$ENCODE$$&quot;+Result;
}
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>WorkFlow / Serverscript</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=1440/template-script-return-value-containing-encode</guid>
<pubDate>Tue, 22 Mar 2016 08:48:40 +0000</pubDate>
</item>
<item>
<title>Efficy SOAP vs. ServerScripts</title>
<link>https://overflow.efficy.io/?qa=768/efficy-soap-vs-serverscripts</link>
<description>&lt;p&gt;Hi guys!&lt;/p&gt;

&lt;p&gt;We need to integrate efficy data and processes into a website. &lt;br&gt;
Including sending emails etc.&lt;/p&gt;

&lt;p&gt;I wondered if it is possible to call a server script via SOAP just like &amp;lt;%RunScript()%&amp;gt;.&lt;br&gt;
Otherwise I need to update some hidden fields field and let workflow do the job...&lt;/p&gt;

&lt;p&gt;Thank you&lt;/p&gt;

&lt;p&gt;Tim&lt;/p&gt;

&lt;p&gt;P.S. overflow.efficy.com does a great job! Well done!&lt;/p&gt;
</description>
<category>Remote API (JSON, SOAP, Node)</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=768/efficy-soap-vs-serverscripts</guid>
<pubDate>Thu, 17 Sep 2015 09:17:10 +0000</pubDate>
</item>
<item>
<title>Flexmail Free Field Length ?</title>
<link>https://overflow.efficy.io/?qa=751/flexmail-free-field-length</link>
<description>&lt;p&gt;Hello Everybody,&lt;/p&gt;

&lt;p&gt;Does anyone of you know the max lenght of the data field &quot;free&lt;em&gt;field&lt;/em&gt;XX&quot; that we can send?&lt;/p&gt;

&lt;p&gt;I looked on the Flexmail API, but they only say that it is a string we don't know the length of it : &lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;http://www.flexmail.eu/fr/api/manual/type/12-emailaddresstype&quot;&gt;Flexmail API&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We &lt;/p&gt;
</description>
<category>Efficy Integrations</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=751/flexmail-free-field-length</guid>
<pubDate>Wed, 16 Sep 2015 07:28:37 +0000</pubDate>
</item>
<item>
<title>Version 2012 - Add contacts to a publication and to the actions link</title>
<link>https://overflow.efficy.io/?qa=717/version-2012-add-contacts-publication-and-the-actions-link</link>
<description>&lt;p&gt;When I add contacts to a publication, these contacts are to be added to the actions link to this publication.&lt;/p&gt;

&lt;p&gt;I did a workflow.&lt;/p&gt;

&lt;p&gt;To add contacts to the publication there are 4 possibilities:&lt;/p&gt;

&lt;p&gt;1)  Add using Search      =&amp;gt; I use &quot;BeforeCommitPublCont&quot; and       &quot;BeforeCommitContPubl&quot;  &lt;br&gt;
2)  Add using Query       =&amp;gt; I use    &quot;OnBeforeAddLinkPublCont&quot; and &quot;OnBeforeAddLinkContPubl&quot;&lt;/p&gt;

&lt;p&gt;3)   Add using a Profile            &lt;strong&gt;=&amp;gt; What is to be used ?&lt;/strong&gt;  &lt;br&gt;
4)   Add using a Publication     &lt;strong&gt;=&amp;gt; What is to be used ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Thank you&lt;/p&gt;
</description>
<category>WorkFlow / Serverscript</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=717/version-2012-add-contacts-publication-and-the-actions-link</guid>
<pubDate>Mon, 07 Sep 2015 13:49:19 +0000</pubDate>
</item>
<item>
<title>Script which checks a date field an send a mail automatically using a template in the template list</title>
<link>https://overflow.efficy.io/?qa=673/script-which-checks-field-automatically-template-template</link>
<description>&lt;p&gt;I need a script that checks a date field, once the period has been arrived, the script should send a mail automatically using a template in the template list to the related person.&lt;/p&gt;

&lt;p&gt;(It can also be used for B-Days)&lt;/p&gt;

&lt;p&gt;Thx,&lt;br&gt;
Can D.&lt;/p&gt;
</description>
<category>WorkFlow / Serverscript</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=673/script-which-checks-field-automatically-template-template</guid>
<pubDate>Wed, 26 Aug 2015 14:10:36 +0000</pubDate>
</item>
<item>
<title>how to get the correct datetime string from a recordset via serverside javascript</title>
<link>https://overflow.efficy.io/?qa=560/correct-datetime-string-recordset-serverside-javascript</link>
<description>&lt;p&gt;It seems that when we request the time from D_CHANGE and convert it to a string, we get the UTC time instead of the local time:&lt;/p&gt;

&lt;p&gt;var chgeDate = FormatDateTime(&quot;dd/mm/yyyy hh:nn&quot;, DataSet.FieldByName('D_CHANGE').AsFloat);&lt;/p&gt;

&lt;p&gt;Is there an easy trick to get the local time?&lt;/p&gt;
</description>
<category>WorkFlow / Serverscript</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=560/correct-datetime-string-recordset-serverside-javascript</guid>
<pubDate>Mon, 27 Jul 2015 08:21:38 +0000</pubDate>
</item>
<item>
<title>Create Acti_Acti relation into SYS_ENTITYVIEWS without EntityView error</title>
<link>https://overflow.efficy.io/?qa=432/create-actiacti-relation-sysentityviews-without-entityview</link>
<description>&lt;p&gt;Hello &lt;br&gt;
I created a new relation Acti_Acti.&lt;br&gt;
Following the SQL Code to create my new relation&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;insert into SYS_ENTITYVIEWS (NAME, ISCUSTOM, TABLEVIEWS) values ('Acti_Acti', 1, 'Acti_Acti')

Update SYS_ENTITYVIEWS set 
    ISCUSTOM=1, 
    TABLEVIEWS=(SELECT TABLEVIEWS FROM SYS_ENTITYVIEWS WHERE NAME = 'ActiEdit') + ';Acti_Acti=Acti'
where NAME='ActiEdit' 

Update SYS_ENTITYVIEWS set 
    ISCUSTOM=1, 
    TABLEVIEWS=(SELECT TABLEVIEWS FROM SYS_ENTITYVIEWS WHERE NAME = 'ActiDelete') + ';Acti_Acti=Acti'
where NAME='ActiDelete' 
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;When I try create a relation from ServerScript in an Edit context the server bring me back this  error &lt;br&gt;
unknown EntityView.&lt;br&gt;
Error context.&lt;/p&gt;

&lt;p&gt;But When I create a link though the Edit screen (Standard method) it's working. &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;onclick=&quot;RelationButtonClick(this, 'Acti', '60', '1028', false)&quot; 
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Delete a relation To.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;javascript:CebPerform('CEB_DEL_REL_', 'Acti35219')
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;But I can't do the same thing from a serverscript.&lt;br&gt;
So any idea why ?&lt;/p&gt;
</description>
<category>Efficy Developers</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=432/create-actiacti-relation-sysentityviews-without-entityview</guid>
<pubDate>Wed, 03 Jun 2015 15:35:23 +0000</pubDate>
</item>
</channel>
</rss>