Thursday, 3 March 2016

compare 2 dates time and fetch the records in between them

Please check the below job:


static void Job154(Args _args)
{
    PurchTable  pTable;
    date        dT,DT1;
    utcDateTime utcDT,utcDT2;
    int         timeOfday,timeOfday2;
    ;

    dT = 02\02\2016;//2016-03-02;//today();
    dT -= dayOfWk(dT)-1;//get first day of week
    timeOfday   =   str2Time("12:08:20");//prepare time
    utcDT = datetimeutil::newDateTime(dT,timeOfday);//convert to utcDT
   
   
     dT1= 02\03\2016;//2016-03-02;//today();//get today
    dT1 -= dayOfWk(dT)-1;//get first day of week
    timeOfday2   =   str2Time("12:08:20");//prepare time

    utcDT2 = datetimeutil::newDateTime(dT1,timeOfday);//convert to utcDT



    while select pTable
    where pTable.createdDateTime >= utcDT && pTable.createdDateTime <= utcDT2
    {
        //todo: add code
        info(strFmt("%1",pTable.RecId));
    }
}

Thursday, 25 February 2016

only one record is checked in a column for a table

say we have a requirement that we have a table and in that table we have many records  for theses records any given point of time only one record should be checked.

go to table table modified and write:


public void modifiedField(FieldId _fieldId)
{
    NumberSequenceTable    NumberSequenceTable;
    ;
    super(_fieldId);
    ttsBegin;

    if(this.Default == NoYes::Yes)
 
    {
        while select forupdate NumberSequenceTable
            where NumberSequenceTable.RecId != this.RecId
        {
          NumberSequenceTable.Default = NoYes::No;
           NumberSequenceTable.update();

        }
    }

    }

    ttsCommit;

}

here we are interating for all the records in the table where rec id does not match and make all the other records as false.

Wednesday, 24 February 2016

job to find the primary address for the customer

static void JobtofindprimaryAddress(Args _args)
{
    CustTable           custTable;
    str                 name;
    str                 address;
    str                 primaryAddress;
    ;
    custTable = CustTable::find("UPNR003", false);
    name = DirParty::primaryPostalAddress(custTable.Party).displayLocationDescription();
    address =  DirParty::primaryPostalAddress(custTable.Party).Address;
    if(!address)
    {
        info("no address found");
    }
    info(strFmt("name: %1", name));
    info(strFmt("adress: %1", address));
}

MVP microsoft

Please follow this link :

http://www.summitgroupsoftware.com/blog/insiders-overview-microsofts-mvp-program

