|
public class
ImportHRData extends RunBase
{
CommaIo csvFile;
Filename filename;
DialogField dialogFilename;
boolean ret;
FirstName firstname,lastname;
DirPersonName dirPersonNameLoc;
HcmWorker hcmWorker;
#define.CurrentVersion(2)
#localmacro.CurrentList
filename,
insertIncorrectRecords,
#endmacro
#localmacro.ListVersion1
filename,
insertIncorrectRecords
#endmacro
#File
}
|
|
private void
hrCreate(container _createcon)
{
CompanyInfo companyInfo;
HcmWorker newHcmWorker;
DirPersonName dirPersonName;
HcmEmploymentRecId newEmploymentRecId;
utcDateTime hiredate,termination,lastdateworked,employmentEndDate;
str job;
OMOperatingUnitNumber businessunit,department;
HcmEmploymentType hcmEmploymentType;
HcmPosition hcmPosition;
HcmPositionDetail hcmPositionDetail;
HcmPositionWorkerAssignment hcmPositionWorkerAssignment;
HcmPositionDuration hcmPositionDuration;
RetailStaffTable retailStaffTable;
NoYes blockPosLogin;
DimensionAttributeValueSetStorage valueSetStorage = new DimensionAttributeValueSetStorage();
DimensionDefault result;
DimensionAttribute dimensionAttribute;
DimensionAttributeValue dimensionAttributeValue;
HcmJob hcmjob;
HcmEmployment hcmEmployment;
HcmEmploymentDetail hcmEmploymentDetail,nwhcmEmploymentDetail;
NumberSeq numberSeq;
companyInfo = companyInfo::find();
hiredate = DateTimeUtil::newDateTime(str2date(conpeek(_createcon,
1),213),0);
firstname = conpeek(_createcon,
2);
lastname = conpeek(_createcon,
3);
hcmEmploymentType =
str2enum(hcmEmploymentType,conpeek(_createcon, 4));
termination = DateTimeUtil::newDateTime(str2date(conpeek(_createcon,
5),213),0);
lastdateworked = DateTimeUtil::newDateTime(str2date(conpeek(_createcon,
6),213),0);
employmentEndDate =
DateTimeUtil::newDateTime(str2date(conpeek(_createcon, 7),213),0);
blockPosLogin = str2enum(blockPosLogin,conPeek(_createcon,8));
job = conPeek(_createcon,9);
businessunit = conPeek(_createcon,10);
department = conPeek(_createcon,11);
if(!employmentEndDate)
employmentEndDate = DateTimeUtil::maxValue();
dirPersonName.FirstName = firstname;
dirPersonName.LastName = lastname;
//Insert New
Woker
newHcmWorker = HcmWorker::find(HcmWorkerTransition::newCreateHcmWorker(dirPersonName
, firstname
, companyInfo.RecId
,
hcmEmploymentType
, hiredate
, employmentEndDate));
if
(newHcmWorker.RecId == 0)
{
ret = false;
}
if(newHcmWorker.RecId
== 0)
{
//
Insert Active Employment for the worker is no active employment for the
worker
newEmploymentRecId =
HcmWorkerTransition::newCreateHcmEmployment(newHcmWorker.RecId,
companyInfo.RecId,
hcmEmploymentType,
hiredate, employmentEndDate);
if
(newEmploymentRecId == 0)
{
ret = false;
}
}
//Set
Dimension value
dimensionAttribute =
dimensionAttribute::findByName("@SYS343395");
dimensionAttributeValue =
dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,businessunit,false,true);
valueSetStorage.addItem(dimensionAttributeValue);
dimensionAttribute =
dimensionAttribute::findByName("@SYS181623");
dimensionAttributeValue =
dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,department,false,true);
valueSetStorage.addItem(dimensionAttributeValue);
result = valueSetStorage.save();
hcmEmployment =
hcmEmployment::getActiveEmploymentsByWorker(newHcmWorker.RecId,
hiredate, employmentEndDate, true);
if(hcmEmployment)
{
hcmEmployment.DefaultDimension =
result;
hcmEmployment.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
hcmEmployment.update();
//Insert
HcmEmploymentDetail
select
* from hcmEmploymentDetail order by
RecId desc
where
hcmEmploymentDetail.Employment
== hcmEmployment.RecId;
if(hcmEmploymentDetail)
{
hcmEmploymentDetail.selectForUpdate(true);
ttsBegin;
hcmEmploymentDetail.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
hcmEmploymentDetail.ValidTo = DateTimeUtil::utcNow();
hcmEmploymentDetail.update();
ttsCommit;
}
nwhcmEmploymentDetail.Employment =
hcmEmployment.RecId;
nwhcmEmploymentDetail.LastDateWorked
= lastdateworked;
nwhcmEmploymentDetail.TransitionDate
= termination;
nwhcmEmploymentDetail.ValidFrom =
DateTimeUtil::utcNow();
nwhcmEmploymentDetail.ValidTo =
DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::maxValue(),
DateTimeUtil::getUserPreferredTimeZone());
nwhcmEmploymentDetail.insert();
}
//Block POS
Login Update
retailStaffTable = RetailStaffTable::find(newHcmWorker.PersonnelNumber,true);
//Check for
Retails Staff Table
if(retailStaffTable)
{
ttsBegin;
retailStaffTable.blocked =
blockPosLogin;
retailStaffTable.doUpdate();
ttsCommit;
}
//Retails
Staff Table do not exist for the worker
else
{
retailStaffTable.initValue();
retailStaffTable.staffId =
newHcmWorker.PersonnelNumber;
retailStaffTable.blocked =
blockPosLogin;
retailStaffTable.insert();
}
if(!HcmJob::findByJob(job).RecId)
{
hcmJob.JobId =
job;
hcmjob.insert();
}
numberSeq =
numberSeq::newGetNum(NumberSeqReference::findReference (extendedTypeNum(HcmPositionId)));
hcmPosition.PositionId =
numberSeq.num();
hcmPosition.insert();
hcmPositionDetail.Job = HcmJob::findByJob(job).RecId;
hcmPositionDetail.Position = hcmPosition.RecId;
hcmPositionDetail.Title = HcmTitle::findByTitle(HcmJobDetail::findByJob(HcmPositionDetail.Job).Description).RecId;
hcmPositionDetail.ValidFrom = hiredate;
if(employmentEndDate)
hcmPositionDetail.ValidTo = employmentEndDate;
else
hcmPositionDetail.ValidTo = DateTimeUtil::maxValue();
hcmPositionDetail.insert();
hcmPositionWorkerAssignment.ValidFrom
= hiredate;
if(employmentEndDate)
hcmPositionWorkerAssignment.ValidTo = employmentEndDate;
else
hcmPositionWorkerAssignment.ValidTo = DateTimeUtil::maxValue();
hcmPositionWorkerAssignment.Position = HcmPosition.RecId;
hcmPositionWorkerAssignment.Worker = newHcmWorker.RecId;
hcmPositionWorkerAssignment.insert();
hcmPositionDuration.Position = HcmPosition.RecId;
hcmPositionDuration.ValidFrom = HcmPositionWorkerAssignment.ValidFrom;
if(employmentEndDate)
hcmPositionDuration.ValidTo = employmentEndDate;
else
hcmPositionDuration.ValidTo = DateTimeUtil::maxValue();
hcmPositionDuration.insert();
}
|
|
public Object dialog()
{
DialogRunbase dialog = super();
;
dialogFilename = dialog.addField(extendedTypeStr(FilenameOpen));
dialogFilename.value(filename);
dialog.filenameLookupFilter(["@SYS54806", #AllFiles]);
return
dialog;
}
|
|
public boolean
getFromDialog()
{
filename = dialogFilename.value();
return
true;
}
|
|
private void
hrUpdate(container _createcon)
{
HcmWorker newHcmWorker;
utcDateTime
hiredate,termination,lastdateworked,employmentEndDate;
str job;
OMOperatingUnitNumber businessunit,department;
HcmEmploymentType hcmEmploymentType;
RetailStaffTable retailStaffTable;
NoYes blockPosLogin;
DimensionAttributeValueSetStorage valueSetStorage = new DimensionAttributeValueSetStorage();
DimensionDefault result;
DimensionAttribute dimensionAttribute;
DimensionAttributeValue dimensionAttributeValue;
HcmEmployment hcmEmployment;
HcmEmploymentDetail
hcmEmploymentDetail,nwhcmEmploymentDetail;
HcmJob hcmjob;
HcmPosition hcmPosition;
HcmPositionDetail hcmPositionDetail;
HcmPositionWorkerAssignment hcmPositionWorkerAssignment;
HcmPositionDuration hcmPositionDuration;
NumberSeq numberSeq;
hiredate = DateTimeUtil::newDateTime(str2date(conpeek(_createcon,
1),213),0);
firstname = conpeek(_createcon,
2);
lastname = conpeek(_createcon,
3);
hcmEmploymentType =
str2enum(hcmEmploymentType,conpeek(_createcon, 4));
termination = DateTimeUtil::newDateTime(str2date(conpeek(_createcon,
5),213),0);
lastdateworked = DateTimeUtil::newDateTime(str2date(conpeek(_createcon,
6),213),0);
employmentEndDate =
DateTimeUtil::newDateTime(str2date(conpeek(_createcon, 7),213),0);
if(!employmentEndDate)
employmentEndDate = DateTimeUtil::maxValue();
blockPosLogin = str2enum(blockPosLogin,conPeek(_createcon,8));
job = conPeek(_createcon,9);
businessunit = conPeek(_createcon,10);
department = conPeek(_createcon,11);
if(hcmWorker.RecId)
{
//Block
POS Login Update
retailStaffTable = RetailStaffTable::find(hcmWorker.PersonnelNumber,true);
//Check
for Retails Staff Table
if(retailStaffTable)
{
if(retailStaffTable.blocked
!= blockPosLogin)
{
ttsBegin;
retailStaffTable.blocked =
blockPosLogin;
retailStaffTable.doUpdate();
ttsCommit;
}
}
//Retails
Staff Table do not exist for the worker
else
{
retailStaffTable.initValue();
retailStaffTable.staffId =
newHcmWorker.PersonnelNumber;
retailStaffTable.blocked =
blockPosLogin;
retailStaffTable.insert();
}
//Set
Dimension value
dimensionAttribute =
dimensionAttribute::findByName("@SYS343395");
dimensionAttributeValue =
dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,businessunit,false,true);
valueSetStorage.addItem(dimensionAttributeValue);
dimensionAttribute =
dimensionAttribute::findByName("@SYS181623");
dimensionAttributeValue =
dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,department,false,true);
valueSetStorage.addItem(dimensionAttributeValue);
result = valueSetStorage.save();
hcmEmployment =
hcmEmployment::getActiveEmploymentsByWorker(hcmWorker.RecId, hiredate,
employmentEndDate, true);
if(hcmEmployment)
{
ttsBegin;
if(hcmEmployment.ValidFrom !=
hiredate || hcmEmployment.ValidTo !=
employmentEndDate)
{
HcmWorkerTransition::newUpdateHcmEmployment(hcmEmployment, hiredate,
employmentEndDate);
}
hcmEmployment.ValidFrom =
hiredate;
hcmEmployment.ValidTo =
employmentEndDate;
if(!employmentEndDate)
hcmEmployment.ValidTo =
DateTimeUtil::maxValue();
hcmEmployment.DefaultDimension
= result;
hcmEmployment.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
hcmEmployment.update();
ttsCommit;
//Update
HcmEmploymentDetail
select
* from hcmEmploymentDetail order by
RecId desc
where
hcmEmploymentDetail.Employment
== hcmEmployment.RecId;
if((hcmEmploymentDetail.TransitionDate !=
termination)||(hcmEmploymentDetail.LastDateWorked != lastdateworked))
{
if(hcmEmploymentDetail)
{
hcmEmploymentDetail.selectForUpdate(true);
ttsBegin;
hcmEmploymentDetail.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
hcmEmploymentDetail.ValidTo = DateTimeUtil::utcNow();
hcmEmploymentDetail.update();
ttsCommit;
}
nwhcmEmploymentDetail.Employment
= hcmEmployment.RecId;
nwhcmEmploymentDetail.LastDateWorked =
lastdateworked;
nwhcmEmploymentDetail.TransitionDate
= termination;
nwhcmEmploymentDetail.ValidFrom
= DateTimeUtil::utcNow();
nwhcmEmploymentDetail.ValidTo
= DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::maxValue(),
DateTimeUtil::getUserPreferredTimeZone());
nwhcmEmploymentDetail.insert();
}
}
if(!HcmJob::findByJob(job).RecId)
{
hcmjob.JobId =
job;
hcmjob.insert();
}
else
{
hcmjob = HcmJob::findByJob(job);
}
select
hcmPositionWorkerAssignment
where
hcmPositionWorkerAssignment.Worker==hcmWorker.RecId
join
hcmPositionDetail where
hcmPositionDetail.Job == hcmjob.recId
&&
hcmPositionDetail.Position == hcmPositionWorkerAssignment.Position;
if
(!hcmPositionDetail)
{
numberSeq = numberSeq::newGetNum(NumberSeqReference::findReference
(extendedTypeNum(HcmPositionId)));
hcmPosition.PositionId =
numberSeq.num();
hcmPosition.insert();
hcmPositionDetail.Job = HcmJob::findByJob(job).RecId;
hcmPositionDetail.Position = hcmPosition.RecId;
hcmPositionDetail.Title =
HcmTitle::findByTitle(HcmJobDetail::findByJob(HcmPositionDetail.Job).Description).RecId;
hcmPositionDetail.ValidFrom = hiredate;
if(employmentEndDate)
hcmPositionDetail.ValidTo
= employmentEndDate;
else
hcmPositionDetail.ValidTo
= DateTimeUtil::maxValue();
hcmPositionDetail.insert();
hcmPositionWorkerAssignment.ValidFrom = hiredate;
if(employmentEndDate)
hcmPositionWorkerAssignment.ValidTo = employmentEndDate;
else
hcmPositionWorkerAssignment.ValidTo = DateTimeUtil::maxValue();
hcmPositionWorkerAssignment.Position
= HcmPosition.RecId;
hcmPositionWorkerAssignment.Worker
= hcmWorker.RecId;
hcmPositionWorkerAssignment.insert();
hcmPositionDuration.Position = HcmPosition.RecId;
hcmPositionDuration.ValidFrom
= HcmPositionWorkerAssignment.ValidFrom;
if(employmentEndDate)
hcmPositionDuration.ValidTo
= employmentEndDate;
else
hcmPositionDuration.ValidTo
= DateTimeUtil::maxValue();
hcmPositionDuration.insert();
}
}
}
|
|
void run()
{
container readCon;
counter icount,inserted,updated;
;
ret =true;
csvFile = new
CommaIO(filename, 'r');
try
{
if
(csvFile)
{
readCon = csvFile.read();
//
ttsbegin;
while
(csvFile.status() == IO_Status::OK)
{
readCon = csvFile.read();
if(readCon)
{
firstname = conpeek(readCon,
2);
lastname = conpeek(readCon,
3);
select FirstName,LastName,person from dirPersonNameLoc
where dirPersonNameLoc.FirstName == firstname
&&
dirPersonNameLoc.LastName ==
lastname;
hcmWorker = HcmWorker::findByPerson(dirPersonNameLoc.person);
if (hcmWorker.RecId == 0)
{
//Insert employee
this.hrCreate(readCon);
inserted++;
}
else
{
//Update employee
this.hrUpdate(readCon);
updated++;
}
icount++;
}
}
}
//icount--;//Remove
header recount from total record count
info(strFmt("@CIT231",icount,inserted,updated));
}
catch(Exception::Error)
{
info(strFmt("%1 %2",Exception::Error,icount));
}
}
|
|
static void
main(Args args)
{
ImportHRData importHRData;
;
importHRData = new
ImportHRData();
if(importHRData.prompt())
{
importHRData.run();
}
}
|
Wednesday, 3 February 2016
HR Data Import
Monday, 7 December 2015
Dynamics AX 2012 Data Import using Excel Add-in
- Import Customers
- Importing Vendors
- Importing Main Accounts
- Importing Products
- Importing Customer Transactions/Balances
- Importing Vendor Transactions/Balances
- Importing Ledger Transactions/Balances
- Importing Inventory Transactions/Balances
- Importing Sales Orders
- Importing Free Text Invoices
- Importing Purchase Orders
Thursday, 3 December 2015
How to add Attachments button on a new form
Step 1. Open your form in AOT and Go to from Design node.
Step 2. Add new button group under ActivePanTab.
Step 3. Add new command button under this new button group.

