Auto settle from custTransOpen when create journal payment lines via x++

example code :

public static void autoSettlementJournalFromPAYDetails(JournalId    _journalNum)
{
    CustVendOpenTransManager manager;
    CustTrans                custTrans;
    CustTransOpen            custTransOpen;
    LedgerJournalTrans       ledgerJournalTrans;
    AxLedgerJournalTable     axLedgerJournalTable;
    AxLedgerJournalTrans     axLedgerJournalTrans;
    ExchangeRateHelper       exchangeRateHelper;
    AmountCur                totalSettleAmount;
    AmountCur                amountCurDebit,amountCurCredit;
    HRSPayJournalDetails     hrsPayJournalDetails;
    HRSPayJournalTable       hrsPayJournalTable;
    
    int                      Row;


    AxLedgerJournalTable = AxLedgerJournalTable::newLedgerJournalTable(LedgerJournalTable::find(_journalNum));
    ttsBegin;
    //details journal lines from Pay Journal Details
    while select hrsPayJournalTable
    join hrsPayJournalDetails
    where
        hrsPayJournalTable.HRSPayJournalId == hrsPayJournalDetails.HRSPayJournalId
    &&  HRSPayJournalTable.JournalNum      == _journalNum
    {
        CustTrans    = CustTrans::findFromInvoice(hrsPayJournalDetails.ReferenceNumber,HRSPayJournalDetails.AccountNum);
        CustTransOpen  = CustTransOpen::findRefId(CustTrans.RecId);

        if(CustTransOpen)
        {

           //Create Trans ...
            axLedgerJournalTrans = new axLedgerJournalTrans();
            axLedgerJournalTrans.parmJournalNum(AxLedgerJournalTable.ledgerJournalTable().JournalNum);

            axLedgerJournalTrans.parmTransDate(today());
            axLedgerJournalTrans.parmDue(today());
            axLedgerJournalTrans.parmAccountType(LedgerJournalACType::Cust);
            axLedgerJournalTrans.parmLedgerDimension(DimensionStorage::getDynamicAccount(hrsPayJournalDetails.AccountNum, LedgerJournalACType::Cust));
            axLedgerJournalTrans.parmAmountCurCredit(hrsPayJournalDetails.Credit);
            axLedgerJournalTrans.parmAmountCurDebit(hrsPayJournalDetails.Debit);
            axLedgerJournalTrans.save();

            manager = CustVendOpenTransManager::construct(axLedgerJournalTrans.ledgerJournalTrans());
            manager.updateTransMarked(custTransOpen,true);
            if(hrsPayJournalDetails.Debit)
            {
                manager.updateSettleAmount(custTransOpen,hrsPayJournalDetails.Debit);
            }
            else
            {
                manager.updateSettleAmount(custTransOpen,hrsPayJournalDetails.Credit);
            }

            //update after settle
            ledgerJournalTrans = axLedgerJournalTrans.ledgerJournalTrans();
            ledgerJournalTrans.selectForUpdate(true);
            ledgerJournalTrans.SettleVoucher =  SettlementType::SelectedTransact;
            ledgerJournalTrans.update();
            Row++;
        }

    }
    ttsCommit;
    
    info(strFmt("Total Lines settled : %1",Row));

}

Join ItemName from (EcoResProductTranslation ) and search name from InventTable to OnHand Form for search matter

it is common for user to search item based on name. but currently on AX 2012, onHand form can’t provide search based on item name or search name. It will take a little modification from technical side.

example how to do it :

1. you can join directly on form datasource or create view like example (i’m using the view that already created for another purpose)
Capture

2. on InventSumTable add relations like this.
Capture

3. then go to form onHand (InventOnHandItem), and add the view to datasource
Capture

4. open class InventDimCtrl_Frm_OnHand and modify method modifyQuery , on class declaration parameter, add new parameter FormDataSource with default null parameter. then define new variable QueryBuildDataSource.
Capture

