Update json in logic apps - json

I want to parse through a json and update specific nodes in json result according to the following code snippet written in power shell:
foreach($val in $getresult.elements.values)
{
if($val.Name -eq "Config")
{
$val.items.Service=$ServiceValue
}
if($val.Name -eq "Analysis")
{
$val.items.ID=$IDValue
$val.items.Name=$NameValue
}
if($val.Name -eq "Report")
{
$val.items.to=$ToValue
}
}
The final $getresult elements/nodes should be updated with $ServiceValue, $NameValue and $ToValue. How do I achieve it in logic apps?

We recently introduced new workflow functions #setProperty, in combination with condition action you will be able to set the properties inside. Or, use #addProperty if such name doesn't exist.
https://learn.microsoft.com/en-us/azure/logic-apps/logic-apps-workflow-definition-language

Related

Jenkins parameter value not displaying

Goal: Declare a conditional multi-line string parameter
Approach:
I have defined two jenkins parameters.
Active choices parameter
Active choices reactive reference parameter(Choice type: Formatted HTML)
In the pipeline, I am just looping over both parameters and printing them
pipeline {
agent any
stages {
stage('print each paramter') {
steps {
script{
params.each {param ->
println "${param.key} -> ${param.getValue()} "
}
}
}
}
}
}
and this is the output
Second parameter is not printed. I have also tried echoing it with
echo ${inventory}
echo ${param.inventory}
echo ${params.inventory}
but it's not working.
Any suggestions how I can declare a conditional multi-line string parameter?
Active choice reactive parameters rendered as HTML can be passed to build only if is hidden and formatted as input. See Behavior and Rendering Summary in the official documentation.
The HTML parameters are only for visualization purposes, not for returning a user input value. For build parameters, use active choice and active choice reactive parameters.

How to save a JSON-object and use it in another request?

i'm currently trying to set up some JMeter testplans. I am pretty new to this (started a week ago) and don't have much programming experience either, so i hope you could help me in this case.
I already set up some http requests and have some simple JSON Extractor post processors to save some of the variables and use them with the "${variable}" notation.
But now i need to save and modify an object from a response to use that in the next http request.
My respose is a extremely big JSON object and the part im interested in looks something like this:
{
"payload": {
"workspace": {
"resultInstance": [
[{"part": "1"...}],
[{"part": "2"...}],
...
[{"part": "20"...}]
]
}
}
}
Note that for whatever reason these objects {"part":"1"...} are inside a nested array. And they are also pretty big.
I would like to safe those objects in a variable to use them in my next http request which should looks like this:
{
"instanceChange": {
"functionChecks": [
{"part": "1"...},
{"part": "2"...},
...
{"part": "20"...}
]
}
}
So what im really trying to find is a way to save all of the possible objects inside the nested array "resultInstance" and put them inside the non nested array "functionChecks".
I already looked inside the JMeter documentation but because of my poor programming background i cant find a way to realize this.
I think i need something like the JSR223 PostProcessor and "simply go through the resultInstance-array and use smth. like an getObject() on these", but i cant figure out the code i need and if its even possible to safe objects in variables in Jmeter.
Im pretty thankful for every bit of help or advice :).
Thanks in advance,
aiksn
Add JSR223 PostProcessor as a child of the request which returns the JSON response
Put the following code into "Script" area:
def response = new groovy.json.JsonSlurper().parse(prev.getResponseData())
def request = ['instanceChange': ['functionChecks': response.payload.workspace.resultInstance]]
vars.put('request', new groovy.json.JsonBuilder(request).toPrettyString())
That's it, you should be able to refer the generated request body as ${request} where required
More information:
Apache Groovy - Parsing and producing JSON
Apache Groovy - Why and How You Should Use It
let response ={
"payload": {
"workspace": {
"resultInstance": [
[{"part": "1"...}],
[{"part": "2"...}],
...
[{"part": "20"...}]
]
}
}
};
let requestObj={
"instanceChange": {
"functionChecks": [
]
}
};
response.payload.workspace.resultInstance.forEach(myFunction);
myFunction(item, index) {
requestObj.instance.functionsCheck.push(item[0]);
}

How to set response code while using json views with Grails 3

