Alfasith AX

Alfasith AX
اللَّهُمَّ انْفَعْنِي بِمَا عَلَّمْتَنِي، وَعَلِّمْنِي مَا يَنْفَعُنِي، وَزِدْنِي عِلْمًا

Monday, December 30, 2013

An unbalanced X++ TTSBegin/TTSCommit pair has been detected .Cause of this include (a) too many/few TTSBegin or TTS Commit - Dynamic AX

Hi,

An unbalanced X++ TTSBegin/TTSCommit pair has been detected .Cause of this include (a) too many/few TTSBegin or TTS Commit . The current TTS level is '1'

Just run this job and go head with your work above error will not come.

static void AlfasithResetTTS(Args _args)
{
while (appl.ttsLevel() > 0)
ttsAbort;
}

Enjoy

Thursday, December 26, 2013

Monday, December 9, 2013

How to get navigation path in Dynamic AX

Hi,

Please note that there is no navigation path as I highlighted. 
 2.Go to concern menu and select particular menu.
 3. Change the properties as Yes to IsDisplayedInContentArea
4.Then Look like this as per the menu position.
Regards,

Data filtration in dialog box In Microsoft Dynamics AX

public class CustAmountCalculation extends RunBase
{
    DialogField fieldAccount;
    CustAccount custAccount;

}

    public Object dialog()
{

    Dialog dialog;
    DialogGroup groupCustomer;
    dialog = super();
    fieldAccount = dialog.addField(extendedTypeStr(custAccount), "CustomerAccount");
    return dialog;
}

    public boolean getFromDialog()
{
    custAccount = fieldAccount.value();
    return super();
}

    public container pack()
{
    return conNull();
}


    public void run()
{
    CustTable custTable;
    CustTrans custTrans;
    ;

    select sum(AmountMST) from custTrans where custTrans.AccountNum == custAccount;
    info("You have enetered customer information");
    info(strfmt("Account: %1", custAccount));
    info(strFmt("Amount: %1", custTrans.AmountMST));
}

    public boolean unpack(container _packedClass)
{
    return true;
}

    public static void main(Args _args)
{
    CustAmountCalculation custAmountCalculation = new CustAmountCalculation();
    if (CustAmountCalculation.prompt())
    {
        CustAmountCalculation.run();
    }
}

http://stackoverflow.com/questions/14501722/how-to-filter-lookup-values-on-a-dialogfield-in-report-dialog-based-on-another-d/20472542#

List of data validation methods on table level in Dynamic AX

The validation methods allow the programmer to verify that certain conditions are fulfilled before an action is executed.
In Axapta, methods of validation at two levels can be programmed:
1.                  Table
2.                  Origin of data of a form
It is important to know that the methods of validation of the tables are executed whenever they are introduced or erase registries. Whereas if the validation is made in the form, it will only work when we are working with that form.
1.                  Whenever it is possible, the validation of data must be made in the table.

Methods

The methods of validation in tables are the following ones:
ValidateField
It is executed when we move the cursor from a field from the form to another one, that is to say, when we left a field. It gives back a data of boolean type. If the result is false, the cursor will remain in the field.
The call to the super method () verifies the validation relations, that is to say, relations in a field where the Validate property has affirmative value. Therefore, we must respect the task made by this super method ().
1.                  Validations do not have to be codified that can be made with some property. Thus, we will avoid to write code in the ValidateField method if the conditions can be verified with the Validate property of a relation.
ValidateWrite
It is executed before inserting or updating a registry in the table. It gives back a data of boolean type. If it gives back false, the registry is not inserted or updates.
The call to the super method () examines all the fields to verify the value of the Mandatoryproperty. Therefore, we must respect the task made by this super method ().
1.                  We will avoid to introduce code that it verifies if a field has value, whenever we pruned to use the Mandatory property.
ValidateDelete
It is not necessary to forget, that often also we want to verify certain conditions before erasing a registry of a table. In order to do this, we used the ValidateDelete method ().
ValidateDelete () is called automatically from forms and is used to verify if the present registry can be erased.
The call to the super method () verifies if there are registries related in tables toDeleteActions of the Restricted type. If that is the case, the super method () gives back false. Therefore, we must respect the task made by this method.
1.                  Whenever we pruned to use a DeleteAction, we will avoid to introduce code in the ValidateDelete method.

