During a recent project customising Unified Service Desk, I had the need to nest one replacement parameter inside another.
Here’s a simplified example of what I wanted to achieve:
- entity.PointerToAHostedControl = MyHostedControl
- MyHostedControl.name = MyNameResult
In other words, I wanted to dynamically find the name of a hosted control and then get the name of the entity that was currently loaded on that hosted control.
The problem is that it doesn’t work! It just gets replaced to something like this:
This is because USD is ‘swallowing up’ all of the opening square brackets and treating them as a single ‘start of replacement parameter’ marker.
When USD processes replacement parameters, it works through the replacement parameter string from left to right, looking for ‘start’ markers [[. Luckily:
- Before it even starts looking for start markers, it processes all of the $Expression sections. If you place your inner replacement parameter within a $Expression, then it gets processed first.
So starting with this (N.B. it is important to get your casing correct and quote marks in the right place):
Firstly, USD processes the $Expression, giving this:
Then it is processes the string like a normal replacement parameter to give the result we are looking for:
In replacement parameters, $Expression handlers are processed before everything else. You can take advantage of this to allow you to nest replacement parameters.
Maybe there might be other uses too that I haven’t thought of yet. If only I’d got round to enabling comments on my blog, you could let me know if you think of anything…
Post image Untitled copyright Louise Leclerc (license)