Month: January 2014

How to SMS from AX 2012 through Code (X++)

System.Net.WebClient cust;
System.IO.Stream data;
System.IO.StreamReader reader;
System.String URLAddres;
Str SMSConfirmID;
;

cust = new System.Net.WebClient();
// Create a String with User, password, api_id, to, Text as required
// example to form string given below ( to be register with clickatell for credits)

URLAddres = “http://www.smszone.in/sendsms.asp?page=SendSmsBulk&username=966535865845&password=6668&number=” + _mobileNo +”&message=” + _message;
data = cust.OpenRead(URLAddres);
reader = new System.IO.StreamReader(data);
SMSConfirmID = reader.ReadToEnd();
data.Close();
reader.Close();
info(SMSConfirmID);

return true;

Advertisements

Create Ledger Dimension in AX 2012

/// <summary>
/// To get the Ledger Dimension Value [RecId] for all listed items in LedgerJournalACType
/// </summary>
/// <param name=”_CustVendAccountId”>
/// Must provide the CustID or VendID
/// </param>
/// <param name=”_accountType”>
/// Must define the Ledger Journal Account Type
/// </param>
/// <returns>
/// Record ID
/// </returns>
/// <remarks>
///
/// </remarks>

public static LedgerDimensionAccount getDynamicLedgerDimension(str _CustVendAccountId, LedgerJournalACType _accountType)
{
LedgerDimensionAccount _ledgerDim;

_ledgerDim = DimensionStorage::getDynamicAccount(_CustVendAccountId, _accountType);

return _ledgerDim;
}

Creating default dimension in AX 2012

/// <summary>
/// Create the Dynamic Default Financial Dimension on the basis of provided dimension values.
/// </summary>
/// <param name=”_dimensionColumnValue”>
/// Fill container variable with required Financial Dimension values.
/// </param>
/// <param name=”_dimensionColumnName”>
/// Fill container variable with the method getFinancialDimensionColumnNames
/// </param>
/// <returns>
/// Financial Dimension Rec ID.
/// </returns>
/// <remarks>
///
/// </remarks>

//Code written by Ahmed Alam on 30th December, 2013
//ReasonCode: To get the new default dimension value on the basis of provided dimension default value
//public Static RecId createDefaultDimensiononString( str 3 _branch, str 2 _dept, str 4 _CC, str 4 _brand, str 4 _emplid, str 15 _lc)
public static RecId createDefaultDimensionString(container _dimensionColumnValue, container _dimensionColumnName)
{
Struct struct;
int _counterDim, _counterValue;
DimensionValue _foundValue[];
Name _foundName[];
container ledgerDimension;
DimensionDefault DimensionDefault;
str _value;
;

struct = new struct();

_counterValue = 1;
for(_counterDim = 1; _counterDim <= conLen(_dimensionColumnValue); _counterDim++)
{
_value = conPeek(_dimensionColumnValue, _counterDim);
if(_value == ” )
{
_counterValue = _counterValue -1 ;
}
if(_value != ”)
{
_foundValue[_counterValue] = conPeek(_dimensionColumnValue, _counterValue);
_foundName[_counterValue] = conPeek(_dimensionColumnName, _counterValue);
struct.add(_foundName[_counterValue], _foundValue[_counterValue]);

ledgerDimension += struct.fields();
ledgerDimension += struct.fieldName(_counterValue);
ledgerDimension += struct.valueIndex(_counterValue);
_counterValue ++;
}
}

DimensionDefault = Dimensions::getDimensionAttributeValueSetId(ledgerDimension);
return DimensionDefault;
}

Calling CSV file through X++ in ax 2012

#File
#aviFiles

FileIOPermission permission;
container readCon, _returnstatus, _dimensionColumnValue, _dimensionColumnName;
int cnt, numLines;
TextIO textIO;
textBuffer tb = new textBuffer();
CommaIo csvFile;
str _branch, _division, _cc, _equipment, _empl, _lc, _custVendID;

