I have an action in a Power Automate flow that returns an array of objects. In my case, the response will only contain a single item in the array. I'd like to work with that single item downstream in the flow, but I want to avoid the "Apply To Each" loop that is automatically inserted when I reference any property of the array item.
I know I can use a Compose action with the first() expression to get the first item in the array. But doing so hurts usability because the dynamic content window only shows the Outputs of the Compose action (i.e., I lose the ease of referencing individual properties of the item in the dynamic content window).
I know I can reference those properties via an expression, but is there a way to get a strongly typed reference to a single array item without incurring an unnecessary Apply to Each?
You can try Parse JSON, this will give you Dynamic content reference once you set it through first expression.
Parse JSON image
As an Content input use first(variables('Array')) then generate Schema from the sample, the sample must be a single item like this:
{
"ID": "11111-2222-333-4444-555",
"Column1": "lorem ipsum",
"Column2": "lorem ipsum 2"
}
Parse JSON reference
Related
https://i.stack.imgur.com/k1bZD.png
I am using sys.person to capture the person's name. Is there any way for just 'john' and not the entire {"name": "john"} to show instead? I want to avoid sys.given-name and sys.last-name since dialogflow says they are deprecated.
Do you have your entity configured as a list? If it is a list, you probably have to output the parameter like $session.params.name[0].name.
If it's not a list, $session.params.name.name would work, but in that case I suggest you change the entity name to person, as it would be more readable to see $session.params.person.name
From your screenshot, it looks like your parameter is an isList parameter.
I have checked today the behavior of static responses when referencing isList parameters and it seems that we can now display the list of values for a certain parameter without the array index in the responses using the format: $session.params.parameter-id.
In your case, it would be:
$session.params.name.
In addition, if you want to reference a specific array index in an isList parameter, you can use the format $session.params.parameter-id[i]. In your case, it would be $session.params.name[0]
or if you want to get the original value you can reference it as $session.params.name[0].original
NiFi Version 1.8.0
I'm trying to build our my json, and one of my fields needs to be an array. I thought I could simply use the UpdateAttribute Processor to set my attribute to '["arrayItem1", "arrayItem2"]' and then I could used AttributeToJSON to convert the attribute to JSON and it would convert to an array. Unfortunately, it simply turns into a string.
In the simplest way, how can I set an attribute to be an array so my final JSON (when using AttributeToJSON) field has the specific array?
EDIT 1
I will have a few SyslogListeners, I want to set an attribute so I know what data came from where. I want to be able to tag this data, so I though of adding an UpdateAttribute to set my attribute. I would like this to be an array. So the tag for:
SyslogListener1 will be ["tag1", "tag2"]
SyslogListener2 will be ["tag3", "tag4"]
SyslogListener3 will be ["tag1", "tag3"]
I thought of just having my flow look like this: SyslogListener -> UpdateAttribute -> Then all the data is now in the main flow -> AttributeToJSON. However, when I look at my JSON, my field is a string, not an array. How can I make this field to be an array? What I used to do, was use ReplaceText , the only problem with this is I didn't want to create a ReplaceText for ever single instance. Is there a single processor that could handle this?
Does your incoming flow file have any existing content? If not, you can use ReplaceContent to set the content to ["arrayItem1", "arrayItem2"] or whatever you wish the JSON to look like.
If the incoming flow file has existing JSON content, you can add the field explicitly (without attributes) using JoltTransformJSON or UpdateRecord.
Not my ideal solution, but I simply added a ReplaceText for each instance I would need. In my case, it was 7 different tag formations. So my nifi looks a little ugly. I was hoping for a single processor solution where I could tell it my JSON field and make it an array. So my pipeline is:
SyslogListener -> UpdateAttribute (creates our tags attribute with the string tag1, tag2 and the other tag combinations because I have 7 total SyslogListeners with their own UpdateAttribute) -> Data is now in the main pipeline, and some Other processing stuff happens here -> AttributeToJSON (setting our json with some attributes including our tags attribute) -> My 7 ReplaceTexts (which checks to see if our tags field has "tag1, tag2" and then replaces it with ["tag1", "tag2"], I do this for all 7 cases) -> PutElasticSearchHttp
So ingesting rsyslog messages, doing a bit of enriching, making my data into a JSON, then saving it to ES.
If anyone knows a single processor solution to this, so I don't need to have 7 unique ReplaceTexts (and more if I need new tags).
I am using SoapUI Pro 4.5.2 to read data from spreadsheets, put them into Soap requests to my web service, and get responses back to write to a spreadsheet. It's working.
I have two fields in the input data pertinent to my question:
Middle name is defined as a string of 4 characters, and as minOccurs = 1 and maxOccurs = 1.
Postal extension code (the 4-digit number that is optional after the normal 5-digit code) is defined as a string of 4 digits. This field is optional, so it is marked as minOccurs=0 and maxOccurs=1.
When I use the SoapUI UI interface to send a request, this works fine; if there's no value for middle name, SoapUI generates an empty tag and sends it (I guess because of the minOccurs=1). If there's no value for PostalCode, it does not send any tag at all (I guess because of minOccurs=0).
When SoapUI reads data from an Excel spreadsheet, however, the response to the same data is an error indicating that the extended postal code value of '' is not legal, because it must be 4 digits. It appears that SoapUI generates an empty tag for the extended postal code when reading data from the spreadsheet, and sends it.
I found the "Remove Empty Content" option for SoapUI requests, default to false. I set it to true, and now get an error back from validation indicating that middle name is required but not found. I'm guessing that the remove empty content removed all the empty content (reasonable enough), and middle name has to be there, even if empty, because of the minOccurs=1.
Do I have any way out of this tail-chasing problem? I suppose I'm looking for something like a conditional for the output of the postal extension code, so I can eliminate it if it's empty, even if reading values from the spreadsheet.
I am also curious if there are XSD fixes, but I greatly prefer a fix that doesn't involve changing the XSD -- that becomes a political matter.
EDIT FOR DETAIL:
To put input into the request: I have used the SoapUI UI to choose "properties" from the input spreadsheet for each of the input fields; when that's done, one ends up with values in the request fields like:
${SpreadsheetInput#FrstNm}
Where SpreadsheetInput is the name of the datasource step reading the spreadsheet, and FrstNm is one of the properties. I do this with the "Get Data" option off the popup menu you get by right-clicking the request input field, but there may be other ways.
So first your problem:
Remember that internally to SoapUI almost everything is a string. Doing something like:
<postCode>${SpreadsheetInput#PostCode}</postCode>
in your SOAP request, assuming PostCode is either blank or does not exist outright, will expand to:
<postCode></postCode>
and SoapUI will even optimize it to:
</postCode>
Then your validation kicks in, which says you do not need to provide this element, but if you do, it had better be 4-characters long. Which the above fails.
The solution:
You need to pragmatically (meaning you will have to write Groovy code) create this node in your request. There are several ways to handle this. The quick and dirty is with a Groovy step, that goes something like:
def postCode = context.expand('${SpreadsheetInput#PostCode}').trim()
if (postCode != null && postCode != '')
testRunner.testCase.setpropertyValue("postCodeNode", "<postCode>" + postCode + "</postCode>")
else
testRunner.testCase.setpropertyValue("postCodeNode", "")
Then in your request replace the original:
<postCode>${SpreadsheetInput#PostCode}</postCode>
with just:
${#TestCase#postCodeNode}
Notice, the XML node elements are part of the SoapUI property! Again: everything in SoapUI is just a plain string.
If you want something more hard-core, have a look at
dynamically create elements in a SoapUI request. This is mine.
I need a list where when a user types a letter into an above input, the list displays words starting with that letter. Thus, if a user types in "a" into the input, a dropdown ul pops out and displays words from an external php page starting with "a", maybe "apple" or "artifact". Additionally, if the user types in "ab", the page should show all words starting with "ab".
I know I have to use Jquery ajax somehow to GET the data from the external page (which is just on a simple list) and insert specific data into the other page based upon the letters typed in by the user. How can I do this?
If this is the callback from your ajax call, which is returning an array of words, something like this should work
function ajaxComplete(listOfWords){
var ul = $("<ul />");
for(var i = 0; i < listOfWords.length; i++)
ul.append("<li>" + listOfWords[i] + "</li>");
$("#someDiv").html(ul);
}
The easiest way, if you can control your external page, is to modify it to return JSON data. You can then use jQuery UI Autocomplete out-of-the-box.
http://docs.jquery.com/UI/Autocomplete
When a String is used [as the data source parameter], the Autocomplete plugin expects that string to point to a URL resource that will return JSON data. It can be on the same host or on a different one (must provide JSONP). The request parameter "term" gets added to that URL. The data itself can be in the same format as the local data described above.
If you cannot modify the page, you must use the third type of jQuery UI Autocomplete, which is to pass a callback to the plugin. Then, write a callback function that .get()s the data off your other page and parses it. This is easy with jQuery's DOM traversal methods.
Is it possible using NSArrayController to bind a NSTextField's value to a particular item in the array? In particular, I want to bind to a property on the first item in the array, and show nothing if the array is empty.
Using arrangedObjects.command shows just "(" -- presumably it's trying to show a multi-line string with comma-separated strings for each item. I just want the first one.
Bind the text field to selection.command, and programmatically set the array controller's selection index to 0. You may need to also re-set the selection index to 0 any time you add or remove items to the content array.
Obviously, this won't work if you're allowing the user to select items within the array controller (you'd need a second array controller). I'm assuming that's not the case, since if it were, I'd expect you to want to show the user-selected object, instead of always the first object.
EDIT: Better yet, do nothing like this—if the object that is first in the array has some special status, you should make a separate non-array property (in the same object that holds the original array, from which I assume the array controller is getting it) to hold the object that has that status.