Wednesday, 18 September 2013

AX2012 Delete Action: Restricted Vs. Cascade+Restricted

Restricted Vs. Cascade+Restricted 

Cascade + Restricted Delete Action, useful only when using 3 tables.
Scenario 1 :
Table1 is having a restricted delete actions with table2 and table3 is having a cascade delete action with table1.
Now if we try to delete the record in table3 , and if record exists in table2 , we will get error
"The record may not be deleted. Transactions exist in table 'Table2'."

Scenario 2:

Table1 is having a cascade + restricted delete actions with table2 and table3 is having a cascade delete action with table1.
Now if we try to delete the record in table3 , and if record exists in table2, records will be deleted from table 3 , table 1 and table 2 as well.

One more thing , if you will try to delete the data from table1 and record exist in table2 , you cannot delete the  data in table1 (now cascade + restricted will behave like restricted)


information get from Click here

Monday, 15 October 2012

Dynamics Axapta Basic methods

Display method:

static InventTable find(ItemId      itemId,
                        boolean     update = false)
{
    InventTable  inventTable;
    ;

    inventTable.selectForUpdate(update);

    if (itemId)
    {
        select firstonly inventTable
            index hint ItemIdx
            where inventTable.ItemId == itemId;
    }

    return inventTable;
}

Exist method:

static boolean exist(ItemId  itemId)

{

    return itemId && (select RecId from inventTable

                index hint ItemIdx

                where inventTable.ItemId == itemId

           ).RecId != 0;

}

Lookup method:
Method 1:

static void nonProductionLookup(FormStringControl   _ctrl)//,str category)
{
    Query query             =   new Query();
    QueryBuildDataSource        qbds1;
    QueryBuildRange             qbr;
    SysTableLookup              sysTableLookup;
    ;
    sysTableLookup = sysTableLookup::newParameters(tablenum(PMMachineTable),_ctrl);

    sysTableLookup.addLookupfield(fieldnum(PMMachineTable,MId));
    sysTableLookup.addLookupfield(fieldnum(PMMachineTable,AssetName));

    qbds1 = query.addDataSource(tableNum(PMMachineTable));
    qbr  = qbds1.addRange(fieldNum(PMMachineTable,PmEqType));

    qbr.value(enum2value(PmEqType::NonProduction));

    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();

}

Method2:
Public void lookup ()
{
    SysTableLookup          sysTableLookup;
    Query                   q =new Query();
    QueryBuildDataSource    qbds,qbds1;
    QueryBuildRange         qbr,qbr1,qbr2;
    PMSpecLookUp            specLookUp;
    PMSpecificationTemplateLine specificationTemplateLine;
    ;
    sysTableLookup = sysTableLookup::newParameters(tablenum(PMSpecLookUp),this);

    sysTableLookup.addLookupfield (fieldnum (PMSpecLookUp,PMSpecificLookUp));
    sysTableLookup.addLookupfield(fieldnum(PMSpecLookUp,Description));

    qbds  = q.addDataSource(tableNum(PMSpecLookUp));
    qbds1 = q.addDataSource(tablenum(PMSpecificationTemplateLine));
    qbr   = qbds.addRange(fieldnum(PMSpecLookUp,PMGroup));
    qbr2  = qbds1.addRange(fieldNum(PMSpecificationTemplateLine,Description));
    qbds1.joinMode(JoinMode::ExistsJoin);
    qbds1.relations(true);

    qbr.value(PMSpecificationTemplateLine.Description);


    sysTableLookup.parmQuery(q);
    sysTableLookup.performFormLookup();
}
JumpRef method:
public void jumpRef()
{
    Args args = new args();
    FormRun formrun;
    ;
//    super();

    args     = new Args(formStr(PMSpecLookUp));
    args.caller(element);
    args.lookupField(fieldNum(PMSpecLookUp,PMSpecificLookUp));
    args.lookupValue(PMSpecificationTemplateLine.PMSpecificLookUp);

    formRun = ClassFactory::formRunClassOnClient(args);
    formRun.init();
    formRun.run();
    formRun.wait();

}