Following function is used to create the Assets into the Asset Table.
public void createAssetTable(
AssetId _assetId
, AssetGroupId _assetGroupId
, AssetName _assetName
, AssetLocationId _assetLocationId
, Num _num
, AssetType _assetType
, AssetNameAlias _assetNameAlias
, AssetNotes _assetNotes
, AssetMajorTypeId _assetMajorTypeId)
{
AxAssetTable axAssetTable;
;
axAssetTable = new AxAssetTable();
axAssetTable.validateInput(true);
axAssetTable.parmAssetId(_assetId);
axAssetTable.parmAssetGroup(_assetGroupId ? _assetGroupId : assetGroupId);
axAssetTable.parmName(_assetName);
axAssetTable.parmLocation(_assetLocationId);
axAssetTable.parmSerialNum(_num);
axAssetTable.parmAssetType(_assetType);
axAssetTable.parmNameAlias(_assetNameAlias);
axAssetTable.parmNotes(_assetNotes);
axAssetTable.parmMajorType(_assetMajorTypeId);
axAssetTable.save();
}
// creates the Assets book
protected void CreateAssetBook(container _conLine)
{
#Define.AssetId(1)
#Define.BookId(2)
#Define.PostingProfile(9)
#Define.LifeTime(11)
#Define.LifeTimeRest(12)
#Define.DepreciationStartDate(16)
#Define.LastDepreciationDate(18)
#Define.AcquisitionDate(27)
AssetBook assetBook;
AxAssetBook axAssetBook = AxAssetBook::construct();
SysDictClass sysDictClassAxAssetBook = new SysDictClass(classIdGet(AxAssetBook));
;
assetBook = AssetBook::find(this.getLineValue(_conLine, #AssetId), this.getLineValue(_conLine, #BookId), true);
if(assetBook)
{
axAssetBook = AxAssetBook::newAssetBook(assetBook);
// AssetId
axAssetBook.parmAssetId(this.getLineValue(_conLine,#AssetId))
// BookId
axAssetBook.parmBookId(this.getLineValue(_conLine,#BookId));
// PostingProfile
axAssetBook.parmPostingProfile( this.getLineValue(_conLine, #PostingProfile) );
// LifeTime
axAssetBook.parmLifeTimes(str2num(this.getLineValue(_conLine,#LifeTime)));
// LifeTimeRest
axAssetBook.parmLifeTimeRest(str2num(this.getLineValue(_conLine,#LifeTimeRest)));
// DepreciationStartDate
axAssetBook.parmDepreciationStartDate(str2date((this.getLineValue(_conLine,#DepreciationStartDate),123));
// LastDepreciationDate
axAssetBook.parmLastDepreciationDate(str2dat(this.getLineValue(_conLine,#LastDepreciationDate),123));
// AcquisitionDate
axAssetBook.parmAcquisitionDate(str2date(this.getLineValue(_conLine,#AcquisitionDate),123));
axAssetBook.save();
}
else
{
throw error(strFmt(AssetBook::txtNotExist(), this.getLineValue(_conLine, #AssetId),
this.getLineValue(_conLine, #BookId)));
}
}
// gets the value from the container
protected anytype getLineValue(container _conLine,
int _columnNum,
Types _valueType = Types::String,
EnumId _enumId = 0)
{
str strValue;
anytype anyTypeValue;
DictEnum dictEnum;
strValue = conPeek(_conLine,
_columnNum);
switch(_valueType)
{
case Types::String :
anyTypeValue = strValue;
break;
case Types::Integer :
if(strValue)
{
anyTypeValue = str2int(strValue);
}
else
{
anyTypeValue = 0;
}
break;
case Types::Real :
if(strValue)
{
anyTypeValue = str2num(strValue);
}
else
{
anyTypeValue = 0.00;
}
break;
case Types::Enum :
if(!_enumId)
{
throw error(strFmt("@SYS22828", funcName()));
}
dictEnum = new DictEnum(_enumId);
if(!dictEnum)
{
throw error(strFmt("@SYS22828", funcName()));
}
if(strValue)
{
anyTypeValue = dictEnum.name2Value(strValue);
}
else
{
anyTypeValue = 0;
}
break;
case Types::Date :
if(strValue)
{
anyTypeValue = str2date(strValue,123);
}
else
{
anyTypeValue = dateNull();
}
break;
case Types::UtcDateTime :
if(strValue)
{
anyTypeValue = DateTimeUtil::parse(strValue);
}
else
{
anyTypeValue = utcDateTimeNull();
}
break;
default :
throw error(strFmt("@SYS26908", _valueType));
}
return anyTypeValue;
}
// creates the Assets book
protected void CreateAssetBook(container _conLine)
{
#Define.AssetId(1)
#Define.BookId(2)
#Define.PostingProfile(9)
#Define.LifeTime(11)
#Define.LifeTimeRest(12)
#Define.DepreciationStartDate(16)
#Define.LastDepreciationDate(18)
#Define.AcquisitionDate(27)
AssetBook assetBook;
AxAssetBook axAssetBook = AxAssetBook::construct();
SysDictClass sysDictClassAxAssetBook = new SysDictClass(classIdGet(AxAssetBook));
;
assetBook = AssetBook::find(this.getLineValue(_conLine, #AssetId), this.getLineValue(_conLine, #BookId), true);
if(assetBook)
{
axAssetBook = AxAssetBook::newAssetBook(assetBook);
// AssetId
axAssetBook.parmAssetId(this.getLineValue(_conLine,#AssetId))
// BookId
axAssetBook.parmBookId(this.getLineValue(_conLine,#BookId));
// PostingProfile
axAssetBook.parmPostingProfile( this.getLineValue(_conLine, #PostingProfile) );
// LifeTime
axAssetBook.parmLifeTimes(str2num(this.getLineValue(_conLine,#LifeTime)));
// LifeTimeRest
axAssetBook.parmLifeTimeRest(str2num(this.getLineValue(_conLine,#LifeTimeRest)));
// DepreciationStartDate
axAssetBook.parmDepreciationStartDate(str2date((this.getLineValue(_conLine,#DepreciationStartDate),123));
// LastDepreciationDate
axAssetBook.parmLastDepreciationDate(str2dat(this.getLineValue(_conLine,#LastDepreciationDate),123));
// AcquisitionDate
axAssetBook.parmAcquisitionDate(str2date(this.getLineValue(_conLine,#AcquisitionDate),123));
axAssetBook.save();
}
else
{
throw error(strFmt(AssetBook::txtNotExist(), this.getLineValue(_conLine, #AssetId),
this.getLineValue(_conLine, #BookId)));
}
}
// gets the value from the container
protected anytype getLineValue(container _conLine,
int _columnNum,
Types _valueType = Types::String,
EnumId _enumId = 0)
{
str strValue;
anytype anyTypeValue;
DictEnum dictEnum;
strValue = conPeek(_conLine,
_columnNum);
switch(_valueType)
{
case Types::String :
anyTypeValue = strValue;
break;
case Types::Integer :
if(strValue)
{
anyTypeValue = str2int(strValue);
}
else
{
anyTypeValue = 0;
}
break;
case Types::Real :
if(strValue)
{
anyTypeValue = str2num(strValue);
}
else
{
anyTypeValue = 0.00;
}
break;
case Types::Enum :
if(!_enumId)
{
throw error(strFmt("@SYS22828", funcName()));
}
dictEnum = new DictEnum(_enumId);
if(!dictEnum)
{
throw error(strFmt("@SYS22828", funcName()));
}
if(strValue)
{
anyTypeValue = dictEnum.name2Value(strValue);
}
else
{
anyTypeValue = 0;
}
break;
case Types::Date :
if(strValue)
{
anyTypeValue = str2date(strValue,123);
}
else
{
anyTypeValue = dateNull();
}
break;
case Types::UtcDateTime :
if(strValue)
{
anyTypeValue = DateTimeUtil::parse(strValue);
}
else
{
anyTypeValue = utcDateTimeNull();
}
break;
default :
throw error(strFmt("@SYS26908", _valueType));
}
return anyTypeValue;
}
Hi Krishh,
ReplyDeleteI need to import AssetTable & AssetBook Table data from excel file using code. I have written code to import assettable data, but am not able to import assetbook table data from excel. If you have any code to import Assetbook data pls. let me know.
Regards,
Ansar.
Hi,
DeleteUpdated the post with creation of AssetsBook.
regards,
krishna.
krishna.dynamics@gmail.com
Hello Krishh,
ReplyDeleteI'm also facing the same scenario, what has mentioned by Basha, pls help.
Hi,
DeleteUpdated the post with creation of AssetsBook.
regards,
krishna.
krishna.dynamics@gmail.com
Hi Krishh,
ReplyDeleteI'm also facing the same scenario mentioned by Basha, pls help.
Hi Krishh,
ReplyDeleteI am new to AX, here i am trying to create Fixed Assets through code, but my doubt is, in CreateAssetBook method what is (AxAssetBook) means may i know what it is ........Thanks in advance........