Tuesday, November 24, 2015

Creating a CSV File from Ax

Hi!

Now I am about to show you how create a CSV file in Ax 2012 R3.

First of all, we need to create an instance of the class CommaTextIo, a Container, and the reference to the #File macro.

 
01 static void CreateCSV(Args _args)
02 {
03     CommaTextIo file;
04     Container line;
05     InventTable inventTable;
06    #File
07
08    file = new CommaTextIo("c:\\users\\jarizmendi\\aCSVFile.csv", #io_write);
09    if (!file || file.status() != IO_Status::Ok)
10    {
11        throw error("File cannot be opened.");
12    }
13
14    while select * from
inventTable
15    {
16        line = [
inventTable.ItemId, inventTable.ItemName];
17        file.writeExp(line);
18    }
19    info("It works!!.");
20 }


Then, we need to create the CSV file in a specified directory, and finally, we need to write the data as lines 14 to 18 show.

I hope it helps!!

Friday, November 20, 2015

Updating Inventory Dimensions Group in Ax 2012

Hi!

If you need to change the Inventory Dimension Groups In Ax (StorageDimensionGroup and TrackingDimensionGroup), you could use this.

1  InventTable                     inventTable;
2  EcoResStorageDimensionGroup     ecoResStorageDimensionGroup;
3  EcoResTrackingDimensionGroup    ecoResTrackingDimensionGroup;

4 ;
5   inventTable                                      =   InventTable::find("anArticle");
6   ecoResStorageDimensionGroup     =   ecoResStorageDimensionGroup::findByDimensionGroupName("anotherGroup");

7   ecoResTrackingDimensionGroup   =   ecoResTrackingDimensionGroup::findByDimensionGroupName("anotherGroup");
8

9   InventTableInventoryDimensionGroups::updateDimensionGroupsForItem(
10            curext()

11           , inventTable.ItemId
12            , ecoResStorageDimensionGroup.RecId
13            , ecoResTrackingDimensionGroup.RecId
14            , inventTable.Product);
15 }

  

Line 1 to 4 declarations, line 5 to  7 finding the ItemId named "AnArticle" and the Storage Dimension Group and the Tracking Dimension Group, they both named "anotherGroup".

Line 9 performs the updateDimensionGroupsForItem of the class InventTableInventoryDimensionGroups.

Important!. There must not be physical movementsor financial movements pending for this item.


Monday, July 27, 2015

Using SysLastValue in Ax 2012 R3



We can save some prompt values in forms without using a table, in this post I will show you how you can use SystemLastValue.

1. Design a form (jcSysLastValue) with an editable field, in this case I used am ImventLocationId field.


2. We have to edit the classDeclaration as follows:

public class FormRun extends ObjectRun
{

    InventLocationId   inventLocationId;
    InventLocationId   inventLocationId2;

    #define.CurrentVersion(1)
    #define.version1(1)
    #localmacro.CurrentList
        inventLocationId,
        inventLocationId2
    #endmacro
}


3. Write the method initParmDefault() to set a default Value

public void initParmDefault()
{
;
    inventLocationId = "001";
}



4.  Define the methods pack and unPack()

public container pack()
{
    return [#CurrentVersion,#CurrentList];
}



public boolean unpack(container packedClass)
{
    int version     = RunBase::getVersion(packedClass);

    switch (version)
    {
        case #CurrentVersion:
            [version,#CurrentList] = packedClass;
            return true;
        default :
            return false;
    }

    return false;
}


5.  Define the methods lastValue....

public dataAreaId lastValueDataAreaId()
{
    return curext();
}



public identifiername lastValueDesignName()
{
    return '';



public identifiername lastValueElementName()
{
    return formStr(jcSysLastValue);
}



public UtilElementType lastValueType()
{
    return UtilElementType::Form;


public userId lastValueUserId()
{
    return curuserid();
}


6. Getting saved values and setting them to the field.

public void run()
{
    super();
    xSysLastValue::getLast(this);
    inventLocationId_text.text(inventLocationId);
}  


7. Saving values to somewhere  

public void close()
{
    super();
    inventLocationId = inventLocationId_text.text();
    xSysLastValue::saveLast(this);
}



If you want to clear the values just delete de follow record and that's it.




 

Wednesday, June 3, 2015

Consuming MySuite WebService in Ax 2012 R3 (Part 2)


Expanding the project.



Now, you have to restart Ax 2012 R3, this is an important step, if you ignore this then you will suffer.

 Finally the source code is the following



static void MySuiteCFDI(str Requestor,str Transaction, str Country,str Entity, str User,str UserName, str Data1, str Data2, str Data3)
{
    XMLDocument         xmlDoc;
    XMLWriter           writer;
    XMLNode             nodoxml;
    str                 nodo;
    str                 xml;
    XmlNamespaceManager nsmgr;
    str                 valor;
    str                 cadena[];
    str                 ret = '';

    ClrObject                       clientType;

    str strRutaXML; str strNomXML; str Transaction; str UUID = "";



    MySuiteCFDI.MySuiteReference.FactWSFrontSoapClient      c;
    MySuiteCFDI.MySuiteReference.TransactionTag             tag;
    MySuiteCFDI.MySuiteReference.FactResponseData           respuesta;
    MySuiteCFDI.MySuiteReference.FactResponse               respError;




    clientType = CLRInterop::getType("MySuiteCFDI.MySuiteReference.FactWSFrontSoapClient");




            new InteropPermission(InteropKind::ClrInterop).assert();

            c = AifUtil::createServiceClient(clientType);

                     tag=c.RequestTransaction(Requestor,Transaction,Country,Entity,User,UserName,Data1,Data2,Data3);

            respuesta = tag.get_ResponseData();
            respError = tag.get_Response();

            strErrorInfo = respError.get_Data();

            if(strErrorInfo == '')
            {
                doSomething (respuesta);
            }
            else
            {
                Throw error(strErrorInfo);
            }
            CodeAccessPermission::revertAssert();
}