Saturday, 28 September 2019

Insert data in TempDB table using while Opning the Form in ax 2012

public class FormRun extends ObjectRun
{
    QueryBuildRange qbr,qbr1;
    Table1          tmpTableBufferParent;
    Table2          tmpTableBufferChild;

}

public void init()//Form init method
{
    super();
    //parent ->>>>>>>>>>>>>>>>>>>>>>>
    tmpTableBufferParent = element.insertRecordsParent();

    table1.setTmpData(tmpTableBufferParent);
    table1.linkPhysicalTableInstance(tmpTableBufferParent);

    //child-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    tmpTableBufferChild = element.insertRecordsBasicChild();

    table2.setTmpData(tmpTableBufferChild);
    table2.linkPhysicalTableInstance(tmpTableBufferChild);
}

Table2 insertRecordsBasicchild()
{
    Table2 tmpTableBufferlocal;
    purchline   purchline;
    PurchTable  PurchTable;

    while select PurchId from purchline
        exists join PurchTable where PurchTable.PurchId == purchline.PurchId
            && PurchTable.DocumentStatus == DocumentStatus::PurchaseOrder
            && PurchTable.DocumentState == VersioningDocumentState::Confirmed
            && PurchTable.PurchStatus == PurchStatus::Backorder
    {
        tmpTableBufferlocal.clear();
        tmpTableBufferlocal.field1 = purchline.PurchId;
        tmpTableBufferlocal.insert();
    }

    return tmpTableBufferlocal;
}

Table1 insertRecordsParent()
{
    Table1 tmpTableBuffer;
    PurchTable PurchTable;

    while select PurchId from PurchTable
        where  PurchTable.DocumentStatus == DocumentStatus::PurchaseOrder
            && PurchTable.DocumentState == VersioningDocumentState::Confirmed
            && PurchTable.PurchStatus == PurchStatus::Backorder
    {
        tmpTableBuffer.clear();
        tmpTableBuffer.field1 = PurchTable.purchid;
        tmpTableBuffer.field2 = "T1";
        tmpTableBuffer.insert();
    }

    return tmpTableBuffer;
}


DS Table1->Init method:

public void init()
{
    super();
    qbr = this.query().dataSourceTable(tableNum(table1)).addRange(fieldNum(table1,field1));
}

DS->executeQuery method:
public void executeQuery()
{
    if (FilterStringEdit.valueStr())
    {
        qbr.value(FilterStringEdit.valueStr());
    }
    super();
}

DS table2 : linkActive
public void linkActive()
{
    this.query().dataSourceTable(tableNum(table2)).clearRanges();

    select Field1 from table2
        where table2.Field1 == table1.Field1;
    if (table2.Field1)
    {
        this.query().dataSourceTable(tableNum(table2)).addRange(fieldNum(table2,field1)).value(table1.Field1);
    }
    else
    {
        this.query().dataSourceTable(tableNum(table2)).addRange(fieldNum(table2,field1)).value(SysQuery::valueEmptyString());
    }
    super();

}

No comments:

Post a Comment

DefaultDimension in d365 FO X++

 Navigate to PurchTable methods you can find with DefaultDimension this.DefaultDimension = this.mergeDimension(this.getDefaultDimension(),th...