13 Kasım 2015 Cuma

AXAPTA - Security check with X++ code

Sometimes we need security check with code (Display method etc...):



    SecurityKeySet securityKeys = new SecurityKeySet();
    ;
    securityKeys.loadUserRights(curuserid());

   if (securityKeys.access(securitykeynum("KRC_CrossCompany")) ==  AccessType::NoAccess)
   chkCrsCompany.value(NoYes::No);

12 Kasım 2015 Perşembe

AXAPTA - Add extra action to info function with SysInfoAction class

There're two ways to call a form with this class:

info(strfmt("Sales order created: %1",salesTable.SalesId),"",
            SysInfoAction_TableField::newBuffer(salesTable));


Difference with this way with up is while this way sends record data to form, upper way doesn't:

SysInfoAction_FormRun    infoAction = SysInfoAction_FormRun::newFormName(formStr(SalesTable));
;
infoAction.parmCallerBuffer(salestable);
 

info(strfmt("Satış siparişi oluşturuldu: %1",salesTable.SalesId),"",
            infoaction);

16 Ekim 2015 Cuma

AXAPTA - Pack-unpack at forms

ClassDeclaration method:

    Container   packedQuery;
    SysQueryRun qRun;
    s
tr dummy;
    #DEFINE.CurrentVersion(1)
    #LOCALMACRO.CurrentList
        dummy,
        packedQuery
    #ENDMACRO


Other methods:

