-->

Add custom text to AX 2012 drill-down links

2019-09-09 09:23发布

问题:

I want to customize the standard drill-down functionality and add a text parameter to the drill-down URL. I will then parse and use the parameter in the SysStartUpCmdDrillDown or EventDrillDownPoller class like the solution provided by Jan B. Kjeldsen in this question.

The standard drill-down link is dynamics://Target/?DrillDown_RecID/ :

dynamics://0/?DrillDown_5637230378/

In previous versions of AX it was possible to modify the RecId to custom text and parse the text once the client is started:

dynamics://0/?DrillDown_0MenuItemName=PurchTable&FieldName=PurchId&FieldValue=P000044

Unfortunately, in AX 2012 the RecId is checked before the client is started and if it is not a valid int64, the drill-down event is not sent to the client. Since it is not possible to change the RecId to anything other than an integer, @Alex Kwitny suggested in the comments at that same question that you can add the custom text to the drill-down target like this:

dynamics://0MenuItemName=PurchTable/?DrillDown_5637230378/

The problem I experience with this is that the link now gets confused about which instance to start.

If the target is equal to the value in the System Admin -> system parameters -> Alerts ->Drill-down target, a client with the correct server instance is started. When I append the text with my custom text, it always starts the default instance(Which could be different from the instance I intended to start). While this is not ideal, I could work around this issue.

The bigger problem is that it now always starts a new session of the default instance, even if a client session is already started. As far as I can see I cannot write X++ code to solve this issue since the server instance is determined before any code in the client is executed.

My question is this - How can I add custom text to the drill-down link while preserving the way the client instance is started: If a client for the instance is already open, it should process the link in the open client, and not start up a new client of the default instance.

回答1:

You should probably come up with another solution as mentioned in this post, but there could still be a way.

The URL has two objects that can be modified:

dynamics://[Drill-down target(str)]/?Drilldown_[Int64]

According to you, if you modify the [Drill-down target], then it launches AX using the default client config, and that is behavior that you don't want. If you have a matching [Drill-down target], it'll launch in the open client window, which is behavior I can't confirm, but I'll take it at face value and assume you're correct.

So that means the only thing you can modify in the URL is [int64]. This is actually a string that is converted to an int64 via str2int64(...), which in turn corresponds to a RecId. This is where it gets interesting.

This work all happens in \Classes\SysStartUpCmdDrillDown\infoRun.

Well, lucky for you the ranges for the objects are:

  • RecId - 0 to 9223372036854775807
  • Int64 - -9223372036854775808 to 9223372036854775807

You can call minRecId() and maxRecId() to confirm this.

So this means you have -9223372036854775808 to -1 numbers to work with by calling URLs in this range:

  • dynamics://0/?DrillDown_-1
  • to
  • dynamics://0/?DrillDown_-9223372036854775808

Then you would modify \Classes\SysStartUpCmdDrillDown\infoRun to look for negative numbers, and fork to your custom code.

HOW you decide to user these negative #'s is up to you. You can have the first n-digits be a table id or a look-up value for a custom table. You can't technically use a RecId as part of that negative number because in theory the RecId could get up that high (minus 1).