Saturday, 18 February 2017

Create custom service customer details

create  custom service  customer  details  


[DataContractAttribute]

class AIFCustomerSContract

   str     accountNum;
    str     custGroup;
    str     currency;
    str     segmentId;
    str     subsegmentId;
    str     paymMode;
    str     deliveryMode;
    str     dlvTerm;
    str     PaymTerm;


[DataMemberAttribute('accountNum')]
public str accountNum(str _accountNum = accountNum)
{
    accountNum  = _accountNum;
    return  accountNum;
}


[DataMemberAttribute('Name')]
public str Name(str _Name = Name)
{
    Name  = _Name;
    return  Name;
}


[DataMemberAttribute('paymMode')]
public str paymMode(str _paymMode =paymMode)
{
    paymMode  = _paymMode;
    return  paymMode;
}


class AIFCustomerSService
{
}


AIF Customer services





[SysEntryPointAttribute(true), AifCollectionTypeAttribute('_cust',Types::Class)]
public void CreateAndUpDateCustomers(AIFCustomerSContract _cust)
{

    CustTable                   custTable;
    str                         ErrorMessage;
    DirParty                    dirParty;
    DirPartyTable               dirPartyTable;
    DirPerson                   dirperson;
    DirPersonName               dirPersonName;
    DirPartyType                partyType;


    ErrorMessage = this.ValidateCustomer(_cust);
    if(ErrorMessage != "")
    {
        throw Error(strFmtLB(ErrorMessage));
    }

    try
            changeCompany (_cust.Company())
    {
            ttsBegin;
            custTable = CustTable::find(_cust.AccountNum(), true);
            if(!custTable.RecId)  //If CustAccount is not existing the initialize
            {
                custTable.initValue();
                custTable.AccountNum            = _cust.AccountNum();
                custTable.CustGroup             = _cust.CustGroup();
                custTable.Currency              = _cust.Currency();
                custTable.PaymTermId            = _cust.PaymTerm();
                custTable.PaymMode              = _cust.PaymMode();
                custTable.PaymTermId            = _cust.PaymTerm();
                custTable.PaymMode              = _cust.PaymMode();
                custTable.SegmentId             = _cust.segmentId();
                custTable.SubsegmentId          = _cust.subsegmentId();
                custTable.dlvTerm               = _cust.dlvTerm();
                custTable.DlvMode               = _cust.DlvMode();
                custTable.LineOfBusinessId      = _cust.LineOfBusinessId();
                custTable.IdentificationNumber  = _cust.identificationNumber();
                dirParty = DirParty::constructFromCommon(custTable);
                custTable.IsIntegration     = NoYes::Yes;
                custTable.insert(_cust.PartyType(), _cust.Name());
            }
            else // For Updating existing Customer
            {
                custTable.CustGroup             = _cust.CustGroup();
                custTable.Currency              = _cust.Currency();
                custTable.PaymTermId            = _cust.PaymTerm();
                custTable.PaymMode              = _cust.PaymMode();
                custTable.PaymTermId            = _cust.PaymTerm();
                custTable.PaymMode              = _cust.PaymMode();
                custTable.SegmentId             = _cust.segmentId();
                custTable.SubsegmentId          = _cust.subsegmentId();
                custTable.dlvTerm               = _cust.dlvTerm();
                custTable.DlvMode               = _cust.DlvMode();
                custTable.LineOfBusinessId      = _cust.LineOfBusinessId();
                custTable.IdentificationNumber  = _cust.identificationNumber();
                custTable.update();
            }

            // fill Names
            if(!custTable.Party)
            {
              custTable.Party         = DirPartyTable::createNew(_cust.PartyType(), _cust.Name()).RecId;
            }

            dirPartyTable = DirPartyTable::findRec(custTable.Party, true, _cust.PartyType());
            // For Updating Person Name if the Party Type is Person.
            if (dirPartyTable.RecId && _cust.PartyType() == DirPartyType::Organization)
            {
                dirPartyTable.Name      = _cust.Name();
                dirPartyTable.NameAlias = _cust.Name();
                dirPartyTable.update();
            }
            // For Updating Person Name if the Party Type is Person.
            else if (dirPartyTable.RecId && _cust.PartyType() == DirPartyType::Person)
            {
                dirPerson = DirPerson::find(dirPartyTable.RecId,true);
                dirPerson.Name = _cust.Name();
                dirPerson.NameAlias = _cust.Name();
                dirPerson.update();

                //Update Person Name individually
                dirPersonName =  DirPersonName::find(dirPerson.RecId,true);
                [dirPersonName.FirstName, dirPersonName.MiddleName, dirPersonName.LastName] = DirPerson::splitNameParts(_cust.Name());
                dirPersonName.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
                dirPersonName.ValidFrom = DirUtility::getCurrentDateTime();
                dirPersonName.ValidTo = DateTimeUtil::maxValue();
                if (dirPersonName.validateWrite())
                {
                    dirPersonName.update();
                }
            }
        // calling  for  Customers Address
            this.CustomerAddress(_cust);

            ttsCommit;

    }
    catch (Exception::Error)
    {
        ttsAbort;
        throw Exception::Error;
    }
 }