Step 4. Set following properties of this button

Now you need to do one functional setup for this new customization
Step 5: Open below from
Organization administration/SetUp-> Document Management -> Active Document Table
Step 6: Add your table details here and click on Always enable.

Step 7: So its done now.
Open your form and click on Attachment button , below form must open.

Step 2. Add new button group under ActivePanTab.
Step 3. Add new command button under this new button group.
Step 4. Set following properties of this button
Now you need to do one functional setup for this new customization
Step 5: Open below from
Organization administration/SetUp-> Document Management -> Active Document Table
Step 6: Add your table details here and click on Always enable.
Step 7: So its done now.
Open your form and click on Attachment button , below form must open.
Sunday, 29 November 2015
Ware house Phone number
static void warehousetelephonenumber(Args _args)
{
str Warehouse;
LogisticsElectronicAddress LogisticsElectronicAddress;
LogisticsLocation LogisticsLocation;
InventLocationLogisticsLocation InventLocationLogisticsLocation;
InventLocation InventLocation;
;
Warehouse = "11";
InventLocation = InventLocation::find(Warehouse);
Select firstOnly InventLocationLogisticsLocation
where InventLocationLogisticsLocation.InventLocation == InventLocation.RecId;
if (InventLocationLogisticsLocation)
{
select firstOnly LogisticsLocation
where LogisticsLocation.ParentLocation == InventLocationLogisticsLocation.Location
&& LogisticsLocation.IsPostalAddress == NoYes::No;
if (LogisticsLocation)
{
Select firstOnly LogisticsElectronicAddress
where LogisticsElectronicAddress.Location == LogisticsLocation.RecId;
if (LogisticsElectronicAddress)
{
info(strFmt("%1", LogisticsElectronicAddress.Locator));
}
}
}
}
===============================================================
logisticsElectronicAddressLocator getElectronicAddressByType(LogisticsElectronicAddressMethodType _type)
{
InventLocationLogisticsLocation InventLocLogLocation;
LogisticsLocation logisticsLocation;
logisticsLocation contactInfoLogLoc;
LogisticsElectronicAddress logisticsElectronicAddress;
LogisticsPostalAddress logisticsPostalAddress;
;
while select firstOnly * from logisticsLocation
where logisticsLocation.IsPostalAddress == NoYes::Yes
exists join InventLocLogLocation
where InventLocLogLocation.Location == logisticsLocation.RecId
&& InventLocLogLocation.InventLocation == this.RecId
&& InventLocLogLocation.IsPrimary == NoYes::Yes
exists join LogisticsPostalAddress
where LogisticsPostalAddress.Location == logisticsLocation.RecId
&& logisticsPostalAddress.ValidFrom <= DateTimeUtil::utcNow()
&& logisticsPostalAddress.ValidTo > DateTimeUtil::utcNow()
exists join contactInfoLogLoc
where contactInfoLogLoc.ParentLocation == logisticsLocation.RecId
exists join LogisticsElectronicAddress
where LogisticsElectronicAddress.Location == contactInfoLogLoc.RecId
&& logisticsElectronicAddress.Type == _type
{
return logisticsElectronicAddress.Locator;
}
return '';
}
===============================================================
logisticsElectronicAddressLocator getElectronicAddressByType(LogisticsElectronicAddressMethodType _type)
{
InventLocationLogisticsLocation InventLocLogLocation;
LogisticsLocation logisticsLocation;
logisticsLocation contactInfoLogLoc;
LogisticsElectronicAddress logisticsElectronicAddress;
LogisticsPostalAddress logisticsPostalAddress;
;
while select firstOnly * from logisticsLocation
where logisticsLocation.IsPostalAddress == NoYes::Yes
exists join InventLocLogLocation
where InventLocLogLocation.Location == logisticsLocation.RecId
&& InventLocLogLocation.InventLocation == this.RecId
&& InventLocLogLocation.IsPrimary == NoYes::Yes
exists join LogisticsPostalAddress
where LogisticsPostalAddress.Location == logisticsLocation.RecId
&& logisticsPostalAddress.ValidFrom <= DateTimeUtil::utcNow()
&& logisticsPostalAddress.ValidTo > DateTimeUtil::utcNow()
exists join contactInfoLogLoc
where contactInfoLogLoc.ParentLocation == logisticsLocation.RecId
exists join LogisticsElectronicAddress
where LogisticsElectronicAddress.Location == contactInfoLogLoc.RecId
&& logisticsElectronicAddress.Type == _type
{
return logisticsElectronicAddress.Locator;
}
return '';
}
Thursday, 26 November 2015
How to add a method for the click event of a button placed on action pane of a List Page
Setting the DisplayTarget property of the button to the value "Client" will hide the button if used from Enterprise Portal and will enable you to override the
clicked method. If you not plan to use the list page in EP then go ahead.
Otherwise you will have to put your code in the target form
init or class main method.Wednesday, 25 November 2015
Automatic PO Confirmation and Packingslip
static void PostPOPackingSlip(Args _args)
{
PurchFormLetter purchFormLetter;
PurchTable purchTable;
purchTable = purchTable::find('000048');
if (purchTable.DocumentState != VersioningDocumentState::Confirmed)
{
purchFormLetter = PurchFormLetter::construct(DocumentStatus::PurchaseOrder);
purchFormLetter.update(purchTable, "def1");
}
purchTable.reread();
if (purchTable.DocumentState == VersioningDocumentState::Confirmed)
{
purchFormLetter = PurchFormLetter::construct(DocumentStatus::PackingSlip);
purchFormLetter.update(purchTable,"123",systemDateGet(), PurchUpdate::All, AccountOrder::None,false,false);
}
info("jobcompleted");
}
{
PurchFormLetter purchFormLetter;
PurchTable purchTable;
purchTable = purchTable::find('000048');
if (purchTable.DocumentState != VersioningDocumentState::Confirmed)
{
purchFormLetter = PurchFormLetter::construct(DocumentStatus::PurchaseOrder);
purchFormLetter.update(purchTable, "def1");
}
purchTable.reread();
if (purchTable.DocumentState == VersioningDocumentState::Confirmed)
{
purchFormLetter = PurchFormLetter::construct(DocumentStatus::PackingSlip);
purchFormLetter.update(purchTable,"123",systemDateGet(), PurchUpdate::All, AccountOrder::None,false,false);
}
info("jobcompleted");
}
Thursday, 19 November 2015
AutomaticSOPackingSlip
static void AutomaticSOPackingSlip(Args _args)
{
SalesTable salestbl;
SalesLine salesline;
SalesFormLetter_PickingList salesFormLetter;
salestbl = SalesTable::find('000184');
while select salesline where salesline.SalesId == salestbl.SalesId
{
salesline.selectForUpdate(true);
ttsBegin;
salesline.SalesDeliverNow = salesline.QtyOrdered;
salesline.update();
ttsCommit;
}
salesFormLetter = SalesFormLetter_PickingList::newPickingList();
salesFormLetter.transDate(systemDateGet());
salesFormLetter.update(salestbl,
systemdateget(),
SalesUpdate::All,
AccountOrder::None,
NoYes::No,
NoYes::No);
}
{
SalesTable salestbl;
SalesLine salesline;
SalesFormLetter_PickingList salesFormLetter;
salestbl = SalesTable::find('000184');
while select salesline where salesline.SalesId == salestbl.SalesId
{
salesline.selectForUpdate(true);
ttsBegin;
salesline.SalesDeliverNow = salesline.QtyOrdered;
salesline.update();
ttsCommit;
}
salesFormLetter = SalesFormLetter_PickingList::newPickingList();
salesFormLetter.transDate(systemDateGet());
salesFormLetter.update(salestbl,
systemdateget(),
SalesUpdate::All,
AccountOrder::None,
NoYes::No,
NoYes::No);
}
Subscribe to:
Posts (Atom)