Wednesday, 18 June 2014

AX tips

If the form opens from other form menuitem not directly from form then we have to write this code in form init method after super()


if (!element.args().caller())
    {
        throw error("@SYS22539");
    }

Un Select all coding: In click method of button:
void clicked()
{
    DNGRSSalesPaymentSettelmentLines _DNGRSSalesPaymentSettelmentLines;
    super();

   _DNGRSSalesPaymentSettelmentLines =DNGRSSalesPaymentSettelmentLines_ds.getFirst();
    while (_DNGRSSalesPaymentSettelmentLines)
    {

        if(_DNGRSSalesPaymentSettelmentLines.SelectPayment == NoYes::Yes)
        {
            _DNGRSSalesPaymentSettelmentLines.SelectPayment = NoYes::no;
        }
        _DNGRSSalesPaymentSettelmentLines.update();

        _DNGRSSalesPaymentSettelmentLines = DNGRSSalesPaymentSettelmentLines_ds.getNext();
    }
}
 Select all coding:   In click method of button:
void clicked()
{
    DNGRSSalesPaymentSettelmentLines _DNGRSSalesPaymentSettelmentLines;
    super();

   _DNGRSSalesPaymentSettelmentLines =DNGRSSalesPaymentSettelmentLines_ds.getFirst();
    while (_DNGRSSalesPaymentSettelmentLines)
    {

        if(_DNGRSSalesPaymentSettelmentLines.SelectPayment == NoYes::no)
        {
            _DNGRSSalesPaymentSettelmentLines.SelectPayment = NoYes::yes;
        }
        _DNGRSSalesPaymentSettelmentLines.update();

        _DNGRSSalesPaymentSettelmentLines = DNGRSSalesPaymentSettelmentLines_ds.getNext();
    }
}



Note : For invoice settlements we can use the  CustVendSettle class:
                CustVendSettle  - updateOtherSettlementFieldsOnTrans






Existing and new customer creation:

class DNGRSCustomertEntitiesFromReservatio
{
}



static public void main(Args args, boolean _showForm = true)
{
    smmEntityToCreate   entityCreate;
    NoYes               conversionSuccessful;
    MenuFunction        menuFunction;
    Args                argsToPass = new Args();
    smmBusRelTable      smmBusRelTable;
    DNGRSReservationTable  dngRSReservationTable;
    smmOpportunityTable    smmOpportunityTableLoc;
    CustTable              Custtable;
    ;

    if (!args || !args.dataset())
    {
        throw error("@SYS22996");
    }

    dngRSReservationTable = args.record();

    smmOpportunityTableLoc = smmOpportunityTable::findbyReservationId(dngRSReservationTable.ReservationId);

    if(!smmOpportunityTableLoc.RecId)
    {
        throw error("@DNG21273");
    }

    if (smmOpportunityTableLoc.RecId)
    {
        entityCreate = args.parmEnum();

        // from Create Customer function button
        if (entityCreate == smmEntityToCreate::Customer)
        {
            // Convert to customer
            smmBusRelTable = smmBusRelTable::findByParty(smmOpportunityTableLoc.Party);
            if (smmBusRelTable.canConvertToCustomer())
            {
                conversionSuccessful = smmBusRelTable::convert2Customer(smmBusRelTable, '', false);
            }
            if (conversionSuccessful)
            {
                Custtable = CustTable::findByPartyRecId(smmBusRelTable.Party);
                info(strfmt("New Customer %1 is created",CustTable::findByPartyRecId(smmBusRelTable.Party).AccountNum),'',SysInfoAction_TableField::newBuffer(CustTable));


                info(strfmt("%1 %2 ",dngRSReservationTable.ReservationId,dngRSReservationTable.ExistingCustomer));
                dngRSReservationTable.ExistingCustomer = CustTable::findByPartyRecId(smmBusRelTable.Party).AccountNum;
                // Open the Customer table form if configured to do so
                //if (smmParameters::getBusRelOpenCustForm())
                //{
                    //menuFunction = new MenuFunction(menuitemDisplayStr(CustTable), MenuItemType::Display);
//
                    //// Check access rights
                    //if (!menuFunction || !menuFunction.checkAccessRights())
                    //{
                        //// Access rights are not sufficient to use this function.
                        //throw error("@SYS81158");
                    //}
//
                    //argsToPass.record(smmBusRelTable);
                    //if(_showForm)
                    //{
                        //menuFunction.run(args);
                    //}
                //}
            }
        }

    }

}

Manually creation of numbersequence:
num     = NumberSeq::newGetNum(DNGRSSalesParameter::numRefRESUnitPaymentSchedule());