customer address details



[SysEntryPointAttribute(true), AifCollectionTypeAttribute('_cust',Types::Class)]
public void CustomerAddress(AIFCustomerSContract _cust)
{
        CustTable                   custTable;
        NumberSeq                   numberSeq;
        str                         ErrorMessage;
        DirParty                    dirParty;
        DirPartyPostalAddressView   dirPartyPostalAddressView;
        DirPartyContactInfoView     dirPartyContactInfo;
        DirPartyTable               dirPartyTable;


             try
         {
             ttsBegin;
            custTable = CustTable::find(_cust.AccountNum(), true);
            if(!custTable.RecId)
            {
                custTable.initValue();
            }

            dirParty = DirParty::constructFromCommon(custTable);
             // Fill address
            select dirPartyPostalAddressView
            where  dirPartyPostalAddressView.IsPrimary   == NoYes::Yes
                && dirPartyPostalAddressView.CountryRegionId == _cust.CountryCode()
                && dirPartyPostalAddressView.Party == custTable.Party;


            dirPartyPostalAddressView.LocationName      = _cust.Name();
            dirPartyPostalAddressView.City              = _cust.City();
            dirPartyPostalAddressView.Street            = _cust.Street();
            dirPartyPostalAddressView.StreetNumber      = _cust.StreetNumber();
            dirPartyPostalAddressView.CountryRegionId   = _cust.CountryCode();
            dirPartyPostalAddressView.Party             = custTable.Party;

            dirParty.createOrUpdatePostalAddress(dirPartyPostalAddressView);

            // Fill Phone Number
            dirPartyContactInfo.clear();
              select dirPartyContactInfo
            where dirPartyContactInfo.IsPrimary       == NoYes::Yes
                && dirPartyContactInfo.Type            == LogisticsElectronicAddressMethodType::Phone
                && dirPartyContactInfo.Party == custTable.Party;

            dirPartyContactInfo.LocationName    =_cust.Name();
            dirPartyContactInfo.Locator         =_cust.Phone();
            dirPartyContactInfo.Type            = LogisticsElectronicAddressMethodType::Phone;
            dirPartyContactInfo.IsPrimary       = NoYes::Yes;
            dirPartyContactInfo.Party             =custTable.Party;
            // Fill Contacts
            dirParty.createOrUpdateContactInfo(dirPartyContactInfo);

            //Fill EmailId
            dirPartyContactInfo.clear();
            select dirPartyContactInfo
            where dirPartyContactInfo.IsPrimary == NoYes::Yes
                && dirPartyContactInfo.Type     == LogisticsElectronicAddressMethodType::Email
                && dirPartyContactInfo.Party    == custTable.Party
                ;
            dirPartyContactInfo.LocationName    = _cust.Name();
            dirPartyContactInfo.Locator         = _cust.Email();
            dirPartyContactInfo.Type            = LogisticsElectronicAddressMethodType::Email;
            dirPartyContactInfo.IsPrimary       = NoYes::Yes;
            dirPartyContactInfo.Party           = custTable.Party;
            dirParty.createOrUpdateContactInfo(dirPartyContactInfo);
            // Marks the end of transaction.
            ttsCommit;

     }
    catch (Exception::Error)
    {
        ttsAbort;
        throw Exception::Error;
    }


}




Validate Customer

