How to check project budget amount through code in Dynamics AX 2012?
In my earlier post, I had shown how easy it is to enable budget control on projects. You can read that here.
I got a couple of questions on it and I thank my readers for the interest. I found one of the question to be very generic and the scenario described was something which many customers may be doing.
The scenario given was,
The customer creates a lot of project transactions on a daily basis but posting of them is done through a batch only on the month end.
So the customer has allocated an approved budget of 1000. We have 20 journals each with an amount of 100. Now we post these journals in a batch. So, after posting 10 journals, the whole budget will be exhausted. So from the 11th journal onwards, we will be receiving an error that budget will be exceeded by 100.
Now the question was, is there any way to know before hand while creating the transaction that there isn't a sufficient budget and hence the transaction will not be posted.
Well, it surely can be done with a little customization.
What we need to do is to get the budget amounts for the category of the project transaction being created and see if the amount is greater or equal to the line amount being posted. If the budget amount is less or zero, we throw an appropriate error to the user.
The project budget engine is driven by a class ProjBudgetTransactionManager. A method getBudgetForSelectedPeriod() is responsible to fetch the budget amounts for a gieven category in a given period. This method is declared private so we cannot access it from any of our classes. What I have done is duplicate the logic in my class.
I've added a menu item of my class to the hour journal lines form. Clicking on the menu button will perform a check and let the user know if the line can be posted or not.
You can customize this further to call the method in validateWrite() and stop the record from being saved. Or you can add a a window control and show an image if the line cannot be posted. It all depends on how you want to handle scenarios like these.
Different businesses have their own way of dealing with issues like these. Some customers prefer to catch the issue at the root level while others take some remedial actions when an issue is hit.
For those of you who are interested, the code for the changes required for this scenario can be downloaded here.
Hope this helps. Thats all for today folks, do check back soon for more.
I got a couple of questions on it and I thank my readers for the interest. I found one of the question to be very generic and the scenario described was something which many customers may be doing.
The scenario given was,
The customer creates a lot of project transactions on a daily basis but posting of them is done through a batch only on the month end.
So the customer has allocated an approved budget of 1000. We have 20 journals each with an amount of 100. Now we post these journals in a batch. So, after posting 10 journals, the whole budget will be exhausted. So from the 11th journal onwards, we will be receiving an error that budget will be exceeded by 100.
Now the question was, is there any way to know before hand while creating the transaction that there isn't a sufficient budget and hence the transaction will not be posted.
Well, it surely can be done with a little customization.
What we need to do is to get the budget amounts for the category of the project transaction being created and see if the amount is greater or equal to the line amount being posted. If the budget amount is less or zero, we throw an appropriate error to the user.
The project budget engine is driven by a class ProjBudgetTransactionManager. A method getBudgetForSelectedPeriod() is responsible to fetch the budget amounts for a gieven category in a given period. This method is declared private so we cannot access it from any of our classes. What I have done is duplicate the logic in my class.
I've added a menu item of my class to the hour journal lines form. Clicking on the menu button will perform a check and let the user know if the line can be posted or not.
You can customize this further to call the method in validateWrite() and stop the record from being saved. Or you can add a a window control and show an image if the line cannot be posted. It all depends on how you want to handle scenarios like these.
Different businesses have their own way of dealing with issues like these. Some customers prefer to catch the issue at the root level while others take some remedial actions when an issue is hit.
For those of you who are interested, the code for the changes required for this scenario can be downloaded here.
Hope this helps. Thats all for today folks, do check back soon for more.
Comments