Adding range in execute query:
()
public void executeQuery()
{

 if(DNGRSUnitPaymentschedule.DNGRSChangeorderid == "")
   this.query().dataSourceTable(tableNum(DNGRSUnitPaymentschedule)).addRange(fieldNum(DNGRSUnitPaymentschedule,DNGRSChangeorderid)).value(queryValue(DNGRSUnitPaymentschedule.DNGRSChangeorderid));
    else
      this.query().dataSourceTable(tableNum(DNGRSUnitPaymentschedule)).addRange(fieldNum(DNGRSUnitPaymentschedule,DNGRSChangeorderid)).value(SysQuery::valueEmptyString());
       super();

}


Monday, 31 March 2014

Sending Record through email in Table format

Class:
class SendMailUsingOutlook extends RunBase
{
    Counter                             progressCounter;
    HRMApplicationEmailTemplate         hrmApplicationEmailTemplate;
    DNGRSUnitHandover                   dngrsUnitHandover;
    DNGRSWorkCompletion                 dngrsWorkCompletion;
}
Main method:
static void main(Args args)
{
    DNGRSUnitHandover              dngrsUnitHandover;
    DNGRSWorkCompletion            dngrsWorkCompletion;

    FreeTxt                        bodyText,bodytext2,Fullbody,bodytext3;
    SendMailUsingOutlook SendMailUsingOutlook = new SendMailUsingOutlook();
     if (!args)
    {
        throw error("@SYS25407");
    }
        dngrsUnitHandover = args.record();
        SendMailUsingOutlook.parmDNGRSUnitHandover(dngrsUnitHandover);
        SendMailUsingOutlook.run();
}
Parm method for getting Args:
public DNGRSUnitHandover parmDNGRSUnitHandover(DNGRSUnitHandover _DNGRSUnitHandover = dngrsUnitHandover)
{
    dngrsUnitHandover = _DNGRSUnitHandover;
    return dngrsUnitHandover;
}
Progress Update:
void progressUpdate(str text)
{
    ;
    progressCounter++;
    progress.setCount(progressCounter);
    progress.setText(text);
}





Run:
Public void run ()
{
    FreeTxt                                     bodyText,bodytext2,Fullbody,bodytext3;
    DNGRESAgreementUnitSpecification            dngresAgreementUnitSpecification;
    DNGRSWorkCompletionChangeOrderSpec          dngrsWorkCompletionChangeOrderSpec;
    DNGRSDocumentList                           DNGRSDocumentList;
    DNGRSWorkLineDetails                        DNGRSWorkLineDetails;
    DNGRSInspectionDetails                      DNGRSInspectionDetails;
    DNGRSSpecificationTable                     DNGRSSpecificationTable;
    ;
    bodyText += "<TABLE border=1 style=width:1000px cellspacing=0 cellpadding=0><font color=blue size=4.5><TH colspan = 5 bgcolor =#BDB76B>Unit specification</TH></font><TR bgcolor =#FFFFE0><TH>Major specification</TH><TH>Description</TH><TH>Inspected by</TH><TH>Status</TH><TH>Completed %</TH></TR>";
    while select dngresAgreementUnitSpecification where dngresAgreementUnitSpecification.UnitNum == dngrsUnitHandover.UnitNum
                                                        && dngresAgreementUnitSpecification.BuildingID == dngrsUnitHandover.BuildingId
        {
            bodyText += strFmt("<TR><TD bgcolor =#FFFFE0>%1</TD><TD bgcolor =#FFFFE0>%2</TD><TD bgcolor =#FFFFE0>%3</TD><TD bgcolor =#FFFFE0>%4</TD><TD bgcolor =#FFFFE0>%5</TD></TR>",dngresAgreementUnitSpecification.MajorSpecification,dngresAgreementUnitSpecification.MajorSpecDescription(),HcmWorker::find(dngresAgreementUnitSpecification.Inspectedby).name(),dngresAgreementUnitSpecification.Status,dngresAgreementUnitSpecification.CompletedPercent);
        }
    bodyText += "</TABLE>";
    bodytext2 +="<TABLE border=1 style=width:1000px cellspacing=0 cellpadding=0><font color=blue size=4.5><TH colspan = 5 bgcolor =#BDB76B>Changeorder specification</TH></font><TR bgcolor =#FFFFE0><TH>Major specification</TH><TH>Description</TH><TH>Inspected by</TH><TH>Status</TH><TH>Completed %</TH></TR>";
    while select dngrsWorkCompletionChangeOrderSpec where dngrsWorkCompletionChangeOrderSpec.UnitNum == dngrsUnitHandover.UnitNum
                                                        && dngrsWorkCompletionChangeOrderSpec.BuildingID == dngrsUnitHandover.BuildingId
        {
            bodytext2 += strFmt("<TR><TD bgcolor =#FFFFE0>%1</TD><TD bgcolor =#FFFFE0>%2</TD><TD bgcolor =#FFFFE0>%3</TD><TD bgcolor =#FFFFE0>%4</TD><TD bgcolor =#FFFFE0>%5</TD></TR>",dngrsWorkCompletionChangeOrderSpec.MajorSpecification,dngrsWorkCompletionChangeOrderSpec.MajorSpecificationDesc(),HcmWorker::find(dngresAgreementUnitSpecification.Inspectedby).name(),dngresAgreementUnitSpecification.Status,dngresAgreementUnitSpecification.CompletedPercent);
        }
    bodytext2 += "</TABLE>";
    bodyText3 += "<TABLE border=1 style=width:1000px cellspacing=0 cellpadding=0><font color=blue size=4.5><TH colspan = 5 bgcolor =#BDB76B>Document details</TH></font><TR bgcolor =#FFFFE0><TH>Document ID</TH><TH>Description</TH><TH>Inspected by</TH><TH>Status</TH><TH>Completed %</TH></TR>";
    while select DNGRSDocumentList where DNGRSDocumentList.SalesAgreementID == dngrsUnitHandover.SalesAgreementId
        {
            bodyText3 += strFmt("<TR><TD bgcolor =#FFFFE0>%1</TD><TD bgcolor =#FFFFE0>%2</TD><TD bgcolor =#FFFFE0>%3</TD><TD bgcolor =#FFFFE0>%4</TD><TD bgcolor =#FFFFE0>%5</TD></TR>",DNGRSDocumentList.DocumentID,DNGRSDocumentList.DocumentIDDescription(),HcmWorker::find(dngresAgreementUnitSpecification.Inspectedby).name(),dngresAgreementUnitSpecification.Status,dngresAgreementUnitSpecification.CompletedPercent);
        }
    bodyText3 += "</TABLE>";

    Fullbody = bodyText + "\n" + "<BR>" + bodytext2 + "\n" + "<BR>" + bodyText3;
    this.sendEmail(CustTable::find(dngrsUnitHandover.Customer).email(), CustTable::find(dngrsUnitHandover.Customer).name(), "Unit handover status", Fullbody,true);

}







