Thursday, February 5, 2015

To create a new employee.

As you could see in the client, the basic there are only five basic fields to create a new employee and the rest would be filled in thee next page,

Using this code snippet you could create those basic fields and hence a new employee would be created.

    CompanyInfo                             companyInfo;
    HcmEmploymentRecId                      newEmploymentRecId;
    ValidFromDateTime                       employmentStartDateTime;
    ValidToDateTime                         employmentEndDateTime;
    HcmWorker                               newHcmWorker;
    DirPerson                               dirPerson;
    DirPersonName                           dirPersonName;
    HcmEmploymentType                       hcmEmploymentType = HcmEmploymentType::Employee;
    NumberSeq                               numberSeqPersonnelNum;
    HcmPersonPrivateDetails                 HcmPersonPrivateDetails;
    //HcmEmployment                           hcmEmployment;
    HcmEmploymentType                         hcmEmployment;
    HcmWorkerTitle  hcmWorkerTitle;

    DirParty                        dirparty;
    DirPartyContactInfoView         contactView;
    HcmPersonDetails                persondetails;
    HcmPersonIdentificationNumber   hcmPersonIdentificationNumber;
 
    utcdatetime                     _validFrom = DateTimeUtil::utcNow();

    Struct              struct;
    container           ledgerDimension;
    DimensionDefault    DimensionDefault;
    int                 k;


    TransDate       HireDate,DOB;
    HcmPersonID     Employeecode;
    str             FirstName,Title,MobilePhone,email,MaritalStatus,NationalityCode,NationalityName,PaymentMode,MiddleName,LastName;

    str             DepartmentCode,DepartmentName,SubDivisionCode,SubDivisionName,DivisionCode,DivisionName ,SectorCode, SectorName;
    str             DesignationCode,DesignationName,SponsorCode,SponsorDesc,MOLNo,PASSPORTNUMBER,Gender,BloodGroup,ReligionCategory,EmployeeCategory,Emiratization;
    ;
    Employeecode    = "0005292";  
    FirstName       = "Aravind";
    MiddleName      = "";
    LastName        = "Swamy";
companyInfo = companyInfo::find();

    newHcmWorker = HcmWorker::findByPersonnelNumber(Employeecode);

    if(! newHcmWorker)
    {
        employmentStartDateTime = datetobeginUtcDateTime(HireDate, DateTimeUtil::getUserPreferredTimeZone());
        employmentEndDateTime   = DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::maxValue(), DateTimeUtil::getUserPreferredTimeZone());

        dirPersonName.FirstName     = FirstName;
        dirPersonName.MiddleName    = Middlename;
        dirPersonName.LastName      = LastName;
        newHcmWorker = HcmWorker::find(HcmWorkerTransition::newCreateHcmWorker(dirPersonName
                                                                               , Employeecode
                                                                               , companyInfo.RecId
                                                                               , hcmEmploymentType
                                                                               , employmentStartDateTime
                                                                               , employmentEndDateTime));
    }
    else
    {

        dirPersonName               = DirPersonName::find(newHcmWorker.Person,true);
        dirPersonName.FirstName     = FirstName;
        dirPersonName.MiddleName    = Middlename;
        dirPersonName.LastName      = LastName;
        dirPersonName.update();
    }

Tuesday, February 3, 2015

Validation For contract parameter value at run time in ax 2012

// Validate Method For contract parameter value at run time in ax 2012

class ClassName implements SysOperationValidatable
{
    TransDate   fromdate;
    TransDate   ToDate;
}

public boolean validate()
{
    boolean             condition = true;

    if (!fromdate)
    {
        condition = checkFailed("From Date should be entered");
    }

    if (!ToDate)
    {
        condition = checkFailed("To Date should be entered");
    }

    if (condition && (fromDate > ToDate))
    {
        condition = checkFailed(strfmt("From Date should be less than or equal to To Date", date2StrUsr(fromDate, DateFlags::FormatAll), date2StrUsr(toDate, DateFlags::FormatAll)));
    }

    return condition;
}

Currency Converter through x++

// Currency Converter through x++

static void CurrencyConverter(Args _args)
{
    CurrencyExchangeHelper currencyExchangeHelper;
    CurrencyCode transCurrency = 'SAR';
    AmountCur amountCur = 500.00;
    AmountMst amountMST,amount;

    currencyExchangeHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::current(),01\01\2014);
    amountMST = currencyExchangeHelper.calculateTransactionToAccounting(transCurrency, amountCur ,true);
    amount = currencyExchangeHelper.calculateCurrencyToCurrency("USD" ,transCurrency,amountCur,true);
    info(strFmt("%1",amountMST));
    info(strFmt("%1",amount));
 
    //ExchangeRateHelper  excRateHelper;
    //TransDate           todate = mkDate(01,12,2006);
    //CurrencyCode        transactionCur = "EUR";
    //CurrencyExchangeRate    exchangeRate;
    //;
    //excRateHelper = ExchangeRateHelper::newExchangeDate(Ledger::current(),transactionCur,todate);
    //exchangeRate = excRateHelper.getExchangeRate1();
    //info(num2str(exchangeRate/100,2,2,1,1));
}

Upload data from Excel in D365FO X++

 Action Menu Item: SAN_UploadExcelData Object type: Class Object: <Controller class name> Label: <> Class: Controller class clas...