private str ValidateCustomer(AIFCustomerSContract _cust)
{

       boolean valid = true;

    str Message = "";
    if(_cust.Phone() == "")
    {
        Message = Message + "Phone number is required!\n";
        valid = false;
    }
    if(_cust.Name() == "")
    {
        Message = Message + "Name  is required!\n";
        valid = false;
    }

    if(_cust.AccountNum() == "")
    {
        Message = Message + "AccountNum  is required!\n";
        valid = false;
    }

    if(_cust.Email() == "")
    {
        Message = Message + "EmailID  is required!\n";
        valid = false;
    }

    if(_cust.CountryCode() == "")
    {
        Message = Message + "CountryCode  is required!\n";
        valid = false;
    }

    //if(!CustGroup::exist(_cust.CustGroup()))
    //{
        //Message = Message + "Customer group does not exits!\n";
        //valid = false;
    //}

    if(_cust.PartyType() == DirPartyType::None )
    {
        Message = Message + "Party Type is required!\n";
        valid = false;
    }
    return Message;
}




Calling   for job


static void  job_CustomerInsertAndUpdate(Args _args)
{


    AIFCustomerSContract      _AIFCustomerSContract = new AIFCustomerSContract();
    AIFCustomerSService _AIFCustomerSService = new AIFCustomerSService();

    _AIFCustomerSContract.AccountNum("");
    _AIFCustomerSContract.Currency("");
    _AIFCustomerSContract.CustGroup("");
    _AIFCustomerSContract.segmentId("");
    _AIFCustomerSContract.subsegmentId("");
    _AIFCustomerSContract.paymMode("");
    _AIFCustomerSContract.PaymTerm("");
    _AIFCustomerSContract.dlvTerm("");
    _AIFCustomerSContract.DlvMode("");
    _AIFCustomerSContract.lineOfBusinessId('');
    _AIFCustomerSContract.identificationNumber('');

    _AIFCustomerSContract.Name("");

    _AIFCustomerSContract.CountryCode('');
    _AIFCustomerSContract.CountryRegionId('');
    _AIFCustomerSContract.Street('');
    _AIFCustomerSContract.City('');
    _AIFCustomerSContract.Phone("");
    _AIFCustomerSContract.ZipCode("");
    _AIFCustomerSContract.Email('');
    _AIFCustomerSContract.Company("");
    _AIFCustomerSContract.PartyType(DirPartyType::Person);



    _AIFCustomerSService.CreateAndUpDateCustomers(_AIFCustomerSContract);


    info(_AIFCustomerSContract.AccountNum());





}






Friday, 21 October 2016

Form _Splitters

Form _Splitters

Example : Tutorial_from_split





Create a new form by name - pramod_Splitters

Add a new static text control  and add a new string control

set autodeclarations for both controls to Yes

Drag and drop the group control from the tutorial_form_split to the newly created form in
 between the static
 text and string edit controls

In the class declaration

public class FormRun extends ObjectRun
{
    SysFormSplitter_Y _formSplitter;
}

override init() method of the element and instantiate the sysFormSplitter_y class object

public void init()
{
    super();

     _formSplitter = new SysFormSplitter_Y(groupSplitter,StaticText,element);
}

Three important methods on the group control which will help to resize the splitters are mouseup, mousemove, mousedown

int mouseUp(int x, int y, int button, boolean ctrl, boolean shift)
{
    int ret;

    ret = super(x, y, button, ctrl, shift);

    Return _formSplitter.mouseUp(x, y, button, ctrl, shift);
}

int mouseMove(int x, int y, int button, boolean ctrl, boolean shift)
{
    int ret;

    ret = super(x, y, button, ctrl, shift);

    Return _formSplitter.mouseMove(x,y,button,ctrl,shift);
}

int mouseDown(int x, int y, int button, boolean ctrl, boolean shift)
{
    int ret;

    ret = super(x, y, button, ctrl, shift);

    Return _formSplitter.mouseDown(x, y, button, ctrl, shift);
}






Saturday, 1 October 2016

Insert method, Update method and delete method

static void insert(Args _args)
{
    //LopTable        lopTable;
    //lopTable.Age = 12;
    //lopTable.Name ="pramod";
    //lopTable.Sid = "1001";
    //lopTable.insert();
    //{
        //info("all record  insered");
    //}
   // temTable.setTmp();
 
   
    LopTable            lopTable;
    ;
   
    //
    //ttsBegin;
       //update_recordSet lopTable setting Sid="10";
    //
    //
    //
    //lopTable.Sid ="151";
    //lopTable.update();
    //ttsCommit;
    //
    //{
        //info(strFmt("All record updated"));
    //}
   
   
    //ttsBegin;
    //
    //select  forUpdate lopTable where lopTable.Sid;
    //
    //lopTable.Sid = "160";
    //lopTable.update();
    //ttsCommit;
   
    ttsBegin;
    delete_from lopTable
   
    where lopTable.Sid =="160";
    ttsCommit;
   
    {
        info(strFmt("%1",lopTable.Sid));
    }
   
   
}

