RF Interface. General methods.

Here are some usefull methods that may help you in RF interface development.

General methods

protected container addTop(container _source, container _add)
{
    int a;

    for (a = conLen(_add); a >= 1; a--)
    {
        _source = conIns(_source, 1, conPeek(_add, a));
    }

    return _source;
}

protected container copyErrors(container _con, container _new)
{
    int     length;
    int     i = 3
    ;

    length = conLen(_con);

    while (i <= length)
    {
        if (conPeek(conPeek(_con, i), #controlType) == #RFLabel &&
            conPeek(conPeek(_con, i), #name) == #RFError)
        {
            _new = conIns(_new, 1, conPeek(_con, i));
        }

        ++i;
    }

    return _new;
}

protected container removeErrors(container _con)
{
    int     i = conLen(_con);

    while (i >= #ControlsStart)
    {
        if (conPeek(conPeek(_con, i), #controlType) == #RFLabel &&
            conPeek(conPeek(_con, i), #name) == #RFError)
        {
            _con = conDel(_con, i, 1);
        }

        i--;
    }

    return _con;
}


protected void resetPassValue(List _copyValues = null)
{
    WHSRFPassthrough    newPass = WHSRFPassthrough::newEmpty();
    ListEnumerator      le;

    if (pass.exists(#InventSiteId))
    {
        newPass.insert(#InventSiteId, pass.lookup(#InventSiteId));
    }
    if (pass.exists(#InventLocationId))
    {
        newPass.insert(#InventLocationId, pass.lookup(#InventLocationId));
    }
    if (pass.exists(#UserId))
    {
        newPass.insert(#UserId, pass.lookup(#UserId));
    }
    if (pass.exists(#UserSessionId))
    {
        newPass.insert(#UserSessionId, pass.lookup(#UserSessionId));
    }
    if (pass.exists(#MenuItem))
    {
        newPass.insert(#MenuItem, pass.lookup(#MenuItem));
    }

    if (!prmisDefault(_copyValues) && _copyValues)
    {
        le = _copyValues.getEnumerator();
        le.reset();
        while (le.moveNext())
        {
            if (newPass.exists(le.current()))
            {
                newPass.remove(le.current());
            }
            if (pass.exists(le.current()))
            {
                newPass.insert(le.current(), pass.lookup(le.current()));
            }
        }
    }

    pass = newPass;
}

Inventory dimensions methods

Usefull standard method to get inventDim from pass: \Classes\WHSWorkExecuteDisplay\initInventDimFromPassDimList

Usage: this.initInventDimFromPassDimList(inventDim, InventDim::dimFieldsList());

Or: \Classes\WHSWorkExecuteDisplay\createInventDimFromPass

Want to have dimension drop down controls?

We have to modify \Classes\WHSRFControlData\processData to force standard functionality correctly process new dimension controls.

Add following if statement almost to the end of method. Code should look like:

            }
            // Product dimension drop down -->
            else if ((#ColorId == name || #SizeId == name || #ConfigId == name || #StyleId == name) && data)
            {
                hasError = controlData.processControl(name, data);
                if (hasError)
                {
                    con = conPoke(con, i, conPoke(conPeek(con, i), #data, ''));
                    con = conPoke(con, i, conPoke(conPeek(con, i), #error, '1'));
                    break;
                }
            }
            // <-- Product dimension drop down
            else
            {
                controlData.populateData(name);
            }
        }
    }

    if (hasError)
    {
        con = controlData.rebuildContainer(con);
    }

    return [con, controlData.parmFieldValues().pack()];
Call this method to build product dimension drop down controls.

protected container buildProductDimensionsDD(
    container   _con,
    ItemId      _itemId,
    boolean     _populate = false)
{
    container       ret = _con;
    ListEnumerator  le;
    FieldName       fieldName;
    str             elements;
    str             value;

    le = InventDimGroupSetup::newItemIdProductDimensionsOnly(_itemId).activeFields().getEnumerator();

    while (le.moveNext())
    {
        fieldName = fieldId2name(tableNum(InventDim), le.current());

        elements = this.buildProductDimSequenceGroupString(_itemId, le.current(), true);

        value = (_populate && pass.exists(fieldName)) ? pass.lookupStr(fieldName) : '';
        ret += [this.buildControl(#RFCombobox, fieldName, fieldId2pname(tableNum(InventDim), le.current()), 1, elements, #WHSRFUndefinedDataType, '', 0, (pass.hasValue(fieldName)) ? false : true, value)];
    }

    return ret;
}

protected str buildProductDimSequenceGroupString(
    ItemId  _itemId,
    FieldId _fieldId,
    boolean _showBlank)
{
    InventDimCombination    inventDimCombination;
    InventDim               inventDim;
    Map                     map = new Map(Types::String, Types::Integer);
    str                     elements;
    boolean                 first = true;

    if (_showBlank)
    {
        elements = '||';
    }

    if (_itemId)
    {
        while select RecId from inventDimCombination
            join inventDim
            where inventDimCombination.ItemId   == _itemId
                &&inventDim.inventDimId         == inventDimCombination.InventDimId
        {
            if (!map.exists(inventDim.(_fieldId)))
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    elements += '||';
                }

                elements += inventDim.(_fieldId);
                map.insert(inventDim.(_fieldId), 1);
            }
        }
    }

    return elements;
}

protected boolean checkInventDim(ItemId _itemId, boolean checkTrackingDimensions = true)
{
    boolean                     ret = true;
    ListEnumerator              le;
    FieldName                   fieldName;

    void checkValues()
    {
        while (le.moveNext())
        {
            fieldName = fieldId2name(tableNum(InventDim), le.current());
            if (!pass.hasValue(fieldName))
            {
                ret = false;
                break;
            }
        }
    }
    le = InventDimGroupSetup::newItemIdProductDimensionsOnly(_itemId).activeFields().getEnumerator();
    checkValues();
    if (checkTrackingDimensions)
    {
        le = InventDimGroupSetup::newDimensionGroups(0, 0, InventTable::find(_itemId).trackingDimensionGroup()).activeFields().getEnumerator();
        checkValues();
    }

    return ret;
}

protected InventDim getInventDim(ItemId _itemId, boolean setTrackingDimensions = true)
{
    FieldId                     fieldId;
    InventDim                   inventDim;
    FieldName                   fieldName;
    ListEnumerator              le;
    void getValues()
    {
        while (le.moveNext())
        {
            fieldId    = le.current();
            fieldName = fieldId2name(tableNum(InventDim), fieldId);
            if (pass.exists(fieldName))
            {
                inventDim.(fieldId) = pass.lookup(fieldName);
            }
        }
    }

    inventDim.clear();

    le = InventDimGroupSetup::newItemIdProductDimensionsOnly(_itemId).activeFields().getEnumerator();
    getValues();
    if (setTrackingDimensions)
    {
        le = InventDimGroupSetup::newDimensionGroups(0, 0, InventTable::find(_itemId).trackingDimensionGroup()).activeFields().getEnumerator();
        getValues();
    }

    return inventDim;
}

Unit of Measure

protected container buildUoMConversionText(container _ret, InventTable _inventTable, InventDimId _inventDimId)
{
    container tmp;

    try
    {
        _ret += [this.buildControl(#RFLabel, "Invent Conversion", strFmt("1 %1 = %2 %3", pass.lookup(#SelectedValueUOM),
                                                                    InventTableModule::unitConvert(_inventTable.ItemId,
                                                                    ModuleInventPurchSales::Invent, pass.lookup(#SelectedValueUOM), 1, _inventDimId),
                                                                    _inventTable.inventUnitId()), 1, '', #WHSRFUndefinedDataType, '', 0)];
    }
    catch
    {
        tmp = this.addErrorLabelFromInfolog(conNull(), infologLine(), WHSRFColorText::Error);
        _ret = this.addTop(_ret, tmp);
    }
    return _ret;
}

Search

About

DaxOnline.org is free platform that allows you to quickly store and reuse snippets, notes, articles related to Dynamics AX.

Authors are allowed to set their own AdSense units.
Join us.

Blog Tags