5. on the last line of the method modifyQuery , add code like example :

if(_tidInventLookUp)
{
    qbsInventLookup = query.dataSourceName(_tidInventLookUp.name());

    //filter current company language
    qbr = SysQuery::findOrCreateRange(qbsInventLookup, fieldnum(TIDInventLookup, LanguageId));
    qbr.value(queryValue(CompanyInfo::languageId()));

    qbsInventLookup.addGroupByField(fieldNum(TIDInventLookup,Name));
    qbsInventLookup.addGroupByField(fieldNum(TIDInventLookup,NameAlias));

}

5. then back to the form, on datasource inventSUm, on executeQuery , modify the code from

void executeQuery()
{
    element.inventDimSetupObject().modifyQuery(inventSum_DS,inventDim_DS);

    super();
}

to

void executeQuery()
{
    element.inventDimSetupObject().modifyQuery(inventSum_DS,inventDim_DS,TIDInventLookUp_ds);

    super();
}

6. drag the field from newly add datasource on form to the grid :
Capture

7. Voila done, example result, :
Capture

note: remember to GROUPBY on code if you add new field to the form, or the field on form will show “UNRETRIEVED”

Change properties form control from listPage class example code

public void initializeQuery(Query _query)
{
    // ListPageLabelChange =>
    Common              externalRecord;
    FormDataSource      frmDs;
    FormRun             formRun;
    FormControl         frmCtrl;
    // ListPageLabelChange <=
    
    _query.dataSourceTable(tableNum(HRSBenefitEntitlement)).addRange(fieldNum(HRSBenefitEntitlement,Employment)).value(SysQuery::value(HcmEmployment::findByWorkerLegalEntity(HcmWorker::userId2Worker(curUserId()),CompanyInfo::find().RecId).RecId));
    
    super(_query);
    
     // ListPageLabelChange =>
    externalRecord = this.listPage().activeRecord(_query.dataSourceTable(tableNum(HRSBenefitEntitlement)).name());//No intrisic function for form DS?
    if(externalRecord.isFormDataSource())
    {
        frmDs   = externalRecord.dataSource();
        formRun = frmDs.formRun();
        if(formRun)
        {
            frmCtrl = formRun.design().controlName(formControlStr(TIDBenefitEntitlementListPage,HRSBenefitEntitlement_Entitlement));
            if(frmCtrl)
            {
                frmCtrl.userPromptText("newName");
            }
        }
    }
    // ListPageLabelChange <=
}

clear usage data if no changes on form.

ODBC from x++ example code

public client static void processMDBData(str _StrDSN, str _StrTableName, date _DateFrom, date _DateTo)
{
    #AviFiles
    SysOperationProgress    progress = new SysOperationProgress();
    OdbcConnection          C;
    Statement               S;
    LoginProperty           LP = new LoginProperty();
    ResultSet               RS;
    HcmPersonnelNumberId    _EmplID;
    TimeHour24              _Time;
    str                     strquery,strDSN,tableName;
    Date                    _Date;
    int                     Idx;
    HRSTMAttendanceTemp     attDataTemp;

    ;

    try
    {   
        strDSN    = _StrDSN;
        tableName = _StrTableName;

        ttsbegin;
        LP.setDSN(_strDSN);
        LP.setServer("S-AOS1TEST");

        C   = new OdbcConnection(LP);
        S   = C.createStatement();


        strquery    = strFmt("SELECT * FROM %1 where dateLog >= #%2# AND dateLog <= #%3#",tableName,_DateFrom,_DateTo);
        RS  = S.executeQuery(strquery);
        while (RS.next())
        {
            //Progress.incCount();
            _EmplID = Rs.getString(1);
            _Date   = RS.getDate(2);
            _Time   = str2time(RS.getString(3));
            Idx     = str2int(rs.getString(4));
            
            //insert to temp table
            if(_EmplID == '') continue;
            select forupdate attDataTemp
            where attDataTemp.PersonnelNumber == _EmplID && attDataTemp.Time == _Time
                                  && attDataTemp.TransDate == _Date;
            if(!attDataTemp)
            {
                attDataTemp.clear();
                attDataTemp.PersonnelNumber      = _EmplID;
                attDataTemp.Time        = _Time;
                attDataTemp.TransDate   = _Date;
                attDataTemp.Idx         = Idx;
                attDataTemp.insert();
            }
            else
            {
                attDataTemp.Idx         = Idx;
                attDataTemp.ClockId     = '';
                attDataTemp.update();
            }

            Progress.setText(strfmt("Upload Id %1 - %2 %3", _EmplID, _date, time2str(_time, 1, 1)));
        }
        ttsCommit;

   }
   catch
   {
       ttsAbort;
       return;
   }
}

