0 votes

Hi !

My Products can be a "Batch" :
- PRODUCTS.FAMILY=1
- Contains other products

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

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

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

function addProductsFromLot() {
    var EditHandle = StrToIntDef(Request.Argument("editHandle"), 0), // Docu Edit Context
        lotKey = Request.Argument("lotKey"),
        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);
    }
}

Custom.js :

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

Thanks a lot!

closed with the note: e
asked in WorkFlow / Serverscript by (245 points)
closed by
1,169 questions
1,427 answers
1,718 comments
325 users