SSRS Report set value of parameter based on other parameter - reporting-services

I want to set the default value of 1 of my parameter using the other selected parameters dataset value.
for example, the content of the dataset is something like
[{'name': alex, 'id': 1},
{'name': bloom, 'id': 2},
{'name': kelly, 'id': 3},
{'name': david, 'id': 4},
{'name': lyn, 'id': 5}];
then in previous parameter, the user choose for name = alex, then how to set the next parameter value = 1, which the previous parameter's id.

Go to the parameter properties of the one you want to default > go to Default Values tab > Specify values > add 1 value and use this expression:
=Parameters!YourParameterName.Value

Is there any reason you need two parameters essentially pointing to the same thing?
Typically you would point you parameter's available values property to your dataset and set the parameter values to be ID and the parameter label to be name. This way the user chooses "Alex" from the list but internally the parameter value is actually 1

Related

Use object keys given by JSON_SEARCH to find a different key in the same object in mysql/mariadb

I have some records of payments in the database and I keep the items belonging to the payment as a JSON(LONGTEXT) column in mariadb. For example the items columns would be like below.
items
[{"id":"a4","quantity":1,"title":"A4 Sheets","unitprice":7000,"total":7000},{"id":"reports","quantity":1,"title":"Reports","unitprice":750,"total":750},{"id":"other","quantity":2,"title":"Cap","unitprice":250,"total":500}]
[{"id":"exam3_5","quantity":1,"title":"Exam Fees : Grade 03 - 05","unitprice":750,"total":750},{"id":"a4","quantity":1,"title":"A4 Sheets","unitprice":7000,"total":7000},{"id":"reports","quantity":1,"title":"Reports","unitprice":750,"total":750}]
[{"id":"other","quantity":10,"title":"Test1","unitprice":1,"total":10},{"id":"other","quantity":10,"title":"Test2","unitprice":2,"total":20}]
what I want to do is find objects that have the id of "other" and get the total of each object.
I can get objects with other by JSON_SEARCH(items, 'all', 'other')
and it will give results like below, just an example. Not according to the first table.
JSON_SEARCH(items, 'all', 'other')
"$[2].id"
["$[0].id", "$[1].id"]
So i know which indexes of the array have i need to look at. Now i need to get the total of every object which has id as "other".
I can do a JSON_EXTRACT(items, '$[*].total') which gives me
JSON_SEARCH(items, 'all', 'other')
JSON_EXTRACT(items, '$[*].total')
"$[2].id"
[7000, 750, 500]
["$[0].id", "$[1].id"]
[10, 20]
I need a third column something like this
JSON_SEARCH(items, 'all', 'other')
JSON_EXTRACT(items, '$[*].total')
Required Column
"$[2].id"
[7000, 750, 500]
500
["$[0].id", "$[1].id"]
[10, 20]
30
Finally I want a cumulative total of the "Required Column" which I guess I can do by SUM(Required Column).
Any advice on achieving the "Required Column"?
I'm using nodejs as the backend. I could do the processing there but I want to know if it can be done with mysql itself.
Thanks

Create single dictionary with jq

I have the following input:
[
{
constant_id: 5,
object_id: 2,
object_type: 'delimited_file',
name: 'data_file_pattern',
value: 'list_of_orders.csv',
insert_date: 2021-11-23T10:24:16.568Z,
update_date: null
},
{
constant_id: 6,
object_id: 2,
object_type: 'delimited_file',
name: 'header_count',
value: '1',
insert_date: 2021-11-23T10:24:16.568Z,
update_date: null
}
]
That I'd like to combine to get the following result:
{
data_file_pattern: 'list_of_orders.csv',
header_count: '1'
}
Basically creating a single dictionary with only the name and value keys from the input dictionaries. I believe I've done this before but for the life of me I can't figure it out again.
If you get your quoting right in the input JSON, it's as simple as calling the from_entries builtin. It converts an array of objects to a single object with given key/value pairs. It takes the field name from a field called key, Key, name or Name and the value from a field called value or Value (see Demo):
from_entries
{
"data_file_pattern": "list_of_orders.csv",
"header_count": "1"
}
Note: I believe the second field name should read header_count instead of delimited_file as you wanted to take its name from .name, not .object_type.

access a dictionary key value inside a list

Hi I have got a json response from al API with the following structure:
{'totalCount': 82,
'items': [{'id': '81',
'priority': 3,
'updatedAt': '2021-07-28T01:30:53.101Z',
'status': {'value': None, 'source': None},
'ps': {'value': None,'source': None},
'lastUpdate': '2020-09-07T03:00:17.590Z'}
....
]}
So when I check the key, values with python:
for key, value in jsonResponse.items():
print(key)
I am getting:
totalCount
items
Which are the keys of this dictionary.
So when I loop over the values, I get the ones inside the key called items, which at the same time is a list with dictionaries inside of it, how could I get the keys inside that list called items and the values inside of it as well?
You only have to play with the key, value, and nest some for blocks:
for key, value in jsonResponse.items():
print(key)
if key == "items":
for items_key and items_value in value[0].items():
# do whatever you want with the dictionary
# items here?
That way, you can access to this specific dictionary.

ImmutableJs - compare objects but for one property

I am converting a shopping basket to an immutable structure.
Is there an easy way with immutablejs to see if an immutable object already exists within an immutable list EXCEPT for one object property 'quantity' which could be different? List example:
[{
id: 1,
name: 'fish and chips',
modifiers: [
{
id: 'mod1',
name: 'Extra chips'
}
],
quantity: 2
},{
id: 2,
name: 'burger and chips',
modifiers: [
{
id: 'mod1',
name: 'No salad'
}
],
quantity: 1
}]
Now, say I had another object to put in the list. But I want to check if this exact item with modifiers exists in the list already? I could just do list.findIndex(item => item === newItem) but because of the possible different quantity property then it wont work. Is there a way to === check apart from one property? Or any way to do this without having to loop through every property (aside from quantity) to see if they are the same?
Currently, I have an awful nested loop to go through every item and check every property to see if it is the same.
Well this should work-
list.findIndex(item => item.delete("quantity").equals(newItem.delete("quantity"))
The equals method does deep value comparison. So once you delete the quantity, you are comparing all values that matter.
PS: please ignore code formatting, I am on SO app.
PPS: the above code is not optimal, you should compare a pre-trimmed newItem inside the arrow function instead of trimming it there.

PURE use default value

I'm using PURE from BeeBole for filling some HTML templates with JSON, everything works perfect except that I can't find how to pass a default value when a missing property, and I wanted to do this from this side since from the server there is nothing I can do. So for example I have this JSON object:
var example = {records: [ {id: '1', name: 'Bill', nick: 'B'}, {id: '2', name: 'Amy'} ]}
When I render this in a table, on the directive when I ask for 'nick' I get 'B' for the first and nothing for the second, but for this case I would like to set a default value such as '-' when the property is not found.
Is this possible?
Thank you
A bit late on this one.
If you want to show the nick in a SPAN, it should look something like:
'span':function(){
return this.nick || '-';
}
instead of:
'span':'nick'
You would probably get a quicker answer on the forum