RecId _productID;
str _catCode;

int _counter;

;

permission = new fileIOpermission(_fileName,#io_read);
permission.assert();

textIO = new TextIO(_fileName,#io_read);
if (!textIO)
{
throw error(“Error reading provided CSV file”);
}

tb.fromFile(_fileName);//File name with Path …
numLines = tb.numLines();
csvFile = new CommaIo(_fileName, ‘r’);
csvFile.inFieldDelimiter(” “); // Delimiter…

if (csvFile)//Checking for csv file.
{
readCon = csvFile.read();//reading the file.
for(cnt=1;cnt<=numLines;cnt++)
{
readCon = str2Con(tb.nextToken(true));
if(cnt>1)
{
ttsBegin;

ttscommit;

}

}

}

Import Items/Product Part II

//INVENTTABLE—————————————————————————————-
_invTable.clear();
_invTable.BOMUnitId = ‘pc’;
if(conPeek(readCon, 4) == ‘No’)
{
_invTable.CostModel = 0;
}
else
{
_invTable.CostModel = 1;
}
if(conPeek(readCon, 5) == ‘No’)
{
_invTable.PurchModel = 0;
}
else
{
_invTable.PurchModel = 1;
}
_invTable.SalesModel = conPeek(readCon, 6);

_invTable.ItemId = conPeek(readCon, 1);
_invTable.ItemType = ItemType::Item;
_invTable.NameAlias = conPeek(readCon, 2);
_invTable.Product = _productID;

_invTable.SalesPercentMarkup = conPeek(readCon, 7);
_invTable.SalesPriceModelBasic = conPeek(readCon, 8);
_invTable.PmfProductType = conPeek(readCon, 9);
_invTable.PdsVendorCheckItem = PdsVendorCheckItem::NotAllowed;

_invTable.DefaultDimension = Dimensions::createDefaultDimensionString(_dimensionColumnValue, _dimensionColumnName);
_invTable.insert();
//END HERE

 

//ECORESSTORAGEDIMENSIONGROUPITEM—————————————————————————————-
_ecoResTrackDimGrpItem.clear();
_ecoResTrackDimGrpItem.ItemDataAreaId = ‘unim’;
_ecoResTrackDimGrpItem.ItemId = conPeek(readCon, 1);
_ecoResTrackDimGrpItem.TrackingDimensionGroup = EcoResTrackingDimensionGroup::findByDimensionGroupName(conPeek(readCon, 10)).RecId;
_ecoResTrackDimGrpItem.insert();
//END HERE

//ECORESTRACKINGDIMENSIONGROUPITEM—————————————————————————————-
_ecoResStrDimGrpItem.clear();
_ecoResStrDimGrpItem.ItemDataAreaId = ‘unim’;
_ecoResStrDimGrpItem.ItemId = conPeek(readCon, 1);
_ecoResStrDimGrpItem.StorageDimensionGroup = EcoResStorageDimensionGroup::findByDimensionGroupName(conPeek(readCon, 11)).RecId;
_ecoResStrDimGrpItem.insert();
//END HERE

//INVENTMODELGROUPITEM—————————————————————————————-
_invModelGrpItem.clear();
_invModelGrpItem.ItemDataAreaId = ‘unim’;
_invModelGrpItem.ItemId = conPeek(readCon, 1);
_invModelGrpItem.ModelGroupDataAreaId = ‘unim’;
_invModelGrpItem.ModelGroupId = conPeek(readCon, 12);
_invModelGrpItem.doInsert();
//END HERE

//INVENTITEMGROUPITEM—————————————————————————————-
_invItmGrpItem.clear();
_invItmGrpItem.ItemDataAreaId = ‘unim’;
_invItmGrpItem.ItemGroupDataAreaId = ‘unim’;
_invItmGrpItem.ItemGroupId = conPeek(readCon, 13);
_invItmGrpItem.ItemId = conPeek(readCon, 1);
_invItmGrpItem.doInsert();
//END HERE

//INVENTMODELGROUP—————————————————————————————-
_invTableModule.clear();
_invTableModule.EndDisc = NoYes::Yes;
_invTableModule.ItemId = conPeek(readCon, 1);
_invTableModule.ModuleType = ModuleInventPurchSales::Invent;
_invTableModule.UnitId = ‘pc’;
_invTableModule.Price = conPeek(readCon, 14);
_invTableModule.doInsert();

_invTableModule.clear();
_invTableModule.EndDisc = NoYes::Yes;
_invTableModule.ItemId = conPeek(readCon, 1);
_invTableModule.ModuleType = ModuleInventPurchSales::Purch;
_invTableModule.Price = conPeek(readCon, 15);
_invTableModule.UnitId = ‘pc’;
_invTableModule.doInsert();

_invTableModule.clear();
_invTableModule.EndDisc = NoYes::Yes;
_invTableModule.ItemId = conPeek(readCon, 1);
_invTableModule.ModuleType = ModuleInventPurchSales::Sales;
_invTableModule.Price = conPeek(readCon, 16);
_invTableModule.UnitId = ‘pc’;
_invTableModule.doInsert();
//END HERE

//ECORESPRODUCTCATEGORY——————————————————————————————————
_catCode = conPeek(readcon, 17);
_ecoResPrdCat.clear();
_ecoResPrdCat.Category = EcoResCategory::findByCode(_catcode,5637144576).RecId;
_ecoResPrdCat.Product = _productID;
_ecoResPrdCat.CategoryHierarchy = 5637144576; //MAIN
_ecoResPrdCat.doInsert();
//END HERE

//INVENTITEMLOCATION—————-
_invItemLocation.clear();
_invItemLocation.ItemId = conPeek(readCon, 1);
_invItemLocation.inventDimId = ‘AllBlank’;
_invItemLocation.insert();

//END HERE

Import Items/Product through X++ AX 2012 [Initial Version]

I used below code for Distinct Product.

 

EcoResProductService erProdSrv;
EcoResEcoResProduct EcoResProd;
EcoResEcoResProduct_Product_Distinct ProdMast;
EcoResEcoResProduct_Translation Translation;
EcoResEcoResProduct_Identifier Identifier;
EcoResEcoResProduct_ProductDimGroup ProdDimGroup;
EcoResEcoResProduct_TrackingDimGroup TrackDimGroup;
EcoResEcoResProduct_StorageDimGroup StoreDimGroup;

 

//CLASS INITIALIZING
erProdSrv = EcoResProductService::construct();
EcoResProd = new EcoResEcoResProduct();
ProdMast = new EcoResEcoResProduct_Product_Distinct();
//END HERE

 
ProdMast.parmDisplayProductNumber(conPeek(readCon, 1));
ProdMast.parmProductType(EcoResProductType::Item);
ProdMast.parmSearchName(conPeek(readcon, 2));
Translation = ProdMast.createTranslation().addNew();
Translation.parmDescription(conPeek(readCon, 3));
Translation.parmLanguageId(“en-us”);
Translation.parmName(conPeek(readCon, 3));
Identifier = ProdMast.createIdentifier().addNew();
Identifier.parmProductNumber(conPeek(readCon, 1));

/* TrackDimGroup = ProdMast.createTrackingDimGroup().addNew();
TrackDimGroup.parmProduct(conPeek(readCon,1));
TrackDimGroup.parmTrackingDimensionGroup(conPeek(readCon, 10));
StoreDimGroup = ProdMast.createStorageDimGroup().addNew();
StoreDimGroup.parmProduct(conPeek(readCon,1));
StoreDimGroup.parmStorageDimensionGroup(conPeek(readCon, 11));*/
// ProdMast.parmVariantConfigurationTechnology(EcoResVariantConfigurationTechnologyType::PredefinedVariants);

EcoResProd.createProduct().add(ProdMast);
erProdSrv.create(EcoResProd);

BulkUpload::insertProductCompleteData(_fileName);