Tuesday 30 September 2014

Activity Process(Case process steps):

Activity Process:



Step 1. Add Enum type for process with "YourProcessName" and "enum value" you will use many placess

  

1.1). In HierarchyType Enum add the bellow element with "YourProcessName" and "enum value"



1.2). In smmActigityParentType Enum add the bellow element with "YourProcessName" and "enum value"




Step 2. Create EDT

To create EDT we cannot create “Relation Node” EDT Level so just duplicate it






New EDT, here 102 is the Enum value



Step 3. Create new field in your main table and extend this EDT





Create Field Fix Relation with Hierarchy table




Step 4. Add code in tables
  
4.1). Hierarchy

    getMenuItemStr(HierarchyType _hierarchyType)
     // Sales agreement cancellation process
        case HierarchyType::DNGRSSalesCancellation :
            menuItemStr = menuitemDisplayStr(DNGRSSalesCancellationProcess);
            break;
   
    hierarchyType2fieldId(HierarchyType _hierarchyType)
     // Sales agreement cancellation process
        case HierarchyType::DNGRSSalesCancellation:
            fieldId = fieldNum(DNGRSSalesAgreementCancellationHeader, CancellationID);
            break;
   
    hierarchyType2ParentType(HierarchyType _hierarchyType)
    // Sales agreement cancellation process
       case HierarchyType::DNGRSSalesCancellation :
            parentType = smmActivityParentType::DNGRSSalesCancellation;
            break;
   
    hierarchyType2tableId(HierarchyType _hierarchyType)
    // Sales agreement cancellation process
        case HierarchyType::DNGRSSalesCancellation:
            refTableId = tableNum(DNGRSSalesAgreementCancellationHeader);
            break;
   
    isHierarchyTypeCRM(HierarchyType _hierarchyType)
     _hierarchyType == HierarchyType::DNGRSSalesCancellation ||
   
    parentType2HierarchyType(smmActivityParentType _parentType)
    case smmActivityParentType::DNGRSSalesCancellation :
            hierarchyType = HierarchyType::DNGRSSalesCancellation;
            break;
   
    tableId2hierarchyType(TableId _tableId)
    case tableNum(DNGRSSalesAgreementCancellationHeader):
           // if (isConfigurationkeyEnabled(configurationKeyNum(PublicSector)))
            {
                hierarchyType = HierarchyType::DNGRSSalesCancellation;
            }
            break;
   
4.2. smmActivities

initFromCommonUsingTemplate(Common _table, smmActivities _templateActivity)
   // added by
        case tableNum(DNGRSSalesAgreementCancellationHeader) :
            SalesAgreementCancellationHeader = _table;
            this.initFromHierarchyTemplate(_templateActivity, DateTimeUtil::date(SalesAgreementCancellationHeader.CreatedDateTime));
            parentType = smmActivityParentType::DNGRSSalesCancellation;
            break;

 
Step 5. Add code in Classes

5.1). smmActivityParentLink
   
    getLinkedTypes(smmActivityParentType _parentType)
    //added by
    case smmActivityParentType::DNGRSSalesCancellation:
         con = [smmActivityParentType::DNGRSSalesCancellation, smmActivityParentType::DNGRSSalesCancellation];
    break;
   
    getLookupFields(smmActivityParentType _smmActivityParentType)
    case smmActivityParentType::DNGRSSalesCancellation :
         fields = [fieldStr(DNGRSSalesAgreementCancellationHeader, SalesCancellationProcess)];//,
    break;
   
    parentType2FieldId(smmActivityParentType _parentType)
    //added by
    case smmActivityParentType::DNGRSSalesCancellation :
         fieldId = fieldNum(DNGRSSalesAgreementCancellationHeader,CancellationID);
    break;
    
    parentType2FieldName(smmActivityParentType _parentType)
     //added by
    case smmActivityParentType::DNGRSSalesCancellation :
         name = fieldStr(DNGRSSalesAgreementCancellationHeader,CancellationID);
    break;
   
    parentType2RefTableId(smmActivityParentType _parentType)
    //added by
    case smmActivityParentType::DNGRSSalesCancellation :
         tableId = tableNum(DNGRSSalesAgreementCancellationHeader);
    break;

   5.2). smmCreateEntity
   
    createLinkCommon(Common _common, Common _newRecord)
    case tableNum(DNGRSSalesAgreementCancellationHeader) : //by kiran as on 30-01-2014 for sales agreement activity

   