container pack()
{
    ;
    dummy      = txtDummy.valuestr();
    return [#CurrentVersion,#CurrentList];
}


public boolean unpack(container _packedClass)
{
    int version = conPeek(_packedClass,1);

    switch (version)
   {
        case #CurrentVersion:
            [version,#CurrentList] = _packedClass;
            break;
        default:
            return false;
    }
    return true;
}


public void init()
{
    ;
    xSysLastValue::getLast(this);
    super();
    txtDummy(dummy);
    element.initQuery();
}


public void close()
{
    super();
    xSysLastValue::saveLast(this);
}


void initParmDefault()
{
}


private IdentifierName lastValueDesignName()
{
    return '';
}


private IdentifierName lastValueElementName()
{
    return this.name();
}


private UtilElementType lastValueType()
{
    return UtilElementType::Form;
}


private UserId lastValueUserId()
{
    return curuserid();
}


public dataAreaId lastValueDataAreaId()
{
    return curExt();
}


This method is not mandatory, but you may write like this if you would like to use query:


void initQuery()
{
  Query                q;
  QueryBuildDataSource qbds;
  QueryBuildDataSource qbds2;
  QueryBuildRange      qRange;
  ;
  if (packedQuery)
      qRun = new SysQueryRun(packedQuery);
  else
  {
      q = new query();
      qbds = q.addDataSource(tablenum(EmplTable));
      qRun = new SysQueryRun(q);
  }
  qRun.promptLoadLastUsedQuery(false);
}


This one is for select button of query, so of course not mandatory too:

 void clicked()
{
    ;
    super();
    if (qRun.prompt())
        packedQuery = qRun.pack();
}

12 Ekim 2015 Pazartesi

AXAPTA - Add right click menu popup to form control

You can do this with overwrite control's showContextMenu method:

public int showContextMenu(int _menuHandle)
{
    int                 ret;
    int                bar1,bar2;
    PopupMenu           pMenu = PopupMenu::create(_menuHandle,element.hWnd());
    ;
        bar1 = pMenu.insertItem("Selection 1");
        bar2 = pMenu.insertItem("Selection 2");

    ret = pMenu.draw();
    switch (ret)
    {
    case -1 :
        break;
    case bar1:

...
    case bar2:
...
    default :
        break;
    }
    return ret;

}

8 Ekim 2015 Perşembe

Axapta - Send and receive dataset

I took this code part from Fatih Demirci's developments.

Send dataset:
 

    System.Data.DataTable               dataTable;
    System.Data.DataColumnCollection    dataTableColumns;
    System.Data.DataRowCollection       DataRowCollection;
    System.Data.DataRow                 tmpRow;
    System.Data.DataSet dataset = new System.Data.DataSet();
    System.Data.DataTableCollection     dataTableCollection;


    dataTable = new System.Data.DataTable();
    dataTableColumns = dataTable.get_Columns();

//Describe lines
    dataTableColumns.Add("ACCOUNTNO", System.Type::GetType("System.String"));
    dataTableColumns.Add("ITEMNO", System.Type::GetType("System.String"));
    dataTableColumns.Add("TOACCOUNTNUM", System.Type::GetType("System.String"));
    dataTableColumns.Add("RETURNREASONIDD", System.Type::GetType("System.String"));
    dataTableColumns.Add("QUANTITY", System.Type::GetType("System.Double"));
    dataTableColumns.Add("DESCRIPTION", System.Type::GetType("System.String"));
//bir satır al
    DataRowCollection = dataTable.get_Rows();
        tmpRow = dataTable.NewRow();
//fill lines
    tmpRow.set_Item("ACCOUNTNO","MU_014600");
    tmpRow.set_Item("ITEMNO","200.05.01.0306");
    tmpRow.set_Item("TOACCOUNTNUM","MU_014600");
    tmpRow.set_Item("RETURNREASONIDD","");
    tmpRow.set_Item("QUANTITY",11);
    tmpRow.set_Item("DESCRIPTION","");

    DataRowCollection.Add(tmpRow);

     dataTable.AcceptChanges();
//At this time if opposite side needs data table, it's ready

//In the other case if wants dataset, tie to dataset
     dataTableCollection     = dataSet.get_Tables();
     dataTableCollection.Add(datatable);
//now dataset ready too


Receive dataset:

    System.Data.DataTable               dataTable;
    System.Data.DataTableCollection     dataTableCollection;
    System.Data.DataColumnCollection    dataColumnCollection;
    System.Data.DataRowCollection       dataRowCollection;
    System.Data.DataRow                 dataRow;
    System.Data.DataColumn              dataColumn;
    System.Data.DataTable               returnData;
;


        dataTableCollection     = dataSet.get_Tables();
        totalTable              = dataTableCollection.get_Count();
        for(i = 0; i < totalTable; i ++)
        {
            dataTable               = dataTableCollection.get_Item(i);
            dataColumnCollection    = dataTable.get_Columns();
            DataRowCollection       = dataTable.get_Rows();
            totalRow                = dataRowCollection.get_Count();
            totalCol                = dataColumnCollection.get_Count();
            for( j = 0; j < totalRow; j ++)
            {
                dataRow         = dataRowCollection.get_Item(j);
                custAccount     = dataRow.get_Item("ACCOUNTNO");
                itemId          = dataRow.get_Item("ITEMNO");
                toCustAccount   = dataRow.get_Item("TOACCOUNTNUM");
                strtext         = dataRow.get_Item("RETURNREASONIDD");
                krc_DefectiveId = str2int64(strtext);
                strtext         = dataRow.get_Item("QUANTITY");
                _b2bdesc        = dataRow.get_Item("DESCRIPTION");
...

3 Eylül 2015 Perşembe

Axapta - Query prompt prevent "Select query - query last used"

When you run a query and restore values  at Axapta you would be see values are not you restored. Reason would be "last used query" at "select query". To prevent this effect you have to use SysQueryRun instead of QueryRun. SysQueryRun is extended version of QueryRun.

This code prevents "last used query":

mySysQueryRun.promptLoadLastUsedQuery(false);

2 Eylül 2015 Çarşamba

Axapta - Transfer order partial receive

This's so easy with a way which I learned from a forum page :


inventTranstransferLine.QtyReceiveNow = 50;

When you post the transfer order, your 50 pcs items will be receive.