Snippets

Edwin Marshall Link Template Formatter

Created by Edwin Marshall last modified
{
  "name": "link",
  "parameters": {
    "pathname": "/erp/sales-order/",
    "query": {
      "VBELN": "0200000216"
    }
  }
}

// Firstly, note the addition of the "query" key, which isn't currently present on sbx.clearui.com. Without it, you
// get a link that goes to https:/sbx.clearui.com/erp/sales-order/. With it, you get one that goes to
// https:/sbx.clearui.com/erp/sales-order/?VBELN=0200000216. 

// The problem with this current set up is that you have to know the VBELN number ahead of time. In the case of the 
// Customers Sales Order history tab (https://sbx.clearui.com/?KUNNR=LINCOLNELE), we don't know the numbers until the 
// page loads, namely because every customer has a different sales order history. That's the problem I'm attempting 
// to solve. See `1_new_simple_props.json` below.
{
  "name": "linkTemplate",
  "parameters": {
    "pathname": "/erp/sales-order/?VBELN={0}"
  }
}

// This is the simplest case. Often what we want to appear after `VBELN` is the value that the user types into the input.
// The above does so by replacing `{0}` with that number. Also note that the name is `linkTemplate` instead of `link`. 
// The reason for this is backwards compatibility.
{
  "name": "linkTemplate",
  "parameters": {
    "pathname": "/erp/sales-order/?VBELN={0}",
    "query": [
        "0200000216"
    ]
  }
}

// A similar result to `0_old.json` above can be obtained with these props. The core difference that we are using an
// array (where order matters) instead of an object (with the {}s). 

{
  "name": "linkTemplate",
  "parameters": {
    "pathname": "/erp/sales-order/?VBELN={VBELN}",
    "query": {
        "VBELN": "0200000216"
    }
  }
}

// This does the exact same thing, except the shape of `query` is closer to the original example. The idea is that
// query would look in the `pathname` and replace `{key}` with the key that matches. In this case `{VBELN}` would be
// replaced with the value of `query`s `VBELN` (query.VBELN).


// Each of these has the same restriction as our original example. I mention it for completeness. The only other use
// case we care about is when we need to add multiple values to the URL parameters dynamically instead of just one,
// which I'll address next once I get feedback on whether or not this makes sense.

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.