Wednesday, April 29, 2015

Add new button in existing form AX

//  Add new button in existing form AX

private void San_addAboutButton()
{
FormActionPaneControl actionPane;
FormActionPaneTabControl actionPaneTab;
FormCommandButtonControl cmdAbout;
FormButtonGroupControl btngrp;
#define.taskAbout(259)
actionPane = this.design().controlNum(1);
if (!actionPane ||
!(actionPane is FormActionPaneControl) ||
actionPane.style() == ActionPaneStyle::Strip)
{
return;
}
actionPaneTab = actionPane.controlNum(1);
if (!actionPaneTab ||
!(actionPaneTab is FormActionPaneTabControl))
{
return;
}
btngrp = actionPaneTab.addControl(
FormControlType::ButtonGroup, 'ButtonGroup');
btngrp.caption("About");
cmdAbout = btngrp.addControl(
FormControlType::CommandButton, 'About');
cmdAbout.command(#taskAbout);
cmdAbout.imageLocation(SysImageLocation::EmbeddedResource);
cmdAbout.normalImage('412');
cmdAbout.big(NoYes::Yes);
cmdAbout.saveRecord(NoYes::No);
}

RUn Method

this.San_addAboutButton()

Form Creation through Code in ax .. For Dynamic Form Creation

// Form Creation through Code in ax .. For Dynamic Form Creation

static void DynamicFormAX(Args _args)
{
    DictTable                           dictTable;
    Form                                form;
    FormBuildDesign                     design;
    FormBuildDataSource                 dataSource;
    FormBuildActionPaneControl          actionPane;
    FormBuildActionPaneTabControl       actionPaneTab;
    FormBuildButtonGroupControl         buttonngroup1;
    FormBuildButtonGroupControl         buttonngroup2;
    FormBuildCommandButtonControl       cmdNew;
    FormBuildCommandButtonControl       cmdDel;  
    FormBuildMenuButtonControl          menubuttonPosting;
    FormBuildFunctionButtonControl      menuFuncbuttonPosting;
    FormBuildFunctionButtonControl      menuFuncbuttonForecast;
    FormBuildGridControl grid;
    FormBuildGroupControl grpBody;
    Args args;
    FormRun formRun;
    #Task
   
    dictTable = new DictTable(tableNum(CustGroup));
    form = new Form();
    form.name("CustGroupDynamic");
    dataSource = form.addDataSource(dictTable.name());
    dataSource.table(dictTable.id());
    design = form.addDesign('Design');
    design.caption("Customer groups");
    design.style(FormStyle::SimpleList);
    design.titleDatasource(dataSource.id());
    actionPane = design.addControl(FormControlType::ActionPane, 'ActionPane');
    actionPane.style(ActionPaneStyle::Strip);
    actionPaneTab = actionPane.addControl(FormControlType::ActionPaneTab, 'ActionPaneTab');
    buttonngroup1 = actionPaneTab.addControl(FormControlType::ButtonGroup, 'NewDeleteGroup');
    buttonngroup2 = actionPaneTab.addControl(FormControlType::ButtonGroup, 'ButtonGroup');
    cmdNew = buttonngroup1.addControl(FormControlType::CommandButton, 'NewButton');
    cmdNew.buttonDisplay(FormButtonDisplay::TextAndImageLeft);
    cmdNew.normalImage('11045');
    cmdNew.imageLocation(SysImageLocation::EmbeddedResource);
    cmdNew.primary(NoYes::Yes);
    cmdNew.command(#taskNew);
    cmdDel = buttonngroup1.addControl(FormControlType::CommandButton, 'NewButton');
    cmdDel.text("Delete");
    cmdDel.buttonDisplay(FormButtonDisplay::TextAndImageLeft);
    cmdDel.normalImage('10121');
    cmdDel.imageLocation(SysImageLocation::EmbeddedResource);
    cmdDel.saveRecord(NoYes::Yes);
    cmdDel.primary(NoYes::Yes);
    cmdDel.command(#taskDeleteRecord);
    /*menubuttonPosting = buttonngroup2.addControl(FormControlType::MenuButton, 'MenuButtonPosting');
    menubuttonPosting.helpText("Set up related data for the group.");
    menubuttonPosting.text("Setup");
    menuFuncbuttonPosting = menubuttonPosting.addControl(FormControlType::MenuFunctionButton, 'Posting');
    menuFuncbuttonPosting.text('Item posting');
    menuFuncbuttonPosting.saveRecord(NoYes::No);
    menuFuncbuttonPosting.dataSource(dataSource.id());
    menuFuncbuttonPosting.menuItemName(menuitemDisplayStr(InventPosting));
    menuFuncbuttonForecast = buttonngroup2.addControl(FormControlType::MenuFunctionButton, 'SalesForecast');
    menuFuncbuttonForecast.text('Forecast');
    menuFuncbuttonForecast.saveRecord(NoYes::No);
    menuFuncbuttonForecast.menuItemName(menuitemDisplayStr(ForecastSalesGroup));*/
    grpBody = design.addControl(FormControlType::Group, 'Body');
    grpBody.heightMode(FormHeight::ColumnHeight);
    grpBody.columnspace(0);
    grpBody.style(GroupStyle::BorderlessGridContainer);
    grid = grpBody.addControl(FormControlType::Grid, "Grid");
    grid.dataSource(dataSource.name());
    grid.widthMode(FormWidth::ColumnWidth);
    grid.heightMode(FormHeight::ColumnHeight);
    grid.addDataField(dataSource.id(), fieldNum(CustGroup,CustGroup));
    grid.addDataField(dataSource.id(), fieldNum(CustGroup,Name));
    grid.addDataField(dataSource.id(), fieldNum(CustGroup,PaymTermId));
    grid.addDataField(dataSource.id(), fieldnum(CustGroup,ClearingPeriod));
    grid.addDataField(dataSource.id(), fieldNum(CustGroup,BankCustPaymIdTable));
    grid.addDataField(dataSource.id(), fieldNum(CustGroup,TaxGroupId));
    args = new Args();
    args.object(form);
    formRun = classFactory.formRunClass(args);
    formRun.init();
    formRun.run();
    formRun.detach();
}

Get Default Dimensions value For Vend Cust Item

// Get Default Dimensions value For Vend Cust Item

static void San_GetDefaultDimensionsForVendCustItem(Args _args)
{
    VendTable                       vendTable;
    InventTable                     inventTable;
    CustTable                       custTable;
    DimensionAttributeValueSet      dimAttrValueSet;
    DimensionAttributeValueSetItem  dimAttrValueSetItem;
    DimensionAttributeValue         dimAttrValue;
    DimensionAttribute              dimAttr;
    Common                          dimensionValueEntity;
    ;
    //vendTable = VendTable::find('3008');
    //inventTable = InventTable::find('1001');
    custTable = CustTable::find('1102');
    //dimAttrValueSet = DimensionAttributeValueSet::find(vendTable.DefaultDimension);
    //dimAttrValueSet = DimensionAttributeValueSet::find(inventTable.DefaultDimension);
    dimAttrValueSet = DimensionAttributeValueSet::find(custTable.DefaultDimension);
    while select dimAttrValueSetItem
        where   dimAttrValueSetItem.DimensionAttributeValueSet   == dimAttrValueSet.RecId
    {
        dimAttrValue        = DimensionAttributeValue::find(dimAttrValueSetItem.DimensionAttributeValue);
        dimAttr             = DimensionAttribute::find(dimAttrValue.DimensionAttribute);
        dimensionValueEntity = DimensionDefaultingControllerBase::findBackingEntityInstance(curext(),dimAttr,dimAttrValue.EntityInstance);
        info(dimAttr.Name + ' ' + dimAttrValue.getValue());
    }
}

Copy Markup charges while posting purchase invoice using X++

 Copy Markup charges while posting purchase invoice using X++ Class: Important: Code logic is just for Reference.  New class => Duplicate...