Dynamics AX
  RSS Feed  LinkedIn  Twitter
Want to turn you're data into a true asset? Ready to break free from the report factory?
Ready to gain true insights that are action focused for truly data informed decisions?
Want to do all of this across mutliple companies, instances of Dynamics and your other investments?
Hillstar Business Intelligence is the answer then! (www.HillstarBI.com)

Hillstar Business Intelligence for Microsoft Dynamics AX and NAV on Mobile, Desktop, Tablet


Let us prove to you how we can take the complexity out of the schema and truly enable users to answer the needed questions to run your business! Visit Hillstar Business Solutions at: www.HillstarBI.com

Sunday, December 11, 2011

AX 2012 - Using the PricePriceDiscJournalService





I hope everyone is enjoying their weekend. I hope you have gotten some downtime, and are ready to kick off a new week! To help get things started right this week, I thought I would give some specific focus to one of the out-of-the-box services that comes as part of Dynamics AX 2012.

The service I'm talking about, is the PricePriceDiscJournalService

This service is what you should use, when needing to work with Trade Agreements, via code, inside or outside of AX 2012. As I've mentioned before, around the topics of Services, document services should be used internal and external of AX 2012, as much as possible. This services abstraction has benefits now, with AX 2012 and what comes with the AIF Document Framework. It also holds values, for the future, as Dynamics ERP scales to Azure with AX 7.0, and beyond.

With this in mind, we need to then start with how to use this service, from within AX itself, via X++ code. We have reviewed a similar topic before, in which I talked you through the consumption of the EcoResProductService.



Working with the PricePriceDiscJournalService is similar, in the type of objects you need to create, and make use of. All, relating and apart of the AIF Framework.

There is a functional setup part to this service, in which needs to be understood for proper execution. With AX 2012, Trade Agreements, for Sales Prices, Discounts, etc. must be first created as a Journal, and then posted. Since this is the functional workflow, and therefore functional requirement, AIF has to know which price journal name should be used, during the operations of the service.

This is enabled through the setup parameters, of the Procurement & Sourcing Module. You can navigate to this location, by going to Procurement & Sourcing > Setup > Procurement & Sourcing Parameters. In navigating to this location, there is an AIF smart tab, that appears on the left hand of the parameters form. Clicking on this, will take to you where you select which Journal Name to make use of.



The possible overlooked value in this setup, and use of a default journal for AIF price entries, is it can allow for a degree of separation. In that, the ability to have easily all the prices and discounts that are coming in through AIF, can be separated from other price journals.

Now having this set, we can now move forward with our use of the PricePriceDiscJournalService. In order to show this off, lets start with a simple job, in a new project. This job, will be what shows off our X++ example code.



Now that we have our job, lets take a look at the following code, and break it down for it's use.

static void idbExecutePricPriceDiscJourSvcJob(Args _args)
{
// PricePrice Vars
PricePriceDiscJournalService PriceDiscSvc;
PricePriceDiscJournal PriceDiscJour;
PricePriceDiscJournal_PriceDiscAdmTrans PriceDiscJourAdmTrans;
PricePriceDiscJournal_InventDim PriceDiscJourDim;

// keys return from create process
AifEntityKeyList keys;

// Instantiate the objects
PriceDiscSvc = PricePriceDiscJournalService::construct();
PriceDiscJour = new PricePriceDiscJournal();
PriceDiscJourAdmTrans = PriceDiscJour.createPriceDiscAdmTrans().addNew();
PriceDiscJourDim = PriceDiscJourAdmTrans.createInventDim().addNew();

// Set PriceDiscJourDim
PriceDiscJourDim.parminventDimId(InventDimCombination::
findByDistinctProductVariant(
EcoResProduct::findByDisplayProductNumber(
"SomeProductVariant").RecId)
.InventDimId);

// Set PriceDiscJourAdmTrans
PriceDiscJourAdmTrans.parmInventDim().add(PriceDiscJourDim);
PriceDiscJourAdmTrans.parmItemRelation("SomeProduct");
PriceDiscJourAdmTrans.parmItemCode(TableGroupAll::Table);
PriceDiscJourAdmTrans.parmAmount(100.00);
PriceDiscJourAdmTrans.parmFromDate(today());
PriceDiscJourAdmTrans.parmAccountCode(TableGroupAll::All);
PriceDiscJourAdmTrans.parmrelation(PriceType::PriceSales);
PriceDiscJourAdmTrans.parmCurrency("USD");

// Post PriceDiscJour
keys = PriceDiscSvc.create(PriceDiscJour);
}


With the above code, we can see that we are now working with the PricePriceDiscJournalService, and using the AIF Entity objects, in order to create a Price Journal, that represents a ready to be reviewed, and posted Trade Agreement.

Just to break down, first we start off we Instantiate an instance of the needed objects. This includes the service, PriceDiscSvc. Also, the PriceDiscJour , PriceDiscJourAdmTrans & the PriceDiscJourDim. All of which are a part of the AIF Framework. The PriceDiscJour extends from AIFDocument, as the other two PriceDiscJourAdmTrans & PriceDiscJourDim extends from the AfStronglyTypedDataContainer class.

These are critical in filling out the information needed, for the PricePriceDiscJournalService to properly create a brand new Trade Agreement journal.

From here we can see that I fill the PriceDiscJourDim first, as it is then added tot he PriceDiscJourAdmTrans. This is then filled in the rest of the way, and in turn itself ias added to the PriceDiscJour object.

Finally the PriceDiscJour Object, is sent as the needed variable for calling the create() service operation of the PricePriceDiscJournalService, represented by the PriceDiscSvc variable within the example code.

With this, we can now create Price Journals, that can be reviewed and posted. These can be viewed from the Procurement & Sourcing Module > Journals > Price / Disc. Agreement Journals.



Well that's all for this post. I hope you have enjoyed it, and find it useful. Moving forward from here, if your importing data, and not needing a review the next step would be to post the journal, after the creation of it. That, is a nice little topic for a future post.

Till next time!



Visit Hillstar Business Intelligence (www.HillstarBI.com) in order to truly unlock your data trapped in your Microsoft Dynamics investment. With our value driven business intelligence strategy Hillstar help you transform into a data informed company.


"Visit the Dynamics AX Community Page today!"


Labels: , , , , , , , , , , ,

4 Comments:

Anonymous Tim Schofield said...

Hi Brandon. Nice post. Thank you.
Can the Price/Discount journal be imported from Excel? Can we use the Dynamics AX tab in Excel to create and publish the Price/Discount journal into AX?
Thanks
Tim

9:02 PM  
Blogger Ezhik's Blog said...

Thanks for this helpful topic! How can I create multiple lines in one journal? If I try to do a second call to the "PriceDiscJour.createPriceDiscAdmTrans().addNew()" an exception is thrown "data item already exists".

5:57 AM  
Blogger Aman Nain said...

Facing the same issue. Need to have multiple lines in one journal. Second call to "PriceDiscJour.createPriceDiscAdmTrans().addNew()" throws error "Data item PriceDiscAdmTrans already exists"! Any idea?

2:35 AM  
Blogger Aman Nain said...

You can use something like below
journalLineCollection = PriceDiscJour.createPriceDiscAdmTrans();


//----------------Line1---------------------//
PriceDiscJourAdmTrans1 = journalLineCollection.insertNew(1);

6:05 AM  

Post a Comment

<< Home


Copyright 2005-2011, J. Brandon George - All rights Reserved