I am now in process of switching to use json view in one of my apps built with Grails 3.3
It all looks pretty simple and here is one of my controllers:
def create(ProjectCommand command) {
if (command.validate()) {
// do something with user
Project project = projectService.create(command, springSecurityService.principal.id as Long)
if (project) {
[status: HttpStatus.CREATED, project: project]
} else {
badRequest("failed to create the project")
}
}
else {
badRequest(command.errors)
}
}
Here, I assumed that the status will be used as a response status code, but it does not.
Is there an easy way to set status code of the response without explicitly going through render?
Hmmm... that was easy.
Apparently, inside the view file itself, there is a way to almost anything.
For this particular case, it is enough to do:
response.status HttpStatus.CREATED
I hope it will be useful to someone

How can I POST JSON values without property expansion in soapUI?

In soapUI, I am trying to perform an HTTP POST with the following JSON:
{
"myNode":{
"myOtherNode":"${MY_VALUE}"
}
}
The POST operation is successful, but in the response the value for myOtherNode is blank. I'm guessing this is because soapUI is treating it as parameter and trying to replace it. I do not want it replaced; I want to send it as it is.
I am able to do the same thing using command line curl.
Edit: I could not find the answer in their Property Expansion Documentation.
To prevent the property expansion from replacing ${MY_VALUE} you can add an extra $ like this:
{
"myNode":{
"myOtherNode":"$${MY_VALUE}"
}
}
Doing that your original json will be sent like this:
{
"myNode":{
"myOtherNode":"${MY_VALUE}"
}
}

Pipelining get-content to own function

I'm trying to write a powershell function that receives a list of files from the get-content commandlet by piplining and processes them.
The pipeline looks like this:
get-content D:\filelist.txt | test-pipeline
For simplicity sake the function below should just show each line of the textfile.
function test-pipeline
{
<#
.Synopsis
#>
[CmdletBinding( SupportsShouldProcess=$true)]
Param([Parameter(Mandatory = $true,
ValueFromPipeLine = $true)]
[array]$filelist
)
foreach ($item in $filelist)
{
$item
}
}
My filelist is a normal .txt file and looks like this.
line 1
line 2
line 3
line 4
line 5
No matter what type of parameter I pipe to the function, it never works and shows only the last line of the text file in the $filelist variable. Can anybody help? Powershell Version is v2
Thanks in advance
The reason you see only your last line requires digging a bit into the nature of pipeline-able PowerShell functions. In the absence of explicit begin/process/end blocks that Swonkie alluded to, all code in the function operates as if it is in the end block, i.e. it is as if you wrote:
function test-pipeline
{
[CmdletBinding()]
Param(
[Parameter(ValueFromPipeLine = $true)][array]$filelist
)
END {
$filelist
}
}
But $filelist, being a pipeline variable, has only the current value in it when fed pipeline data; the end block runs when the pipeline input is exhausted, thus $filelist contains just the last value. Simply changing that end block to a process block--where it runs for each value in the pipeline, will give you the desired output:
function test-pipeline
{
[CmdletBinding()]
Param(
[Parameter(ValueFromPipeLine = $true)][array]$filelist
)
PROCESS {
$filelist
}
}
And notice that you do not need any kind of loop there--the pipeline is already providing the "loop".
That is just one of several ways to process pipeline data. Here's a close variant, which is a bit shorter: use filter instead of function, because filter with no explicit blocks operates as if all code is in the process block.
filter test-pipeline
{
[CmdletBinding()]
Param(
[Parameter(ValueFromPipeLine = $true)][array]$filelist
)
$filelist
}
To delve further into the fascinating and arcane world of writing functions for pipelining, take a look at the in-depth analysis I wrote, Down the Rabbit Hole: A Study in PowerShell Pipelines, Functions, and Parameters, published on Simple-Talk.com. Enjoy your PowerShell adventures!
Instead of function try filter:
filter Test-Pipeline {
...
}
This is basically a function with a processing block (which you need to process pipeline objects). Alternatively you can write a function with this block and optional begin and end blocks:
function Test-Pipeline {
begin {
}
process {
...
}
end {
}
}
More info: http://technet.microsoft.com/en-us/magazine/hh413265.aspx