creation of customer payment journal(inserted the data in the LedgerJournalTrans but not showing on the form

Please note when ever we create the customer payment journal normally we are inserting the record in the LedgerJournalTrans  how ever the data will get inserted in the table but still it will not so in the front end.

solutiob

please insert the record in the LedgerJournalTransTaxExtensionIN table

\Data Dictionary\Tables\LedgerJournalTransTaxExtensionIN\Relations\LedgerJournalTrans\LedgerJournalTransTaxExtensionIN.LedgerJournalTrans == LedgerJournalTrans.RecId

Wednesday, 10 February 2016

compare common record with sales table or purchase table


        for (i=tableFlag; i <=fr.dataSourceCount();i++)
        {
            fds = fr.dataSource(i);
            if(flag==0)
            {
                currentRecord  = currentQuery.get(fds.table());
                linesBuffer    = currentRecord;
            }
            else
            {
                if( currentRecord.TableId == tableNum(SalesTable) ||  //if the common record is salestable
                    currentRecord.TableId == tableNum(PurchTable))   //if the common record is purch //table
                {
                    currentRecord = this.queryXMLNodeSalesPurchase(currentRecord.TableId, fds.table(), currentRecord.RecId);
                }
                else
                {
                    currentRecord = this.queryXMLNode(currentRecord.TableId, fds.table(), currentRecord.RecId);
                }
            }

AX and TFS in Daily Development Activities


 To check new objects into TFS:
1.    If the object exists and you have not modified the object, modify it first.  If the object is a completely custom object, create it first.
By default objects do not exist in version control.  For example, objects that exist only in the sys and syp layers would not be checked into TFS because they can be recreated simply by reinstalling AX.  Version control is for tracking changes to customizations made to existing objects or for completely custom objects.
2.            In the AOT right-click on the object and choose Add to Version Control.

3.    Once you have a collection of objects ready for check-in, in the AOT go to Version control > Pending Objects and check-in the objects in the list
-When objects are added to version control, xpos are created for the objects and saved into the local repository on the developer’s machine.
-When the objects are checked into version control, the xpos in the local repository are copied up to the central shared TFS repository.

PendingObjects

4.            In the form where you check in the objects there is a Work Items tab.
-Enter in the ID of the TFS task to tie this check-in to and in TFS’s Sharepoint site in this history for the task you’ll see your check-in against the task and you will see the individual objects that were checked-in.

CheckIN

To check out objects previously added to version control:
1.    In the AOT right-click on the object and choose Check Out
2.    Make your changes to the object
3.    Click on Version control > Pending Objects and check-in the objects in the list
-Once one developer has an object checked out, another developer will not be allowed to check out that same object

To view the history of an object:
1.    Right-click on the object and choose History
2.    In the form that opens you can select a version from the list and click the Get button to import that version of the object into your AOT.
3.    In the form that opens you can click the View file button to open the xpo for a particular version of the file
History_Version1

To synchronize to changes checked into the central repository by yourself or other developers:
1.    Click on Version control > Synchronize
2.    In the dialog that opens mark the Force checkbox and click OK.
-This will force version control to overwrite any changes you’ve made to objects in your local AOT that aren’t checked out or under version control.
3.            In the form that opens, mark the model you want to synchronize to.
-When you synchronize to the central repository all of the xpos that have been checked in since the last time a sync was executed on the machine, are copied from the central repository to the local repository.
-Once the xpos exist in the local repository they are imported into AX and a database synch and compile are performed for those imported objects.

To check out the label file and add new labels to it:
1.    Click on Tools > Labels > Label editor
2.    The label editor form will open and at the top click on the Get Latest button to ensure you have the latest copy of the label file.
3.    At the top of the label editor form click the check-out button to check out the label file.
4.    To create a new label, in the label editor form, click the New button and save the label.
5.    The label will be given a temporary label id like $@ABC123.  Use the temporary label id in your code that uses the label.
6.    Once the labels have been created, click Version control > Pending objects and check-in the objects in the list.  (The label file will be one of the objects.)
7.    When you check in the label file, a permanent label id will be assigned to each new label.
-If the code you have that uses those labels is still checked out or is being checked in with the label file, the temporary labels will be automatically replaced with the permanent label id.
-If the code you have that uses those labels is not checked out, after the label file is checked in and the permanent label ids are known, you’ll have to go through your code, check out the objects, and manually change the code to use the permanent label id.


sales table list page should show the sales order of today only

say we have a requirement where we want to show todays sales order and we dont want to show any old sales order

then we have to add a filter in the salestable list page interaction class like


public void initializeQuery(Query _query)
{
    QueryBuildDataSource    qbds;
    ProjInvoiceTable        projInvoiceTable;
    utcDateTime             dayStartDateTime;               // added by aseem

    if (isCustomer)
    {
        EPQuery::makeMyCustomerSelfServiceQuery(_query,tableNum(SalesTable));
    }

    if (this.listPage().listPageArgs() &&
        this.listPage().listPageArgs().externalRecord() &&
        this.listPage().listPageArgs().menuItemName() ==  menuitemDisplayStr(SalesTableListPage_Proj) &&
        this.listPage().listPageArgs().externalRecord().TableId == tableNum(ProjInvoiceTable))
    {
        projInvoiceTable = this.listPage().listPageArgs().externalRecord();
        qbds = _query.dataSourceTable(tableNum(SalesTable)).addDataSource(tableNum(ProjTable));
        qbds.relations(true);
        qbds.joinMode(JoinMode::ExistsJoin);
        qbds.addRange(fieldNum(ProjTable,ProjInvoiceProjId)).value(queryValue(projInvoiceTable.ProjInvoiceProjId));
    }
    dayStartDateTime = DateTimeUtil::newDateTime(today() , 0);          //
    _query.dataSourceNo(1).addRange(fieldNum(SalesTable, CreatedDateTime)).value(strFmt("> %1", datetime2str(dayStartDateTime)));
    super(_query);
}

Wednesday, 3 February 2016

recommend way of moving file in various ax environment



The following table describes the scenarios in which we recommend you use each installation method.

Scenario Recommended installation method
Distributing a solution to customers Model files
Deploying a solution in a development or test environment Model files or XPO files
Deploying a solution to a production environment Model store files

Monday, 25 January 2016

Info class startupPost()

we have info class and there we have a method called startupPost() this is the first method which opens when AX open.

Say we want to display some message  or greeting for the user once he opens the AX then we have to fo to this class and this method startupPost()  we have to write a infolog in this method.

Sunday, 10 January 2016

Job for creation of user by x++

this job will create a user in ax 2012

static void Usercreation(Args _args)
{
    UserInfoHelp            userInfoHelp;
    UserAdAddManager        userManager;
    int                     i;
    UserInfo                userInfo;

    Microsoft.Dynamics.IntegrationFramework.Util    util;


    userInfoHelp        = new UserInfoHelp();
    util                = new Microsoft.Dynamics.IntegrationFramework.Util();

    userInfo.company    = "USMF";
    userInfo.enable     = NoYes::Yes;
    userInfo.name       = "Rohit";
    userManager         = UserAdAddManager::construct();

    userInfo.accountType    = UserAccountType::ADUser;
    userInfo.language       = LanguageTable::defaultLanguage();
    userInfo.networkAlias   = "naresh.k";
    userInfo.networkDomain  = "ANT.COM";
    userInfo.id             = userInfo.networkAlias;
    while (userManager.validateInitialUserId(userInfo.id) == false)
    {
        i ++;
        userInfo.id         = userManager.generateInitialUserId(userInfo.id, i);
    }
    userInfo.sid            = util.GetUserSid(userInfo.networkDomain, userInfo.networkAlias);
    userInfo.insert();
    info("done");
}

Friday, 8 January 2016

str2enum

         str   Accountcode = "Table";
       SuppItemTable.AccountCode = str2Enum(TableGroupAll, Accountcode);

here Accountcode is a string and  is a base enum.

Wednesday, 6 January 2016

PO creation by ax web service for multiple lines

void createPO()
{
TxtPoStaging poStaging, poStagingLine, poStagingError;
TxtPoStaging poStagingLineQtyChk;
VendAccount vendor;
PurchTable purchTable;
PurchLine purchLine;
VendTable vendTable;
AxPurchTable axPurchTable;
AxPurchLine axPurchLine;
sParameters sParamaters;
InventDim inventDim;
//boolean poInvoiced;
//boolean registerIMEI;
boolean poLineCreate;
//DmsMdmOrderReasonParameter orderReasonParam;
ProductConfigView productVariantsPerCompany;
EcoResConfiguration configuration;
ItemId itemId;

while select poStaging
group by CompInvNo, CompInvDate, DistCode, PurchaseOrder
where poStaging.Processed == NoYes::No
&& poStaging.Error == NoYes::No
&& poStaging.DistributionChannel == @'YPN1'
{

changeCompany(CompanyInfo::findByDmsPartnerCode(poStaging.DistCode).DataArea)
// changeCompany(curDataArea)
{
try
{
info(curext());
poLineCreate = false;
vendor = DmsParameters::find().DefaultVendor;
vendTable = VendTable::find(vendor);
if(!vendor && !vendTable)
throw error("@DMS2408");
dmsParamaters = DmsParameters::find();
ttsBegin;
purchTable.clear();
purchTable.initFromVendTable(vendTable);
axPurchTable = axPurchTable::newPurchTable(purchTable);
axPurchTable.parmPurchaseType(PurchaseType::Purch);
axPurchTable.parmDocumentStatus(DocumentStatus::PurchaseOrder);
axPurchTable.parmAccountingDate(systemDateGet());
axPurchTable.parmDeliveryDate(systemDateGet());
axPurchTable.parmPurchStatus(PurchStatus::Backorder);
axPurchTable.parmInventSiteId(dmsParamaters.Site);
axPurchTable.parmInventLocationId(dmsParamaters.Warehouse);
axPurchTable.doSave();
purchTable.selectForUpdate(true);
purchTable.DmsDOReferenceNumber = poStaging.CompInvNo;
purchTable.DmsDOReferenceDate = poStaging.CompInvDate;
purchTable.update();
setPrefix(strFmt("@DMS2617",poStaging.CompInvNo));
setPrefix(strFmt("@DMS2407",purchTable.PurchId));
//create PurchLine
while select * from poStagingLine where
poStagingLine.CompInvNo == poStaging.CompInvNo &&
poStagingLine.CompInvDate == poStaging.CompInvDate &&
poStagingLine.DistCode == poStaging.DistCode &&
poStagingLine.PurchaseOrder == poStaging.PurchaseOrder &&
poStagingLine.DistributionChannel == @'YPN1' &&
poStagingLine.Processed == NoYes::No
{
poLineCreate = true;
//Item Id
//itemId = InventTable::findByProduct(EcoResProduct::findByDisplayProductNumber(DmsSkuDetailsTable::findBySkuCode(poStagingLine.SkuCode).ProductCode).RecId).ItemId;
itemId = InventTable::findByProduct(EcoResProduct::findByDisplayProductNumber(DmsProductSKUMapping::findProductbySkuCode(poStagingLine.SkuCode)).RecId).ItemId;
if(!itemId )
throw error("@DMS2641");
poStagingLine.selectForUpdate(true);
poStagingLine.ProductCode = itemId;
poStagingLine.update();
//Product dimension
select InventDimId,RetailVariantId,ItemId,Configuration
from productVariantsPerCompany
where productVariantsPerCompany.ItemId == poStagingLine.ProductCode
join configuration
where productVariantsPerCompany.Configuration == configuration.RecId
&& configuration.Name == poStagingLine.OrderReason;
if(productVariantsPerCompany.InventDimId)
{
inventDim = InventDim::find(productVariantsPerCompany.InventDimId);
inventDim.InventSiteId = purchTable.InventSiteId;
inventDim.InventLocationId = purchTable.InventLocationId;
}
else
throw error("@DMS2457");
purchLine.clear();
purchLine.initFromPurchTable(purchTable);
axPurchLine = AxPurchLine::newPurchLine(purchLine);
axpurchLine.parmItemId(poStagingLine.ProductCode);
axPurchLine.parmPurchQty(poStagingLine.IndentQty);
axPurchLine.parmPurchUnit(InventTableModule::find(poStagingLine.ProductCode,ModuleInventPurchSales::Invent).UnitId);
axPurchLine.parmInventDimId(InventDim::findOrCreate(inventDim).inventDimId);
axPurchLine.parmPurchReceivedNow(poStagingLine.IndentQty);
// axPurchLine.parmPurchPrice(InventTable::find(poStagingLine.ProductCode).purchPcsPrice());
axpurchLine.parmVariantId(productVariantsPerCompany.RetailVariantId);
//For price - 16112015
priceMarginModel = new DmsProductPriceMarginModel();
purchprice = priceMarginModel.calculateProcessPurch(itemId,vendor);
axpurchLine.parmPurchPrice(purchprice );
axpurchLine.parmLineAmount(poStagingLine.IndentQty * purchprice);
//purchLine.PurchPrice = priceMarginModel.calculateProcessPurch(purchLine.ItemId, purchLine.VendAccount);
axPurchLine.doSave();
 
poStagingLine.selectForUpdate(true);
poStagingLine.PurchId = purchTable.PurchId;
poStagingLine.doupdate();
if( DmsSkuDetailsTable::findBySkuCode(poStagingLine.SkuCode).DmsSerialNumTracking)
{
select count(qty) from imeiDetailsQtyChk
where imeiDetailsQtyChk.Flag == NoYes::No
join poStagingLineQtyChk
where poStagingLineQtyChk.CompInvDate == imeiDetailsQtyChk.CompInvDate
&& poStagingLineQtyChk.CompInvNo == imeiDetailsQtyChk.CompInvNo
&& poStagingLineQtyChk.ProductCode == imeiDetailsQtyChk.ItemId
&& poStagingLineQtyChk.PurchId == purchLine.PurchId
&& poStagingLineQtyChk.ProductCode == purchLine.ItemId
&& poStagingLineQtyChk.Error == NoYes::No;
if(imeiDetailsQtyChk.Qty != purchLine.PurchReceivedNow)
{
throw error(strFmt("@DMS2394",imeiDetailsQtyChk.CompInvNo));
}
this.IMEInumInsert(purchLine,poStagingLine);
this.insSerialNumTable(purchLine,poStagingLine); //Only run when auto invoice will be done - 151015
}
 
 
}
//Register Serial number
//registerIMEI = this.registerIMEI(purchTable.PurchId, poStaging);
poLineCreate = false;
//Invoice PO
//if(registerIMEI)
//poInvoiced = this.invoicePO(purchTable);
//if(poInvoiced)
{
//this.serialNumTransInsert(purchTable.PurchId);
while select forUpdate poStagingLine where
poStagingLine.CompInvNo == poStaging.CompInvNo &&
poStagingLine.CompInvDate == poStaging.CompInvDate &&
poStagingLine.DistCode == poStaging.DistCode &&
poStagingLine.PurchaseOrder == poStaging.PurchaseOrder &&
poStagingLine.DistributionChannel == @'YPN1' &&
poStagingLine.Processed == NoYes::No
{
poStagingLine.Processed = NoYes::Yes;
poStagingLine.update();
}
}
ttsCommit;
update_recordSet imeiDetails
setting Flag = NoYes::Yes
join poStagingLine where
poStagingLine.CompInvDate == imeiDetails.CompInvDate
&& poStagingLine.CompInvNo == imeiDetails.CompInvNo
&& poStagingLine.ProductCode == imeiDetails.ItemId
&& poStagingLine.PurchId == purchTable.PurchId;
if(purchTable.PurchId)
info(strFmt("@DMS2535",purchTable.PurchId));
}
catch
{
 ttsAbort;//error log
}
}
}

}

intercompany PO multiple product receipt by x++

public void processStampICPO(PackingSlipId _deliveryNote,                             Transdate _deliverydate,                             ...