Friday, 23 September 2016

Run base batch framework SendmailBatch

 Run base batch framework SendmailBatch

//Class Declaration the  class should Extend RunBaseBatch

class sendmailBatch extends RunBaseBatch
{
    Name                name;
    DialogField         dialogfield;

    #define.CurrentVersion(1)
    #define.CurrentList(1)
    #define.Version(1)
    #define.ImageSysTestProjcet(1)
    #define.MainBalance(1)
    #localmacro.CurrentList
   


        MainBalance
    #endmacro

}

the method must be overloaded in situations where a class must be selectable for a batchJournal

public boolean conGoBatchJournal()
{
    return true;
}


This  is used to populate/add the fields to Dialog

public  Object dialog()
{
    DialogRunbase    dialog =super();
    #resAppl

    dialog.addImage(#ImageSysTestProjcet);
    //dialogfield = dialog.addFieldValue(extendedTypeStr(name),MainBalance);


    return dialog;
}


This  will get the  Values form the  dialog a used to populate into Fields


public boolean GetfromDialog()
{
    mainBalance = dialogfield.value();

    return super();

}

This is  used to initialize any  variables


public  boolean init()
{
    return true;
}

Constructer

protected void new()
{
    super();
}


public container pack()
{


    return [#currentVersion,#CurrentList];
}


public void Run()
{
    SysMailer  sysmailer;
    EmployeeTable       employeeTable;
    QueryRun                qr;

    str                 mailMessage;

    InteropPermission permission = new InteropPermission(InteropKind::ComInterop);
    permission.assert();
    try
    {
        sysmailer = new SysMailer();
        employeeTable = qr.getNo(1);

        while select  employeeTable where employeeTable.Name>= name
        {
            mailMessage =strFmt("Dear Customer, your balancein in the is%1.please call us for further query",
            employeeTable.Age);

            //sysmailer.quickSend("",
            //employeeTable.Age,"Account Age",
            //mailMessage);
            //
            info("notification Mail sent");
        }
    }
    //{
        catch(Exception::Error)
        {
            info("Error due to maill configuration.chcek and run again");
        }

    }



public boolean validate(Object _CalledFrom = null)
{

    //if(name <=0)

    return checkFailed("Error!invaild value in minimun balance field");

    return true;
}

static ClassDescription Description()
{
    return "send mail Batch";
}



server static sendmailBatch construct()
{
    return new sendmailBatch();
}


static void Main(Args args)
{
    sendmailBatch       sendmailBatch;
    sendmailBatch = sendmailBatch::construct();
    if(sendmailBatch.prompt())
        sendmailBatch.run();

}





Monday, 20 April 2015

Date functions in ax 2012

Date functions in ax 2012


/ TransDate  d;
    
     OR

      date d;
    ;
     d=today();
      
    info(strFmt("date - %1",d));
    //Gets the month for the given date...
    info(strFmt("month  %1",mthOfYr(d)));
    
    //Gets the month name form the give data....
    info(strFmt("month Name %1",mthName(mthOfYr(d))));
   // Gets the day for the give  date...       
    info(strFmt("day %1",dayOfMth(d)));
     //Gets the day name from the given date...
     info(strFmt("Day Name %1",dayName(dayOfMth(d))));
    // //Gets the year for the given date...
    info(strFmt("year -%1",Year(d)));
    //gets the Current weekend number from the Date....
    info(strFmt("weekday number - %1",dayOfWk(d)));
    //gets the  day of  the  year  form  the give date...
    info(strFmt("Day  of year - %1",dayOfYr(d)));
    // gets the  week of the  year  form the give data...
    info(strFmt("Week of  the year - %1 ",wkOfYr(d)));

Wednesday, 8 April 2015

Filter record through code

Filter record through code

1 Create table,

2  Create form  add to data Source

public void executeQuery()
{

    QueryBuildRange Qbr;
    ;
    // str name;
   
   
   


     Qbr = this.query().dataSourceTable(tableNum(TeskTable)).addRange(fieldNum(TeskTable,Name));

    Qbr.value(queryValue(name.text()));
 
   super();
}



  3  add to    TextBox   Call  Execute Query   modified Method

StringEitd   wrtie  code

public boolean modified()
{
    boolean ret;

    ret = super();
   
    TeskTable_ds.executeQuery();
   
    return ret;
}