Monthwise number sequence

Refreshing the number sequencing for sales order each month so that sales order creation month can be identified based on the number.

Initial setup:

m1

///

/// This batch will update the numbersequence format ‘yr/Month/######’ for salesorder number.
///

class Monthwisenumberseq extends RunBaseBatch
{
}

protected boolean canGoBatchJournal()
{
return true;
}

public void run()
{
NumberSequenceReference numberseqref;
NumberSequenceTable numberSeqTable;
container segments;
str annotatedFormat, format, datestr;
;
ttsBegin;
datestr = date2str(systemDateGet(),
321,
DateDay::Digits2,
DateSeparator::Slash, // separator1
DateMonth::Short,
DateSeparator::Slash, // separator2
DateYear::Digits4,
DateFlags::None);

datestr = subStr(datestr, 1, strLen(datestr)- 2);
segments = [[-1,datestr]];
segments += [[-2,’######’]];

annotatedFormat = NumberSeq::createAnnotatedFormatFromSegments(segments);
format = NumberSeq::createAnnotatedFormatFromSegments(segments, false);

numberseqref = NumberSeqReference::findReference(extendedTypeNum(SalesId));

select firstOnly forupdate numberSeqTable
where numberSeqTable.RecId == numberseqref.NumberSequenceId &&
numberSeqTable.NumberSequenceScope == numberseqref.NumberSequenceScope;

if (numberSeqTable)
{
numberSeqTable.AnnotatedFormat = annotatedFormat;
numberSeqTable.Format = format;
numberSeqTable.NextRec = 1;
numberSeqTable.doUpdate();
}
ttsCommit;
}

public static ClassDescription description()
{
return “Monthwise numbersequence”;
}

public server static void main(Args _args)
{
Monthwisenumberseq monthwisenumberseq = new Monthwisenumberseq();

if (monthwisenumberseq.prompt())
{
monthwisenumberseq.run();
}
}

m2

Advertisements

Dimension Look up in AX 2012

SysTableLookup sysTableLookup;
QueryBuildDataSource queryBuildDataSource,queryBuildDataSource1;
Query query;
QueryBuildRange queryRangePhysical,queryRangeTechnical;
DimensionAttribute dimAttr;

select firstonly recid from dimAttr where dimAttr.Name == “Dimension Name(Department or Costcenter,…etc)”
if (dimAttr)
{
sysTableLookup = SysTableLookup::newParameters(tablenum(DimensionFinancialTag), this);

sysTableLookup.addLookupfield(fieldnum(DimensionFinancialTag, value),true);
sysTableLookup.addLookupfield(fieldnum(DimensionFinancialTag, Description),false);
query = new Query();

queryBuildDataSource = query.addDataSource(tablenum(DimensionFinancialTag));
queryBuildDataSource1 = queryBuildDataSource.addDataSource(tableNum(DimensionAttributeDirCategory));
queryBuildDataSource1.relations(true);
queryBuildDataSource1.joinMode(JoinMode::InnerJoin);
queryBuildDataSource1.addLink(fieldnum(DimensionFinancialTag, FinancialTagCategory), fieldnum(DimensionAttributeDirCategory, DirCategory));

queryBuildDataSource1.addRange(fieldnum(DimensionAttributeDirCategory,DimensionAttribute)).value(queryValue(dimAttr.RecId));
sysTableLookup.parmQuery(query);

sysTableLookup.performFormLookup();
}

Printing dimension value of customer or vendor.

static void ShowcustDefaultDimensions(Args _args)
{
CustTable custTable;
DimensionAttributeValueSet dimAttrValueSet;
DimensionAttributeValueSetItem dimAttrValueSetItem;
DimensionAttributeValue dimAttrValue;
;

custtable = Custtable::find(‘Customer Id’);

while select dimAttrValue
exists join dimAttrValueSetItem
exists join dimAttrValueSet
where dimAttrValueSet.RecId == custTable.DefaultDimension &&
dimAttrValueSetItem.DimensionAttributeValueSet == dimAttrValueSet.RecId &&
dimAttrValue.RecId == dimAttrValueSetItem.DimensionAttributeValue
{
print dimAttrValue.getValue();
}
pause;
}

Product Creation in Ax 2012 using x++

Public void tst_Productcreate()
{
EcoResProductService erProdSvc;
EcoResEcoResProduct EcoResProd;
EcoResEcoResProduct_Product_distinct ProdMast;
EcoResEcoResProduct_Translation Translation;
EcoResEcoResProduct_Identifier Identifier;
EcoResEcoResProduct_ProductDimGroup ProdDimGroup;
EcoResEcoResProduct_Product_Distinct DistProd;
EcoResProduct ecoResProduct;
// Used for releasing Product
EcoResEcoResProduct_StorageDimGroup storageDimGroup;
// Used to assign Storage Dim Group
EcoResEcoResProduct_TrackingDimGroup trackingDimension;
// used to assign Tracking Dimension
erProdSvc = EcoResProductService::construct();
EcoResProd = new EcoResEcoResProduct();
ProdMast = new EcoResEcoResProduct_Product_distinct();
ttsBegin;
ProdMast.parmDisplayProductNumber(“Test84756”);
ProdMast.parmProductType(EcoResProductType::Item);
// Product is Item OR Service
ProdMast.parmSearchName(“Test84756”);
DistProd = new EcoResEcoResProduct_Product_Distinct();
Translation = ProdMast.createTranslation().addNew();
Translation.parmDescription (“Test Product1”);
Translation.parmLanguageId(“en-us”);
Translation.parmName (“Test Product1”);
Identifier = ProdMast.createIdentifier().addNew();
Identifier.parmProductNumber(“Test84756”);
//Code for adding Storage Dimension Group….
storageDimGroup = ProdMast.createStorageDimGroup().addNew();
storageDimGroup.parmProduct(“Test84756”);
storageDimGroup.parmStorageDimensionGroup(“Tst2”);
// Code for adding Tracking Dimension Group….
trackingDimension = ProdMast.createTrackingDimGroup().addNew();
trackingDimension.parmProduct(“Test84756”);
trackingDimension.parmTrackingDimensionGroup(“tst2”);
EcoResProd.createProduct().add(ProdMast);
erProdSvc.create(EcoResProd);
info(“Test Product1 is created”);
// Code for releasing Product
ecoResProduct = EcoResProduct::findByProductNumber(“Test84756”);
EcoResProductReleaseManagerBase::releaseProduct(ecoResProduct.RecId,CompanyInfo::findDataArea(“tst2”).RecId);
ttsCommit;
}

PO Splitting

Splitting Purchase line in AX:
Suppose we are purchasing one item with 10 qty.At the time of receiving the the item we should consider each qty as one asset.So before doing the GRN we should split the item and post the GRN.So 10 assets will be created in the fixed asset table.

Here we go.

Add one butten in Purch table form in line level.In click method of the button add below code.

void clicked()
{

PurchLine purchlinelocal;
int i = 1;
;
if(purchline.PurchQty>1)
{
while(i<=purchline.PurchQty)
{
purchlinelocal.clear();
purchlinelocal.initFromPurchTable(purchTable);
purchlinelocal.PurchId=purchline.PurchId;
purchlinelocal.initFromPurchLine(purchline,true,false,false,false,1);
purchlinelocal.PurchQty = 1;
purchlinelocal.QtyOrdered = 1;
purchlinelocal.CurrencyCode = purchline.CurrencyCode;
purchlinelocal.PurchPrice = purchLine.PurchPrice;
purchlinelocal.InventDimId = purchLine.InventDimId;
purchlinelocal.PurchReqId = purchline.PurchReqId;
purchlinelocal.PurchReqLineRefId = purchline.PurchReqLineRefId;
purchlinelocal.PurchStatus = purchtable.PurchStatus;
purchlinelocal.LineDisc = purchline.LineDisc;
purchlinelocal.LineAmount = purchlinelocal.PurchPrice – purchlinelocal.LineDisc;
purchlinelocal.AssessableValue_IN = purchlinelocal.LineAmount + ((purchlinelocal.LineAmount *1)/100);
purchlinelocal.createLine(0,0,0,0,0,0);
i++;
}
purchline.delete();
}
PurchLine_ds.executeQuery();
PurchLine_ds.refresh();
}