Structure of the validation methods

In order to maintain a good structure of programming, he is recommendable that the code for the verifications is not located directly in these methods of validation. It is more advisable than we create verification methods that will be called from the methods of validation previously described.

Example of validation method
Boolean validateWrite ()
{
Boolean ret;
ret = checkSomething () && checkSomethingElse ();
return ret;
}
When some of the conditions is not fulfilled, the verification method must make two things:
1.                  to present/display to the user an error message
2.                  to give back the false value like result
The CheckFailed method (`Message of error') writes the text chain that receives as parameter in the information window (Infolog) and gives back the false value. Therefore, by means of the use of this method, we obtained simultaneously both objective.

Example of use of CheckFailed
Boolean checkSomething ()
{
Boolean ret;
if (! something)
{
ret = checkFailed (`Something is wrong');
}
return ret;
}
We could use the previous structure, but cases exist in which it interests to us to verify the same Something condition, present in the CheckSomething method (), without presenting/displaying no message to the user. In this case we would need an additional method, that verified the condition but that it did not show any message.
Nevertheless, this would not be very efficient, because we would be duplicating the verification code, therefore is more recommendable to create a called method Something (), to which we will be able to call when we want, that it will be in charge to make this verification.
We will have, in addition, to change the CheckSomething method (), so that it makes a call to this new method. The CheckSomething method () we will use it solely when we want to show a message the user.

