i have a web activity through which i am executing a rest API(execute queries)
this is a sample output of that:
{
"results": [
{
"tables": [
{
"rows": [
{
"[Value]": "2022-10-25T00:00:00Z"
}
]
}
]
}
]
i want to store the date value inside [Value] in a variable in adf
(variable value should be:2022-10-25T00:00:00Z)
but i am not able to do that because of square brackets
this is what i have tried
"#activity('SQl validation').output.results[0].tables[0].rows[0].[value]"
but it give me error
Position 73 Unrecognized expression: value
please suggest how i can fix this
Look at the following demonstration. I have the lookup which returns the following values.
To access the [companyId] attribute from this output array, I have used the following dynamic content (Using for loop just for demonstration):
#string(activity('myLookUp').output.value[item()]['[companyId]'])
So, you can use the following dynamic content instead:
#activity('SQl validation').output.results[0].tables[0].rows[0]['[value]']
Related
Hope this question finds you all in good health.
As per title, would like to know how this is done in Groovy. Found a few, such as this, but the question and answer did not help.
The JSON is like this
def json = '''{
"boston": [
{
"name":"bob",
"phone":"242 123123",
},
{
"name":"alice",
"phone":"212-123-345",
}
],
"chicago": [
{
"name":"charlie",
"phone":"313-232-545",
},
{
"name":"denise",
"phone":"414-123-546",
}
]
}'''
But how do I use the value, for example bob to get boston?
When you use parsedjson['chicago']['email'], the result would be
[charlie#chicago.com, denise#chicago.com]
I tried to do something like
def getKey = parsedjson['email']?.key
as suggested here but in JIRA ScriptRunner console returned null
Any pointer is greatly appreciated in advance!
parsedjson['email']?.key returned null because key is not a List method. key is an Entry method so to find the key from a value you have to iterate through the Map's Entry Set.
Here's an example to get the city from the person's name using Map.find which returns an Entry:
parsedjson.find { it.value.find { it["name"] == "bob" } }.key
We have REST APIs with JSON BODY arrays/objects. To control the data to go in the JSON file at Runtime, using testdata.properties file where defining the data and calling that as below. We are using cucumber Serenity.
Testdata.properties file:
Value = 123
StepDefinition file:
#Given("^Set the \"([^\"]*)\" with \"([^\"]*)\"$")
public void set_data_parameterization (String fieldName, String Value) {
if (fieldName.contains("Test")) {
jsonObjectNew.getAsJsonObject("TestInfo").add("Value",
gson.toJsonTree(Value));
}
System.err.println("Test value fetched from the Scenario outline");
}
JSON File:
{
"TestInfo": {
"Test123": 3,
"Value": 50 // this value to be replaced
}
}
.feature file:
Scenario Outline::
1. Testing data parameterize
Given Set the URL for "Test" as "base"
And Set the "Test" with "Value"
Examples:
|Value|
|700|
|710|
If calling the variable data from .properties file works fine, however if want to have different sets of data to be executed for the same scenario. How can it be achieved. Tried with Examples in feature file, but when run the file as cucumbertest>getting the actual payload value which is 50. It is not replacing with 700/710.
Please guide.
Able to get values as expected now, the issue was I was trying as "String" (ex: "Values"). When tried as in .feature file and rest of the code is similar.
Able to get values iterated of given Examples.
I have an object with the following structure, let's say the object name is apiCall:
{
"Status":"OK",
"ID":"xxx",
"Results":[ ]
}
And this is the structure of the Results array:
[
{
"Call":{
"ID":1,
"CustomerKey":null,
"CustomerID":null
},
"PingID":4,
"Key":null,
"Properties":[
{
"Name":"OrdinalID",
"Value":"1"
}
],
"CreatedDate":"0001-01-01T00:00:00.000",
"ID":0,
"ObjectID":null
}
]
Everything works perfectly fine and I am able to retrieve everything except the nested Properties.
So this is how I retrieve for example Call.ID when iterating through Results - this works fine:
apiCall.Results[i].Call.ID
Now when I try to get the Properties nothing works - I tried parsing, stringifying, and also the following:
apiCall.Results[i].Properties.Value;
apiCall.Results[i].Properties.OrdinalID;
Stringify(apiCall.Results[i].Properties.Value);
nothing from above works.
This is the only thing that somehow worked so far:
Stringify(apiCall.Results[i].Properties);
and it's giving the following result:
[{"Name":"OrdinalID","Value":"1"}]
How can I get to the actual value?
Thank you
Your Properties property is an array, so you need to include an index similar to what you did with Results[i].
Like so: apiCall.Results[i].Properties[0].Value (using 0 as the index here).
i am trying to configure a default value as my sourceID column.
my source is a FILe and my sink is a db table.
hence, i cant define the sourceID in sql query.
i created a parameter and defined the value.
intent to pass the parameter in the column mapping's dynamic content string.
however, i couldnt get the parameter value loaded into my table.
please advice if i made mistake in the dynamic content definition or there is better way to achieve the desired outcome.
{
"type":"TabularTranslator",
"columnMappings":{
"AS_OF_DATE":"AS_OF_DATE",
"SECTOR_ID":"SECTOR_ID",
"ASSET_GROUP":"ASSET_GROUP",
"REGION":"REGION",
"COUNTRY":"COUNTRY",
"FIELD":"FIELD",
"SECTOR_FLAG":"SECTOR_FLAG",
"PRODUCT":"PRODUCT",
"PERIODICITY":"PERIODICITY",
"UNIT_CODE":"UNIT_CODE",
"OPERATORSHIP":"OPERATORSHIP",
"OPRNAME":"OPRNAME",
"ACTUAL":"ACTUAL",
"PLAN":"PLAN",
"SOURCE_ID":"#{pipeline().parameters.sourceIDmpm}"
}
}
To dynamically map column in copy activity, please define a parameter with type 'Object' in pipeline:
"parameters": {
"columnMapping": {
"type": "Object"
}
}
and reference this parameter in copy activity like:
"translator": {
"value": "#pipeline().parameters.columnMapping",
"type": "Expression"
}
Please notice that you need to pass a JSON value to parameter. For example, I pass to the parameter
'columnMapping'.
{
"type": "TabularTranslator",
"columnMappings": {
"Prop_0": "Prop_0",
"Prop_1": "Prop_1", "Prop_2": "Prop_2"
}
}
For more details, you may refer the MSDN thread which addressing similar issue.
Hope this helps.
I have a method in a Groovy file that looks like this:
static Map getFixtures() {
return [
mydb: [
mytable:
[
[
Id: 1,
]
]
]
]
}
When I call the method, like this:
Map fixtures = getFixtures()
I get this error:
Exception in thread "main" java.lang.ClassFormatError: Method getFixtures in class has illegal modifiers: 0x409
How would I typehint a multidimensional array like this?
Too noob to comment on #dagget 's comment but this may be due to the get prefix you chose in your method's name. Groovy maybe trying to make a lookup for a getter method inside the invoking class. Refer to http://groovy-lang.org/style-guide.html#_getters_and_setters