Send email:
private boolean sendEmail(
Email                               _applicantEmail,
DirPartyName                        _applicantName,
HRMApplicationEmailTemplateSubject  _mailSubject,
CCMailBody                          _mailBody,
Boolean                             _previewEmail)
{
    boolean         ret;
    SmmOutlookEmail smmOutlookEmail;
    ccSysInetMail   mail;

    if(!_previewEmail)
    {
        mail = new ccSysInetMail();

        mail.sendMail(_applicantEmail, _mailSubject, _mailBody, false);
        if(!mail.mapiStatus())
        {
           info(strfmt("@SYS31964", _applicantName));
           ret = true;
        }
    }
    else
    {
        smmOutlookEmail = new SmmOutlookEmail();

        if (smmOutlookEmail.createMailItem())
        {
            smmOutlookEmail.addEMailRecipient(_applicantEmail);
            smmOutlookEmail.addSubject(_mailSubject);
            smmOutlookEmail.isHTML(true);
            smmOutlookEmail.addBodyText(_mailBody);
            smmOutlookEmail.sendEMail(smmSaveCopyOfEmail::No);
            ret = true;
        }
    }

    return ret;
}
Substitute Bookmark:
private Container substituteBookmarks(
Container                               _bookmarks,
HRMApplicationEmailTemplateSubject      _mailSubject,
CCMailBody                              _mailBody,
HRMApplication                          _hrmApplication,
HRMApplicationBookmark                  _hrmApplicationBookmark)
{
    Counter                             fieldCounter;
    str                                 tableName, fieldName;
    LabelString                         bookmark, bookmarkValue;

    for (fieldCounter=1; fieldCounter <= conlen(_bookmarks); fieldCounter++)
    {
        bookmark                    = conpeek(_bookmarks, fieldCounter);
        [tableName, fieldName]      = HrmApplicationWordBookmark::splitBookmark(bookmark);
        [bookmark, bookmarkValue]   = _hrmApplicationBookmark.bookmarkAndValue(tableName, fieldName, _hrmApplication, true);

        if (strScan(_mailSubject, bookmark, 1, strlen(_mailSubject)))
        {
            _mailSubject = strReplace(_mailSubject, bookmark, '%1');
            _mailSubject = strfmt(_mailSubject, bookmarkValue);
        }

        if (strScan(_mailBody, bookmark, 1, strlen(_mailBody)))
        {
            _mailBody = strReplace(_mailBody, bookmark, '%1');
            _mailBody = strfmt(_mailBody, bookmarkValue);
        }
    }
    return [_mailSubject, _mailBody];
}