<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Efficy Overflow Q&amp;A - Recent questions tagged data-ajax-url</title>
<link>https://overflow.efficy.io/?qa=tag/data-ajax-url</link>
<description>Powered by Question2Answer</description>
<item>
<title>How to activate Ajax call on select2 attached to a &lt;select&gt; element ?</title>
<link>https://overflow.efficy.io/?qa=6741/how-to-activate-ajax-call-on-select2-attached-select-element</link>
<description>&lt;p&gt;Dear all,&lt;/p&gt;

&lt;p&gt;I am trying to build a &lt;code&gt;&amp;lt;select&amp;gt;&lt;/code&gt; with the &quot;select2&quot; component in order to search data from a Macro in a asynchronous mode because I am searching data to another entity. &lt;/p&gt;

&lt;p&gt;I now that in standard I can use the definition &lt;code&gt;LOOKUPDROPDOWNSEARCH&lt;/code&gt; but by doing so I forced to overwrite the &lt;code&gt;pages/dropdown/ListSearch.htm&lt;/code&gt; in order to pass the Macro I needed to load the data + I need to override the &lt;code&gt;editDetailCmd.js&lt;/code&gt; to pass this macro to the page. which is very not convenient.&lt;/p&gt;

&lt;p&gt;I wanted at first use the &lt;code&gt;&quot;data-ajax-url&quot;&lt;/code&gt; attribut, but it seems we are not allowed to do so on HTML &lt;code&gt;&amp;lt;select&amp;gt;&lt;/code&gt; tag, at least with the select2 library version we have in Efficy Entreprise which is version 3.5.2. &lt;/p&gt;

&lt;p&gt;If we try to use it we got the following error : &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;select2.js?ist=20221004215237&amp;amp;c=202210311518:947 Uncaught Error: Option 'ajax' is not allowed for Select2 when attached to a &amp;lt;select&amp;gt; element.
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And I don't want to use an HTML &lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt; tag like it is used in standard for PostCode/City field since the value that I will store will be a key not a text.&lt;/p&gt;
</description>
<category>Efficy/ Client side</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=6741/how-to-activate-ajax-call-on-select2-attached-select-element</guid>
<pubDate>Mon, 31 Oct 2022 16:36:19 +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>Filter Multiselect filed in category based on value on main Tab</title>
<link>https://overflow.efficy.io/?qa=2695/filter-multiselect-filed-in-category-based-on-value-main-tab</link>
<description>&lt;p&gt;Hello,&lt;/p&gt;

&lt;p&gt;I'm trying to filter multi-select field in category based on value chosen in lookup on Main tab in Cases. I've tried to achieb this by adding this piece of JS to MacroEditSCustom&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;if($('#CASETYPE').val()){
            var newDataAjaxURL = &quot;dialog?_macro=JsonDynaMultiValueListCaseCat&amp;amp;_macrofile=MacroAjax&amp;amp;edithandle=&amp;lt;%GetEditHandle()%&amp;gt;&amp;amp;field=CATEGORY-CASE$GENERAL-F_CATEGORY&amp;amp;casetype=&quot; + $('#CASETYPE').val();
            var $FieldName = $(&quot;#CATEGORY-CASE$GENERAL-F_CATEGORY&quot;)
            if($FieldName.length){
                $FieldName.attr('data-ajax-url', newDataAjaxURL);
            }
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;and the definition in MacroAjaxCustom&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;JsonDynaMultiValueListCaseCat {[&amp;lt;%Delay(0)%&amp;gt;RunQuery(id='DynaMultiValueListCaseCat', 
    SQL='Select F_CATEGORY as F_CATEGORY_EN, * from LK_CASE_CATEGORY CC where f_case_type like :param1 and disabled = 0 order by k_sort',
    Param1=&quot;%;&amp;lt;%GetArgument('casetype')%&amp;gt;;%&quot;
    )%&amp;gt;
    &amp;lt;%Delay(0)%&amp;gt;GetDataGrid(query='DynaMultiValueListCaseCat', count=-1, norecords='', sort='F_CATEGORY_&amp;lt;%GetLanguage()%&amp;gt;' , nolinefeed=T, templatetext=|[&amp;lt;#repeat&amp;gt;
    {
         &quot;id&quot;:&amp;lt;#F=K_CASE_CATEGORY&amp;gt;
        ,&quot;text&quot;:&quot;&amp;lt;#F=F_CATEGORY_&amp;lt;%GetLanguage()%&amp;gt;;jsontext=T;nospace=T&amp;gt;&quot; 

    }&amp;lt;#S=;SEPARATOR=,&amp;gt;&amp;lt;/#repeat&amp;gt;
]|)%&amp;gt;]}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Plus changing CASETYPE in Forms with definition LOOKUPMASTER and add it in FormFieldsEditCustom&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;field.LOOKUPMASTER {[&amp;lt;%GetEdit(&quot;$FIELD$&quot;, type=&quot;LOOKUP&quot;, onchange=&quot;JavaScript:CebPerform('CEB_STATE');&quot;)%&amp;gt;]}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;so every time user chooses new value it refresh the page and set new URL on attribute &quot;data-ajax-url&quot;.&lt;/p&gt;

&lt;p&gt;It works fine if i save directly the case, but if i hit the button &quot;apply&quot; then it's not working, even the attribute has the right URL, but on clicking on the field i get the standard ajax-url&lt;/p&gt;

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

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

&lt;p&gt;Please advise.&lt;br&gt;
Thank you for your help in advance.&lt;br&gt;
Best Regards.&lt;/p&gt;
</description>
<category>Efficy/ Client side</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=2695/filter-multiselect-filed-in-category-based-on-value-main-tab</guid>
<pubDate>Wed, 13 Sep 2017 13:36:16 +0000</pubDate>
</item>
</channel>
</rss>