figure out the calling process

We are introducing some custom code in salesLine table’s insert method. However, we want to execute this code only when the sales lines are being inserted using the AX rich client and not when we are using other methods such as AIF.

Is there a way to figure out the calling process inside the salesLine table’s insert method?

Thank you.

There are some options, but it really depends on what exactly you’re trying to achieve. Please tell us more.

Well, when a rich client is used to enter sales orders, we do a couple of things:

  1. we delete the original sales line and replace it with multiple sales lines of component items because the original item is a “kit”

  2. For each of these exploded lines, we like to change the site/warehouse per some algorithm

The switching of site/warehouse is applicable only when the order is entered from the AX rich client.

I hope that gives you enough information.

This should be handle by your business logic and not some crazy hack detecting the type of client.

Call your logic only when you need it, therefore remove it from insert() and put it into a more appropriate place.

The first part was done before my time. So, the salesLine.insert() has already been modified. I don’t have a choice now of removing the code from salesLine.insert(). All I’m trying to do is the second part. Any suggestions?

That insert() has already been modified is irrelevant. Now you have new requirements and you need different logic.

Your idea to base your business logic on the type of client is wrong. Please don’t add new bugs to your solution.

If you’re not allowed to do the implementation, move to a project where you actually can do your job.

I wish life was that simple Martin.

If I were to design it from scratch, I probably would create a class that does the explosion and insertion. I would then invoke that class from different clients. I don’t have that choice. I’m back to my original question.

http://stackoverflow.com/questions/21748001/how-to-check-caller-is-ep-in-x gives me a way to identify a GUI client, something that serves my purpose. I was wondering whether I could rely upon this method.

If you’re not allowed to do necessary changes, you’ll have to tell them that the logic can’t be implemented unless the situation changes.

You can’t ever rely on the type of client. Today the action is done only from GUI, but tomorrow it may be done by a batch, through Excel add-in, by a web service… You would also end up with extremely fragile code, expensive to maintain. You may be unable to upgrade it to AX 7. And so on and so on.

Don’t help to build another failed implementation. It would be bad both for the customer and for your reputation.

I agree with you wholeheartedly. Thank you for your insights.