Monday, February 24, 2014

Creating Custom AIF Service in Ax 2009 / 2012

Creating the below custom service to print the available physical quantity of particular item.

1. Creating a class 'InventOnHandService'

2. Create a method under this class 'itemOnHandPhysical'

//[SysEntryPointAttribute(true)]
public InventQty itemOnHandPhysical(ItemId  _itemId = '')
{
    SalesLine       salesLine;
    InventOnhand    inventOnHand;
    InventMovement  movement;
    InventQty       qty = 0;

    select firstOnly salesLine
        where salesLine.ItemId == _itemId;

    if (salesLine)
    {
        movement     = InventMovement::construct(salesLine);
        inventOnhand = InventOnhand::newPhysicalUpdate(movement,
                                                       movement.inventdim());

        qty          = inventOnHand.availPhysical();
    }

    return qty;
}

3. Create new service 'InventOnHandService'. Change the Class property to 'InventOnHandService'

4. Add Operation 'itemOnHandPhysical'.

5. To test the above custom service, create a job 'InventOnHandService_CustomService'

static void InventOnHandService_CustomService(Args _args)
{
    // Customer Service class
    InventOnHandService     inventService;
    inventQty inventQty;
    ;
    inventService = new InventOnHandService();
    inventQty = inventService.itemOnHandPhysical('1001');
    info(num2str(inventQty,0,2,1,1));
}

1 comment:

  1. hie, how do call this custom service from, say, a Console Application in VS 2010 ?

    ReplyDelete