example code on custom class ApprovalResubmitActionMgr

example code :

public static void main(Args _args)
{
    recID                           recID               = _args.record().RecId;
    tableId                         tableId             = _args.record().TableId;
    HcmEmploymentLeave              HcmEmploymentLeave  = _args.record();
    WorkflowWorkItemTable           workItem            = _args.caller().getActiveWorkflowWorkItem();
    str                             menuItemName        = _args.menuItemName();
    WorkflowWorkItemActionDialog    workflowWorkItemActionDialog;
    WorkflowSubmitDialog            workflowSubmitDialog;
     
    Debug::assert(tableId == tablenum(HcmEmploymentLeave));
    Debug::assert(recId != 0);

    // The method has not been called correctly.
    if (tableId != tablenum(HcmEmploymentLeave) ||
        recId == 0)
    {
        throw error(strfmt("@SYS19306", funcname()));
    }

    // The journal has an active workflow.
    if (workItem.RecId > 0)
    {
        try
        {
            // The journal does support workflow approvals.
            workflowWorkItemActionDialog = WorkflowWorkItemActionDialog::construct( workItem,
                                                                                    WorkflowWorkItemActionType::Resubmit,
                                                                                    new MenuFunction(_args.menuItemName(),_args.menuItemType()));
            workflowWorkItemActionDialog.run();
            if (workflowWorkItemActionDialog.parmIsClosedOK())
            {

                workItem    = _args.caller().getActiveWorkflowWorkItem();
                WorkflowWorkItemActionManager::dispatchWorkItemAction(  workItem,
                                                                    workflowWorkItemActionDialog.parmWorkflowComment(),
                                                                    workflowWorkItemActionDialog.parmTargetUser(),
                                                                    WorkflowWorkItemActionType::Resubmit,
                                                                    _args.menuItemName(),
                                                                    false);
              
            }
        }

        catch(Exception::Error)
        {
            throw error(strfmt("Leave %1 can't be submitted", HcmEmploymentLeave.HRSLeaveReqId));
        }
    }
    // Make the form refresh its common workflow UI controls.
    _args.caller().updateWorkflowControls();
}

error : Errors in the high-level relational engine. A connection could not be made to the data source with the of ”,

i found this error when i tried deploying cube via ax wizard.
Capture

how to fixed error :
1. Just run the analysis service as admin domain or user domain that have the right priveleges. Set it up on SQL Server Management Configuration.
Capture3

2. Then redeploy the cube :
Capture2

related source :
1. https://msdn.microsoft.com/en-us/ms345578.aspx
2. https://technet.microsoft.com/en-us/library/cc197365%28v=office.12%29.aspx

error : Data or calculated fields with type ‘Record’ are not supported. EP AX 2012

found error : Data or calculated fields with type ‘Record’ are not supported when open custom page on Enterprise Portal.

the reason behind is because the DISPLAY method on table datasource or related table on AX is returning record.

example the error cause :
Capture

get Standard Cost Price Item Based on Activation date and InventSiteId