Step 6. Forms :: DNGRSSalesAgreementCancellation

Form -->Main DataSource-->Writer()
        public void write()
        {

            NoYes           newRecord;
            HierarchyName   oldProcess;
            boolean         ret;
            ;
            ttsbegin;

            newRecord = DNGRSSalesAgreementCancellationHeader.RecId ? NoYes::No : NoYes::Yes;

            oldProcess = DNGRSSalesAgreementCancellationHeader.orig().SalesCancellationProcess;

            super();


            ret = element.setProcessInstance(oldProcess, DNGRSSalesAgreementCancellationHeader.SalesCancellationProcess) ;

            if (!ret)
            {
                ttsabort;
                DNGRSSalesAgreementCancellationHeader_ds.reread();
                return;
            }

            // If called from other form and creating a new record
            if (callerRecord && newRecord)
            {
                // Copy associations for the caller record
                smmCreateEntity::createLinkCommon(callerRecord, DNGRSSalesAgreementCancellationHeader);
            }
            if (newRecord)
            {
                DirParty::showHideMessageBar(element,DNGRSSalesAgreementCancellationHeader);
            }
            ttscommit;
        }

    Form method
        public boolean setProcessInstance(HierarchyName _oldProcess, HierarchyName _newProcess)
        {
            DialogButton    answer = DialogButton::Yes;

            if (_oldProcess && _oldProcess !=_newProcess)
            {
                // Do you want to remove all open activities?
                answer = Box::yesNoCancel("@SYS109839", DialogButton::Cancel);

                if (answer == DialogButton::Cancel)
                {
                    return checkFailed("@SYS25904"); //Update has been canceled.
                }
            }

            smmProcessInstance::write(DNGRSSalesAgreementCancellationHeader, _oldProcess, _newProcess, false, answer == DialogButton::Yes);

            return true;
        }



Step 6. Create one menu item with type:: Display
Place this menu item in to setup place in area page pane
Set the properties










After that create one more action menu item :
And assign below class to that menu item




class RESSaleAgreementCancellationProcess
{
}

static public void main(Args args, boolean _showForm = true)
{
    smmProcessInstance  smmProcessInstance;
    RESSalesAgreementCancelTable   RESSalesAgreementCancelTable;
    ;
    if (!args || !args.dataset())
    {
        throw error("@SYS22996");
    }


    RESSalesAgreementCancelTable = args.record();
  //  if (smmOpportunityTable.ProcessName)
    {
        smmProcessInstance = smmProcessInstance::construct(RESSalesAgreementCancelTable);
    }

    if (_showForm)
    {
        smmProcessInstance.openForm();
    }
}

And place this menu item in to action pane tab of form (and listpage)






And one drop dialog control in the action pane tab below the above menu item
And assign the menuitem as : SmmChangeStage (it is default )




And place this menu item then form look as:



Thursday 3 July 2014

Through controller class selecting the design

public class DNGRMDashUnitStatusEachDateController extends SrsReportRunController
{
    #define.ReportName(‘DNGRMDashUnitStatusEachDateReport.DNGRMDashUnitStatusEachDateDesignPercent′)
    DNGRMDashUnitStatusEachDateContract dNGRMDashUnitStatusEachDateContract;

    boolean isPercent;
}
protected void preRunModifyContract()
{
    SrsReportDataContract dataContract = this.parmReportContract();
    SrsReportRdlDataContract contract = dataContract.parmRdlContract();
    ;

    if (!dNGRMDashUnitStatusEachDateContract)
    {
        dNGRMDashUnitStatusEachDateContract = this.parmReportContract().parmRdpContract();
    }

    isPercent = dNGRMDashUnitStatusEachDateContract.parmIsPercent();

    if(isPercent)
    {
        dataContract.parmReportName('DNGRMDashUnitStatusEachDateReport.DNGRMDashUnitStatusEachDateDesignPercent');
    }
    else
    {
        dataContract.parmReportName('DNGRMDashUnitStatusEachDateReport.DNGRMDashUnitStatusEachDateDesignNumber');
    }


    super();
}
public client static void main(Args _args)
{
    DNGRMDashUnitStatusEachDateController controller = new DNGRMDashUnitStatusEachDateController ();

    controller.parmReportName('DNGRMDashUnitStatusEachDateReport.DNGRMDashUnitStatusEachDateDesignPercent');
    controller.parmArgs(_args);
    controller.startOperation();

}

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];
}