Example of complete validation
Boolean something ()
{
if (! something)
{
return false;
}
return true;
}
Boolean checkSomething ()
{
Boolean ret;
if (! something ())
{
ret = checkFailed (`Something is wrong');
}
return ret;
}

We can consider a standard of nomenclature of Axapta, the use of the Check area code, in the name of all those methods that make a call to the global method CheckFailed (). Of this form we will know what methods present/display messages in the Infolog window.

Friday, December 6, 2013

what is the difference between index and indexhint in select statement in Dynamic AX

Hi,

While fetching data from the database we use select statement and for better performance in data fetching we use an index/indexhint.

Index: when we use index in select statement it implies that the declare index field should behave as an order by and it is optional for the database to use. Database can use its own preference.

Index hint: it force the DB to use that index for fetch the data whether it is right choice or not

Regards,

Monday, December 2, 2013

The SQL server reporting Service service is running -SSRS 2012

Solution for this error: 
The deployment was cancelled because of an error:
On the reporting server, |Verify that
The SQL server reporting Service service is running

Solution:

1. Check Local business connector is optimum/ correct.
2. Check Domain business connector is optimum/ correct.
3. Put increment CIL
Now deploy it will be deployed.
Regards,\

Tuesday, November 26, 2013

Adding image through external resource for Dynamic AX 2012

How to use resource files in Axapta

In AOT, you can find resources node

Select resources node and right click; select Create from File, specify the file location for the new resource 

file. After that you can use this resource file in Axapta without specifying an absolute file path in your 

local/server system.

First, pick up the resource node from AOT;

SysResource::getResourceNode(); 

Then generate a temporary file for this resource file;
SysResource::saveToTempFile() 

Finally specify the temporary file path for controls. 

Here comes an example to show how to use a resource file as a background image of  a given form. 

{
ResourceNode            resourceNode;
FilePath  imagename;
;
resourceNode = SysResource::getResourceNode(resourcestr(ResourceName));
if (resourceNode)
{
resourceNode. AOTload();
imagename =  SysResource::saveToTempFile(resourceNode);
}
else
{
throw Error(“No file exists.”)

element.design().imageName(imagename); 
}

Example:

You can try "Resources" node to achieve your requirement.
Just Add a new resources under "Resources" node in AOT, than use following X++ code to access that image..
SysResource::getResourceNodeData(SysResource::getResourceNode('theaxapta_File'));

How to give null/ space if the values is zero in SSRS 2012

Hi,
 Just enter the syntex as expression for SSRS
=iif(Fields!FieldName.Value > 0,  Fields!FieldName.Value,  space(0))

Regards,

Monday, November 18, 2013

update_recordset , insert_recordset, Delete records and select record of SQL in Dynamic AX 2012


//Select query in Dynamic AX 2012
 MyTable myTableBuffer;
;
Select myTableBuffer
where field1 == 0;
//use while select for multiple select

// Update query in Dynamic AX 2012

MyTable myTableBuffer;
;
update_recordset myTableBuffer
setting
    field1 = 1,
    field2 = fieldX + fieldY
where field1 == 0;

//Delete query in Dynamic AX 2012
 
static void DeleteMultiRow1aJob(Args _args)
{
    MyWidgetTable tabWidget;
    ;
    delete_from tabWidget
        where tabWidget .quantity <= 100;
}
 

// Insert query in Dynamic AX 2012
insert_recordset myTable (Field1, Field2)
    Field1= “QWERTyuioP”
Field2 = “ASDFghjkl” ;
 


Thursday, November 14, 2013

To take complete back up of SQL in single code

DECLARE @name VARCHAR(100)
DECLARE @path VARCHAR(256)
DECLARE @fileName VARCHAR(256)
DECLARE @fileDate VARCHAR(20)
SET @path = 'G:\BACKUP'
SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112) + '_' +REPLACE(CONVERT(VARCHAR(20),GETDATE(),108),':','')
DECLARE db_cursor CURSOR FOR
SELECT name
FROM master.dbo.sysdatabases
WHERE name NOT IN ('master','model','msdb','tempdb')
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @name
WHILE @@FETCH_STATUS = 0
BEGIN
SET @fileName = @path + @name + '_' + @fileDate + '.BAK'
BACKUP DATABASE @name TO DISK = @fileName
FETCH NEXT FROM db_cursor INTO @name
END
CLOSE db_cursor
DEALLOCATE db_cursor

Wednesday, November 13, 2013

AX2012 R2 Retail installation, DB profile, AOS profile and Commerce data syn service setups

Hi,

1. Architecture of the Microsoft Dynamics AX Retail 2012 R2 


We need to understand the modify architecture of Ax2012 R2 retail.  
Main Components
1.      Retail Headquarters.
2.      Commerce Data Exchange: Real-time Service (previously known as transaction service in Ax2009)
3.      Commerce Data Exchange: Synch Service.(previously known as Store connect in ax2009)
4.      Retail POS.
5.      .net Business connector.
Helping Component to do the configuration:
1.      Retail store database utility.
2.      Retail SDK.
3.      Retail online channel.
Open the Ax2012 R2 setup file and run (Before that Ax2012 R2 basic application should be install in your m/c).





Provide the name of the store DB and configure.
Same way do it for offline store DB.
Error: While configuring synch service you might get the following error.



Solution: Don’t configure the Synch service in setup time do it manually after successfully installation of all the retail components.
Go to the Programs>MicrosoftDynamicsAx2012> Retail store database utility
Open it and provide the below information to configure the store.



Don’t try to configure the offline DB after this because it will throw you an error.
Error: Store can’t not be found.
Reason: There is no data at this moment in the Store DB.
Configure the Synch service.
Go to the Programs>MicrosoftDynamicsAx2012> Retail synch service setting.
When you click add the server, it will prompt with Create a message database.
It will ask the database location and credential.
After successfully create of message DB, start the service and do the below setup.







Check that all the services are running stage or not.


Error: Sometime the Synch service shows starting stage and it remain unresponsive You can’t stop/start the service from here.
Solution: Go to the Task Manager and check the Service Processor ID.
Stop it from here and start.


Open Ax2012 R2 application do the following setup:
1. GO to the Retail>setup>Retail Scheduler>Channel integration.
Open AOS Profile

2.Open the Database profiles.


3.open the Synch Service.

  

Sometime we will get the following issue while doing test connection check.

 Reason:
Synch service is not started or we are not pointing the right Synch service or firewall related issue.
Check the setup and see the event viewer for more details.
Go to the System Administration>setup>Initial checklist>
 Go through all the step, main important is the schedule redeployment.
If it fails to insert certain data in some specific tables of Retail Store db, then we need to do it manually.


Go to the Retail>Periodic>Distribution schedule
Run the N-jobs
3 mandatory jobs need to be run 1st
1. N-1095
2. N-1090
3. N-1070
Then what are N- jobs you want to run ,run directly.
 Please check the below status once run the job.

Go to the Programs>MicrosoftDynamicsAx2012> Retail store database utility Open it and provide the below information to configure the store.
Configure offline DB.



You are ready to open the POS.
To configure the real time service you can follow the below link, it is quite helpful.
But I like to add some common troubleshooting on top of the above post which I faced while creating the web service.
 When you open the windows power shell open with Administrator and never use x86 power shell. Otherwise unable to install the Script in powershell, everytime it will fail.
 Enter Set-ExecutionPolicy Unrestricted –Force before the start any installation .\InstallCommerceDataExchangeRealtimeService.ps1
3.                 Be careful with Binary source path.
a.     C:\Program Files (x86)\Microsoft Dynamics AX\60\Commerce Data Exchange\Real-time Services\6.2\  \
4.                         ServerCertificateThumbprint
        You should remove the spaces from the 40-character string. Every time enter the value manually. Otherwise you will face the issue while opening the web service.
If you successfully install and configure the web service it should open like below.


For any other errors please check the below link.
  Configuring the Real-time Service in Retail Headquarters
Now that we have confirmed the Real-time Service Web service is working correctly, we need to configure it in Headquarters and push it down to the POS.
In Dynamics AX navigate to Retail > Setup > Retail scheduler > Channel integration > Real-time Service profiles.
As in previous versions, the Real-time Service profile is assigned to a specific register. Navigate to Retail > Setup > POS > POS registers and open a register. The profile you created should be assigned under General > Profiles:


Basic functional setup:
1. Do the setup of the Address book and a warehouse which is link with a store.



2.      Go CEU/Human resources/Common/Workers/Workers
Create your own worker.
Enter the Address books.
Go to the Retail Tab
Do the below mandatory setup.


Set the POS permission.

  




3.      Go to the retail store and create your own store.
CEU/Retail/Common/Retail channels/Retail stores


Add the worker in the store through employee address book.



Do the Setup of the Distribution Location under Retail>setup>retail scheduler 


Friday, November 1, 2013

Dynamics AX 2012 Reports services extension components installation-failed


Steps to resolve;


1. Open AOT > Services > SRSFrameworkService 
register it

It will clear or else
2. Open AOT > Services group > BIServices
Deploy it


Open AOT > Services group > UserSessionService
Deploy it
Now it will be cleared at last if not run complete (ful) CIL



Wednesday, October 30, 2013

Job / class /code to import the CSV / Excel file in to Vendor table in Dynamic AX 2012

Hi,

1.Prepare the CSV (If it was excel convert ti CSV)  file containing following fields in same order as below
account 
EnglishName 
English 
SearchName 
Invoice 
account 
VendorGroup 
Terms of payment 
Currency 
One-time supplier 
Country/region 
Delivery terms 
Mode of delivery 
Misc. charges group 
Buyer group

2. Create a class using below codes and just run by using |> run button or F5


/**********************************************/
public class VendorMasterImport extends RunBase
{
    CommaIo                     csvFile;
    Filename                    filename;
    DialogField                 dialogFilename;
    #define.CurrentVersion(2)
    #localmacro.CurrentList
    filename,
    insertIncorrectRecords,
    #endmacro
    #localmacro.ListVersion1
    filename,
    insertIncorrectRecords
    #endmacro
    #File
}
/************************************************/
public Object dialog()
{
    DialogRunbase       dialog = super();
    ;
    dialogFilename  = dialog.addField(extendedTypeStr(FilenameOpen));
    dialogFilename.value(filename);
    dialog.filenameLookupFilter(["All files", #AllFiles]);
    return dialog;
}
/**********************************************/
public boolean getFromDialog()
{
    filename                = dialogFilename.value();
    return true;
}
/**********************************************/
void run()
{
    //CommaTextIO                             csvFile;
    container                               readCon;
    counter                                 icount,inserted;
    Dialog                                  dialog;
    DialogField                             dfFileName;
    DirPartyRecId                           partyRecId,contactPartyRecid;
    Name                                    name,contactName;
    VendTable                               vendtable;
    str                                     contactperson;
    DirPartyPostalAddressView               addressView;
    DirPartyContactInfoView                 contactView;
    ContactPerson                           contactpersonTable;
    LogisticsElectronicAddressMethodType    enumType;
    DirContactPersonsService                dirContactPersonsService;
    DirContactPersons                       dirContactPersons;
    DirContactPersons_ContactPerson         dirContactPersons_ContactPerson;
    DirContactPersons_Person                dirContactPersons_Person;
    DirContactPersons_PersonName            dirContactPersons_PersonName;
    AifEntityKeyList                        aifEntityKeyList, aifEntityKeyList_DirContactPerson;
    str                                     fName, mName, lName;
    VendAccount                             vendorAccount;
    DirParty                                dirParty;
    LogisticsPostalAddress                  address;
    LogisticsElectronicAddress              logisticsElectronicAddress;
    BinData                                 binData;
    str                                     stringImage;
    LogisticsAddressStateID                 stateId;
    str                                     accountnum,accountName,vendgroup,currency,dlvmode,paymtermid,countryid,street,city,mobile,fax,email,zipcode,pobox,phone;
    CustInvoiceAccount  invoiceaccount;
    LogisticsAddressCountryRegionId  countryregion;

    NoYes               ontimecustomer;
    CustDlvTermId       termid;
    CustMarkupGroupId   chargegroup;
    ItemBuyerGroupId    buyergroupid;
    ;

    csvFile = new CommaIO(filename, 'r');
    try
    {
        if (csvFile)
        {
           // ttsbegin;
            readCon = csvFile.read();
            while (csvFile.status() == IO_Status::OK)
            {
                readCon = csvFile.read();
                if(readCon)
                {
                icount++;
                accountnum = conPeek(readCon,1);
                accountName = conPeek(readCon,2);
                    name = conPeek(readCon,3);
                invoiceaccount = conPeek(readCon,4);
                vendgroup = conPeek(readCon,5);
                paymtermid = conPeek(readCon,6);
                currency = conPeek(readCon,7);
                ontimecustomer = conPeek(readCon,8);
                countryregion= conPeek(readCon,9);
                termid=conPeek(readCon,10);
                dlvmode = conPeek(readCon,11);
                chargegroup = conPeek(readCon,12);
                    buyergroupid = conPeek(readCon,13);
                if(!name)
                break;
                partyRecId = DirPartyTable::createNew( DirPartyType::Organization, name).RecId;
                vendtable.clear();
                vendtable.initValue();
                vendtable.Party = partyRecId;
                vendtable.AccountNum = accountnum;
                vendtable.VendGroup  = vendgroup;
                vendtable.Currency   = currency;
                vendtable.DlvMode    = dlvmode;
                vendtable.PaymTermId   = paymtermid;
                vendtable.OneTimeVendor   =  ontimecustomer;
                vendtable.DlvTerm =termid;
                vendtable.DlvMode = dlvmode;
                vendtable.MarkupGroup = chargegroup;
                vendtable.InvoiceAccount = invoiceaccount;
                vendtable.ItemBuyerGroupId  = buyergroupid;
                if(contactperson != '')
                {
                    contactname = ContactPerson;
                    ContactPerson::findOrCreateNameParty(partyRecId,contactname);
                }
               vendtable.insert();
                stateId = subStr(stateId,1,25);
                address.PostBox = strLRTrim(PoBox);
                address.CountryRegionId = strLRTrim(Countryid);
                address.State = stateId;
                address.ZipCode = strLRTrim(ZipCode);
                address.Street  = strLRTrim(Street);
                address.county = countryregion;
                address.City    = strLRTrim(City);
                addressView.LocationName = name;
                addressView.IsPrimary = NoYes::Yes;
                addressView.Party = partyRecId;
                addressview.initFromPostalAddress(address);

                DirParty = DirParty::constructFromPartyRecId(addressView.Party );
                DirParty.createOrUpdatePostalAddress(addressView);

                inserted++;
                }
            }
        }
        icount--;//Remove header recount from total record count
    }
    catch(Exception::Error)
    {
        info(strFmt("%1 %2",Exception::Error,icount));
    }
}
/**********************************************/
static void main(Args  args)
{
    VendorMasterImport        VendorMasterImport;
    ;
    VendorMasterImport =  new VendorMasterImport();
    if(VendorMasterImport.prompt())
    {
        VendorMasterImport.run();
    }
}
/*************************************************/
3. Now you will find a browser like this.

4.Select CSV file and proceed.

Regards,

FileNameSplit() to slip the Directory, file name and extension in D365 FnO

 Hi,     /// <summary>     /// Validate the Fileformat     /// </summary>     /// <param name = "filepath">FileP...