public static Price TIDgetSTDCostItemPrice(ItemId _itemId,TransDate _activationDate,InventSiteId _inventSiteId)
{
    InventDim       InventDimLoc;
    InventItemPrice inventItemPriceLoc;
    
    InventDimLoc.clear();
    InventDimLoc.InventSiteId = _inventSiteId;
    InventDimLoc = InventDim::findOrCreate(InventDimLoc);
    
    inventItemPriceLoc = InventItemPrice::findCurrent(_itemId,CostingVersionPriceType::Cost,InventDimLoc.inventDimId,
                                                      _activationDate,_inventSiteId,InventItemCostingType::Standard);
    
    return inventItemPriceLoc.Price;
}

send email via x++ example code

static boolean sendEmail(str toAddress, str theSubject, str body, str fromAddress)
{
    SysEmailParameters parameters = SysEmailParameters::find();

    System.Net.Mail.SmtpClient            mailClient;
    System.Net.Mail.MailMessage           mailMessage;
    System.Net.Mail.MailAddress           mailFrom;
    System.Net.Mail.MailAddress           mailTo;
    System.Net.Mail.MailAddressCollection mailToCollection;
    System.Net.Mail.MailAddressCollection mailCCCollection;
    System.Net.Mail.AttachmentCollection  mailAttachementCollection;
    System.Net.Mail.Attachment            mailAttachment;
    System.Net.NetworkCredential          mailCredentials;

    System.Exception                      e;
    List            toList;
    ListEnumerator  le;


    SMTPRelayServerName mailServer;
    SMTPPortNumber mailPortNumber;
    SMTPUserName mailUserName;
    SMTPPassword mailPassword;

    InteropPermission interopPermission;
    ;

    try
    {
        interopPermission = new InteropPermission(InteropKind::ComInterop);
        interopPermission.assert();

        if (parameters.SMTPRelayServerName)
        {
            mailServer = parameters.SMTPRelayServerName;
        }
        else
        {
            mailServer = parameters.SMTPServerIPAddress;
        }

        mailPortNumber  = parameters.SMTPPortNumber;
        mailUserName    = parameters.SMTPUserName;
        mailPassword    = SysEmailParameters::password();
        mailCredentials = new System.Net.NetworkCredential(mailUserName,mailPassword);


        mailClient = new System.Net.Mail.SmtpClient(mailServer, mailPortNumber);
        mailFrom = new System.Net.Mail.MailAddress(parameters.SMTPUserName); //fromAddress);

        toList = strSplit(toAddress,';');
        le = toList.getEnumerator();
        le.moveNext();

        mailTo  = new System.Net.Mail.MailAddress(strLTrim(strRTrim(le.current())));
        mailMessage = new System.Net.Mail.MailMessage(mailFrom, mailTo);

        mailToCollection = mailMessage.get_To();
        while(le.moveNext())
        {
            mailToCollection.Add(strLTrim(strRTrim(le.current())));
        }


        mailMessage.set_From(mailFrom);
        mailMessage.set_ReplyTo(mailFrom);
        mailMessage.set_Priority(System.Net.Mail.MailPriority::High);
        mailMessage.set_Subject(theSubject);
        mailMessage.set_IsBodyHtml(true);
        mailMessage.set_Body(body);

        if(parameters.TIDUsingSSLorTSL)
        {
            mailClient.set_EnableSsl(true);
            mailClient.set_UseDefaultCredentials(false);
            mailClient.set_Credentials(mailCredentials);
        }
        else
        {
            mailClient.set_EnableSsl(false);
        }


        mailClient.Send(mailMessage);

        mailMessage.Dispose();

        CodeAccessPermission::revertAssert();

        //info("Email has been send.");
    }
    catch (Exception::CLRError)
    {
        e = ClrInterop::getLastException();
        while (e)
        {
            info(e.get_Message());
            e = e.get_InnerException();
        }
        CodeAccessPermission::revertAssert();
        return false;
    }
}

source : my senior’s code