Azure Pipeline string curly braces - reactjs

I have an Azure Pipeline variable containing a string into which I wish to insert a JavaScript parameter.
PipelineVariable: 'http://url/${id}'
React function:
myUrl: id =>`#{PipelineVariable}`
Unfortunately it seems the curly braces in Pipeline variable are interpolated so the output of this function is:
http://url/$%7Bid%7D
Any suggestions for how to get round this, presumably by preventing escaping of the braces? I want to call myUrl('12345') and get
http://url/12345
The following does work, but I want to embed the id within the Azure string.
myUrl: id =>`#{PipelineVariable}/${id}`

Related

LogicApp Split and Replace having problems with \n

I have been trying to split a string into an array of each line \n
As this doesn't work I tried replacing replace(outputs('Compose_6'),'\r\n','#') with a view to then splitting on #.
I have searched the internet and tried various things but nothing seems to work.
Can someone explain how to do this?
Thanks in advance
Using split(variables('string var'),'\n') expression, you can split string into array. By default logic app will add an extra black slash to original back slash. So suggesting you to change expression in code view as mentioned above.
I have created logic app as shown below,
In first initialize variable action, taken a string variable with text as shown below
Hello
Test split functionality
Using logic apps
Next initialize variable action, using a array variable and assigning value using expression as split(variables('string var'),'\n'). Make sure you dont have double back slash added in code view. Only one back slash should be there when you see it in code view.
Code view:
The output of logic app can be shown below,
Refer this SO thread.

Getting a string result from XPath expression in Talend cSetHeader

I'm being stumped by something that should be trivial.
I've got an xml document, which is split using cSplitter using XPath which works fine, but then I want to set headers with values from the split document.
I've got a cSetHeader component with the Language set to XPath and the valid xpath. However, it returns the value as a NodeList object, when I need a string.
If I use an XPath expression that returns a string, it gives an exception as it can't convert to NodeList.
How, in Talend, do I configure the XPath expression to return a string. It seems ok if you're writing the camel directly, as there is a parameter, but I can't see how it is done in Talend.
Thanks!
I've figured it out...
As it's a code generator, talend puts in the .xpath( ... ) whatever you type in the field - so if you want it to generate a string you put
"/your/xpath/here", java.lang.String.class
in the cSetHeader xpath field and the code generator puts your xpath string with the requested class in the right place!
Easy! Now why didn't I think of that earlier...?

How can you reference a single output from an if else conditional in Azure Logic Apps

I have an Azure Logic app with an if/else conditional. In each branch I have a compose action to create some JSON. The true branch has compose and the false compose_2. After the conditional I want to send a message to a queue with the output from either branch but how do I reference the output? I have two actions("compose") and actions("compose_2"). Is there any way I can reference the output with a single variable/property name?
It is possible by using #result() which will return all the output of a scope (Condition in your case) as an array, and you can use #coalesce to find out the non-empty value between Compose and Compose_2.
However, I would use variable instead:
Declare an variable before Condition
Set the variable in each branch
Reference the variable after Condition

Use Array of Values of Object in a Foreach Loop

I cannot seem to find anything about using the values of one property of an object in a foreach loop (without having the entire object placed into the loop).
I first create a function called UFGet-Servers that uses Get-ADComputer and returns the names of the servers in a specific OU in my environment and places them in an array. That's great, except that when I use the array in a foreach loop, each object that it grabs has #[Name=serverName] in it, which I cannot use in any useful manner. The following pseudo-code is an abbreviated example:
foreach($Computer in $ComputerNames){do code... code is adding the server name into a UNC path such as "\\$Computer\C$\"}
The problem with the above is that you can't add the whole object to a path -- it ends up looking like "\#[Name=serverNameHere]\C$\" which totally bombs out. How do I get rid of the "#[property=" part, and simply use the value as the $Computer in the loop?
What really weirds me out is that I can't find a straightforward article on this anywhere... would have thought everyone and their mom would have wanted to do something like this.
So, your issue isn't with ForEach loops, it is with string formatting. There are two ways that I know of to take care of what you need. First is going to be string formatting, which allows you to use {0}m {1} and so on to inject values into a string, providing that you follow the string with -f and a list of said values. Such as:
ForEach($Computer in $ComputerNames){
"The Server Path is \\{0}\Share$" -f $Computer.Name
}
The second way is a sub-expression (I'm sure somebody will correct me if I used the wrong term there). This one involves enclosing the variable and desired property (or a function, or whatever) inside $(). This will evaluate whatever is inside the parenthesis before evaluating the string. See my example:
ForEach($Computer in $ComputerNames){
"The Server Path is \\$($Computer.name)\Share$"
}

unterminated string literal error in salesforce

I am trying to get a value from salesforce class into a javascript variable. I am able to get the value if its a single line value, but if its multiline textarea it gives a unterminated string literal error
caseUpdate.Description = "{!ac__c.C_Info__c}";
After googling for sometime i came to know we can have a workaround for this by having a hidden field and using DOM storing it using the document.getElement.Id. But i am calling this code on a button click so i would not be able to create a input text or hidden field value.
Any body who can provide an way to do it?
Thanks
Prady
You should just be able to use the standard Salesforce JSENCODE() function if you are using OnClick Javascript in a button. This will escape any characters for you.
See the documentation.
It is because of line breaks. merge fields are rendered unescaped into the output stream meaning that CRLFs push into a new line and break javascript strings. Either use the div/input trick or use Apex to replace \r\n's in the field with <br/> or whatever best suits the purpose. Also keep in mind that " will also terminate your JS string.
The easiest way is to just include a function in your extension and then you can use it across board
public String FixNewLine(String s) {
if (s != null) return s.replaceAll('\r\n', '<br/>').replaceAll('"', '\\"');
return null;
}
I had the same issue but was able to fix it! The trick is the JSENCODE function. Its basically {!JSENCODE(Obj.Field)}"; So you are replacing your merge field with this function and nesting the merge field itself within the function. In my scenario I ended up with opptyObj.Description="{!JSENCODE(Case.Description)}"; as my total syntax. First calling upon my set object and field, and then the merge data to populate it.

Resources