Showing posts with label DataSource. Show all posts
Showing posts with label DataSource. Show all posts

Saturday, April 24, 2021

Query with join with multiple data sources in AX (Inner join, not exists join)

    public void initializeQueryDS()
    {
        query = new Query();
        QueryBuildDataSource qbds;
        QueryBuildDataSource qbdsSessionLine;

        switch(routing)
        {
            case Routing::Sales:
                qbds = query.addDataSource(tableNum(SalesLine));

                qbdsSessionLine = qbds.addDataSource(tableNum(WorkbenchSessionLine));
                qbdsSessionLine.joinMode(JoinMode::NoExistsJoin);
                qbdsSessionLine.relations(true);
                qbdsSessionLine.fetchMode(QueryFetchMode::One2One);

                TblNum = tableNum(SalesLine);
                break;
            case Routing::Return:
                qbds = query.addDataSource(tableNum(SalesLine));
                TblNum = tableNum(SalesLine);
                break;
        }
    }

    public void initializeQueryRange()
    {
        if(inventLocationId != strMin())
        {  
            QueryBuildDataSource qbdsSalesLine,qbdsInventDim;

            qbdsSalesLine = query.dataSourceTable(tableNum(SalesLine));
            qbdsInventDim = qbdsSalesLine.addDataSource(tableNum(InventDim));
            qbdsInventDim.joinMode(JoinMode::InnerJoin);
            qbdsInventDim.relations(true);
            qbdsInventDim.fetchMode(QueryFetchMode::One2One);
            qbdsInventDim.addRange(fieldNum(InventDim, InventLocationId)).value(inventLocationId);
        }

        if(shipDate != dateNull())
        {
            QueryBuildDataSource qbds;

            qbds = query.dataSourceTable(tableNum(SalesLine));
            qbds.addRange(fieldNum(SalesLine, ShippingDateConfirmed)).value(SysQuery::value(shipDate));
        }

        if(dlvModeFrom.elements())
        {
            container   conMOD;
            Enumerator  enumerator  =   dlvModeFrom.getEnumerator();

            while (enumerator.moveNext())
            {
                conMOD += enumerator.current();
            }

            QueryBuildDataSource qbds;
            qbds = query.dataSourceTable(tableNum(SalesLine));

            qbds.addRange(fieldNum(SalesLine, DlvMode)).value(con2Str(conMOD));
        }

    }

    public WorkbenchSessionLine initFromCommon(Common _callerTable)
    {
        WorkbenchSessionLine line;

        switch (_callerTable.TableId)
        {
            case tableNum(SalesLine):
                line.RefRecId    = _callerTable.(fieldNum(SalesLine, RecId));
                line.RefTableId    = _callerTable.TableId;

                line.InventTransId    = _callerTable.(fieldNum(SalesLine, InventTransId));

                if(routing == Routing::Sales)
                {
                    line.ReferenceType = RefType::SalesOrder;
                }
                else if(routing == Routing::Return)
                {
                    line.ReferenceType = RefType::ReturnOrder;
                }
                break;

            default:
                break;
        }

        return line;
    }

    public void createWorkbenchSession(WorkbenchSessionContract _contract)
    {
        WorkbenchSessionTable header;
        WorkbenchSessionLine line;

        RecordInsertList lineRecordList = new RecordInsertList(tableNum(WorkbenchSessionLine), true, true, true, false, true, line);

        contract = _contract;
       
        this.initializeParameters();
        this.initializeQueryDS();
        this.initializeQueryRange();

        try
        {
            ttsbegin;

            NumberSeq numberSeq = NumberSeq::newGetNum(TMSParameters::numRefInternalSessionID());

            header.initValue();

            header.DynamicsInternalSessionID = numberSeq.num();

            numberSeq.used();

            header.SessionStatus = SessionStatus::Open;

            header.LE_ID = curExt();

            if (routing == Routing::Sales || routing == Routing::Return)
            {
                header.CombineOrders = true;
            }
           
            header.insert();

            queryRun = new QueryRun(query);

            while(queryRun.next())
            {
                Common common = queryRun.get(TblNum);

                line = this.initFromCommon(common);

                line.WorkbenchSessionTable = header.RecId;

                lineRecordList.add(line);
            }

            lineRecordList.insertDatabase();

            ttscommit;
            
            this.openWorkbenchSessionForm(header);
        }
        catch
        {

        }
    }

Thursday, April 22, 2021

How to get the number of elements in the list in AX

{ 
    List il = new List(Types::Integer); 
 
    il.addStart(1); 
    il.addStart(2); 
    il.addStart(3); 
    if (il.elements() != 3) 
    { 
        print "Something is wrong..."; 
    } 
}

Sunday, April 11, 2021

How to refresh form datasource from Class or Table in D365fo

// If this is a data source on a form, then refresh from table in AX7 / D365.
if (FormDataUtil::isFormDataSource(this))
{
	FormDataUtil::getFormDataSource(this).refresh();
}


Refresh from data source from class in AX7 / D365
Table tableBuffer;
FormDataSource formDataSource;
tableBuffer = _args.record();
formDataSource = FormDataUtil::getFormDataSource(tableBuffer);
formDataSource.research();

Refresh from data source from class in AX7 / D365 from workflow
I just wrote couple of custom workflow. But on Submit workflow, form did not refresh and available for edit until, you manually refresh the form. That behavior is certainly not acceptable by end user.

usually _args.caller().updateWorkflowControls(); will do this. Possible I missed something. But for its solution I add following code snippet for data set refresh that works for me.

dssRfpTable tableBuffer = _args.record();
FormDataSource custInvoiceTableDataSource;
custInvoiceTableDataSource = FormDataUtil::getFormDataSource(tableBuffer);

 

if (custInvoiceTableDataSource)
{
custInvoiceTableDataSource.research(true);
custInvoiceTableDataSource.refresh();
}

Monday, December 7, 2015

AX 2012 : Add Custom lookup on EP

Add Custom lookup on EP

The trick is to override datasetLookup() on Dataset > data source > field > methods. You will not find this method in the list of override methods so just create this as new method.
the table which we are using for lookup should be in the Dataset


public void dataSetLookup(SysDataSetLookup sysDataSetLookup)
{
    List list = new List(Types::String);

    Query query = new Query();

    QueryBuildDataSource    queryBuildDataSource;

    QueryBuildRange qbr;

    // Add the table to the query.

    queryBuildDataSource  = query.addDataSource(tableNum(DependentDetails));

    //add the range

    qbr = queryBuildDataSource.addRange( fieldnum(DependentDetails, PersonnelNumber));

   // qbr.value(DirPersonUser::currentWorkerPersonnelNumber());

   // qbr.status(RangeStatus::Locked);

     // Specify the fields to use for the lookup.

    list.addEnd(fieldStr(DependentDetails,DependentId));

    list.addEnd(fieldStr(DependentDetails,Name));


     sysDataSetLookup.parmLookupFields(list);

     // Specify the field that is returned from the lookup.

    sysDataSetLookup.parmSelectField('DependentId');

     // Pass the query to the SysDataSetLookup so that the query is used.

    sysDataSetLookup.parmQuery(query);
 
}

Table browser URL in D365FO

Critical Thinking icon icon by Icons8