How to replace default App-Open with Customization

Maybe someone with a few more brain cells will pop in later with an easier and less hacky solution.

Now that I think about it, we should be able to restrict it to just the one place called from.
I think I already did that, gotta check who called it.

If you don’t figure it out first, I’ll look at that later. Gotta go get about 4 inches of mop cut off
my head before Insights.

I’m getting somewhere…

if (request.id == "Erp.UI.EndActivityEntry" && request.properties.mode != "AppStudio" && request.properties.additionalContext.ContainsKey("menuId"))

The mop is gone, but it looks like I’m not needed. :tada:

It worked!
Celebrate Doc Brown GIF by Back to the Future Trilogy

Incredibly, it worked on the first attempt.

/// The following BPM script applies Kinetic UI layers to a MetaFX GetApp request.
/// Business Object: Ice.Lib.MetaFX
/// Method: GetApp
/// BPM Type: Pre-Processing

// Kinetic UI App/Resource Name
var requestID = "Erp.UI.EndActivityEntry";

// Only modify the request if:
// It matches the desired Request ID
// It is not in 'AppStudio' mode
// It contains a 'menuId' property. This is required to look up the Menu item from the database.
if (request.id == "Erp.UI.EndActivityEntry" && request.properties.mode != "AppStudio" && request.properties.additionalContext.ContainsKey("menuId"))
{
  // Get the Menu ID from the request.
  var menuID = (string)request.properties.additionalContext["menuId"];
  
  // Get the existing Layer Names from the request. Convert to a list so we can add items.
  var layers = request.properties.layers.ToList();

  // Get the Menu Item from the database, preferring the company-specific menu item.
  var menuItem = Db.Menu.Where(x => x.MenuID == menuID).OrderByDescending(x => x.Company == callContextClient.CurrentCompany).FirstOrDefault();
  
  if (menuItem != null)
  {
    // Get the URL parameters from the Menu Item
    var parameters = menuItem.WebResourceURL.Split('?')[1].Split('&');
    
    // Get the Layer Names parameter, and get an array of layer names.
    var layerNamesParameter = parameters.FirstOrDefault(x => x.StartsWith("layerNames"));
    var layerNames = layerNamesParameter?.Split('=')[1].Split(',');
    
    // Loop through the layer names and if it does not already exist in the list, add it.
    foreach (var layerName in layerNames)
    {
      if (!layers.Contains(layerName))
      {
        layers.Add(layerName);
      }
    }
    
    // Replace the layers in the request with our new list
    request.properties.layers = layers.ToArray();
  }
}

Thank you @klincecum for pointing me in the right direction.

2 Likes

ehhh… :dumpster_fire:

I likes the way you code.
Noice Thats Nice GIF

I must be blind, but I can’t find the Ice.Lib.MetaFX in the Method Directive search.

Can you guide me? I really like how you handled this using a BPM.

image

It should be available in System Code: ICE, Type: Simple Service, Service Name: MetaFX

image

Mike, when you did this with Start Production in MES, did you handle disabling your new button if the user was not logged in yet ?

(I am doing the same thing, and can’t seem to get the disable/enable correctly setup)

You can try a condition on the button click with the parameter
%LaborHed.hasRow%

Here is an example from my Report Quantity button for the detail