Powerautomate Parsing JSON Array - power-automate

I've seen the JSON array questions here and I'm still a little lost, so could use some extra help.
Here's the setup:
My Flow calls a sproc on my DB and that sproc returns this JSON:
{
"ResultSets": {
"Table1": [
{
"OrderID": 9518338,
"BasketID": 9518338,
"RefID": 65178176,
"SiteConfigID": 237
}
]
},
"OutputParameters": {}
}
Then I use a PARSE JSON action to get what looks like the same result, but now I'm told it's parsed and I can call variables.
Issue is when I try to call just, say, SiteConfigID, I get "The output you selected is inside a collection and needs to be looped over to be accessed. This action cannot be inside a foreach."
After some research, I know what's going on here. Table1 is an Array, and I need to tell PowerAutomate to just grab the first record of that array so it knows it's working with just a record instead of a full array. Fair enough. So I spin up a "Return Values to Virtual Power Agents" action just to see my output. I know I'm supposed to use a 'first' expression or a 'get [0] from array expression here, but I can't seem to make them work. Below are what I've tried and the errors I get:
Tried:
first(body('Parse-Sproc')?['Table1/SiteConfigID'])
Got: InvalidTemplate. Unable to process template language expressions in action 'Return_value(s)_to_Power_Virtual_Agents' inputs at line '0' and column '0': 'The template language function 'first' expects its parameter be an array or a string. The provided value is of type 'Null'. Please see https://aka.ms/logicexpressions#first for usage details.'.
Also Tried:
body('Parse-Sproc')?['Table1/SiteconfigID']
which just returns a null valued variable
Finally I tried
outputs('Parse-Sproc')?['Table1']?['value'][0]?['SiteConfigID']
Which STILL gives me a null-valued variable. It's the worst.
In that last expression, I also switched the variable type in the return to pva action to a string instead of a number, no dice.
Also, changed 'outputs' in that expression for 'body' .. also no dice
Here is a screenie of the setup:
To be clear: the end result i'm looking for is for the system to just return "SiteConfigID" as a string or an int so that I can pipe that into a virtual agent.

I believe this is what you need as an expression ...
body('Parse-Sproc')?['ResultSets']['Table1'][0]?['SiteConfigID']
You can see I'm just traversing down to the object and through the array to get the value.
Naturally, I don't have your exact flow but if I use your JSON and load it up into Parse JSON step to get the schema, I am able to get the result. I do get a different schema to you though so will be interesting to see if it directly translates.

Related

Access value from a Netsuite hash, Enumerator

Hi I am trying to extract a value from a Netsuite hash inside custom fields, and some others, which typically look like this - `
"custbody_delivery_ticket_number"=>
{
"script_id"=>"custbody_delivery_ticket_number",
"internal_id"=>"2701",
"type"=>"platformCore:DateCustomFieldRef",
"attributes"=> {
"value"=>"123abc"
}
}` and want the value of it inside of attributes.
Have tried many different ways, but one in particular -
delivery_ticket_number: "#{netsuite_sales_orders.custom_field_list.custom_fields.select['custbody_nef_meter_ticket_number']['attributes']['value']}",
throws error for class Enumerator, NoMethodError: undefined method `[]' for #Enumerator:0x00005589ec778730 which indicates may be getting close, but doing something wrong.
If anyone has any idea how to get values from these kind of hashes?
(Am told by the system admin that it is the correct custbody identifier)
Many Thanks
Eventually fixed this, grabbing Netsuite custom fields with a select of script_id by name,and map as below:
delivery_date:netsuite_sales_order.custom_fields_list.custom_fields.select { |field| field.script_id == 'custbody_delivery_date' }.map { |field| field.value }.first
First selecting the script_id by unique name, then mapping to the value. Was able to get any custom field like this, preferable as they can move and might not have the same index if use an index to grab them, fetching an incorrect value. This way ensures getting the correct data even if the item is moved up or down in the custom fields list.
Thanks for everyones help!

Cypress - counting number of elements in an array that contain a specific string

Attempting to confirm that of all the schema in the head of a page exactly 3 of them should have a specific string within them. These schemas have no tags or sub classes to differentiate themselves from each other, only the text within them. I can confirm that the text exists within any of the schema:
cy.get('head > script[type="application/ld+json"]').should('contain', '"#type":"Product"')
But what I need is to confirm that that string exists 3 times, something like this:
cy.get('head > script[type="application/ld+json"]').contains('"#type":"Product"').should('have.length', 3)
And I can't seem to find a way to get this to work since .filter, .find, .contains, etc don't filter down the way I need them to. Any suggestions? At this point it seems like I either need to import a custom library or get someone to add ids to these specific schema. Thanks!
The first thing to note is that .contains() always yields a single result, even when many element match.
It's not very explicit in the docs, but this is what it says
Yields
.contains() yields the new DOM element it found.
If you run
cy.get('head > script[type="application/ld+json"]')
.contains('"#type":"Product"')
.then(console.log) // logs an object with length: 1
and open up the object logged in devtools you'll see length: 1, but if you remove the .contains('"#type":"Product"') the log will show a higher length.
You can avoid this by using the jQuery :contains() selector
cy.get('script[type="application/ld+json"]:contains("#type\": \"Product")')
.then(console.log) // logs an object with length: 3
.should('have.length', 3);
Note the inner parts of the search string have escape chars (\) for quote marks that are part of the search string.
If you want to avoid escape chars, use a bit of javascript inside a .then() to filter
cy.get('script[type="application/ld+json"]')
.then($els => $els.filter((index, el) => el.innerText.includes('"#type": "Product"')) )
.then(console.log) // logs an object with length: 3
.should('have.length', 3);

dd works but echo does not for an object passed as a parameter to a function in Laravel

I passed an object in a function in laravel.
I tried to assign the value of a property to a variable. It pops an error.
When I tried to figure out what was going on I tried to dd ()the value it worked.
But when I tried to echo the same it does not.
What am I mising.
On using this,
location1 and location2 are two objects of the location class.
The function is here:
function geodistance($location1,$location2){
dd($location1->lat);
$lat1=$location1->lat;
}
it prints
"28.612072"
But when I change the same function to
function geodistance($location1,$location2){
echo($location1->lat);
$lat1=$location1->lat;
}
The output error is:
Trying to get property 'lat' of non-object
Even the function
function geodistance($location1,$location2){
echo $location1->lat;
$lat1=$location1->lat;
}
gives the same output
The aim to remind you is to assign the value to a variable like so.
function geodistance($location1,$location2){
$lat1=$location1->lat;
}
When I echo $location1 from within the function geodistance() gives out and error which makes sense.
function geodistance($location1,$location2){
echo $location1;
$lat1=$location1->lat;
Object of class App\MyClasses\city could not be converted to string
When I dd ($location1 from the funciton like so it gives the right result.
function geodistance($location1,$location2){
dd($location1);
$lat1=$location1->lat;
like so:
city {#13410 ▼
+id: 2245
+info: "{}"
+name: "New Delhi"
+lat: "28.612072"
+lon: "77.22978"
+timezone: null
+weightedrating: null
+country_id: 1
}
It seems i am missing out something very trivial. :(
As pointed out by #salman zafar and #apokryfos, the mistake was that I was passing an array.
When I was doing a dd, after processing the first data the programme was terminated.
The array that was passed was not completely correct. The last data point in my array was not an object of the same class.
So the data ended up being corrupted when using echo. Echo would print one data after another but eventually it would get a wrong input.
The best way to catch these errors (after so much experimenting) is to write the values of the variable in a text file on each iterartion.
What that does is that it catches the error in your text file and u get to know after how many iterations the programme stopped.
Hope this helps others from making such obviously glaring mistakes which are tough to catch (atleast for me since this was the first of such errors)

Why can't I append an object to an array in rethinkdb?

I am trying to append an object into an array in rethink. Here is how I am trying to append it:
rethink.table('shifts')
.get(shiftId)
.update(row => row("milestones").default([]).append({
dateAchieved: "2017-01-01",
phaseType: "TEST"
})).run(rethinkConnection)
The error I get is this:
first_error: 'Inserted value must be an OBJECT (got ARRAY):\n[\n\t{\n\t\t"dateAchieved":\t"2017-01-01",\n\t\t"phaseType":\t"TEST"\n\t}\n]',
I also tried the same code about, but removed .default([]), which did not change anything.
I have tried logging out what row('milestones') is and this is the result:
var_15("milestone")
I was expecting to see an array. What else is necessary to add an object to an array? How do I make this work?
You need to update document with a document not an array. Your reql should look like this
rethink.table('shifts')
.get(shiftId)
.update({
milestones: rethink.row('milestones').append({
dateAchieved: "2017-01-01",
phaseType: "TEST"
})
})
.run(rethinkConnection)
this is because the .append command does not commit data to the database it only returns an in memory modified array

What does "read_strt" meaning here?

What does this vbscript code mean?
<%=read_strt(objRS, "ccnumber", "")%>
I want to know whats the meaning or used of read_strt on the code?
Any ideas?
The statement writes the return value of a call to the function "read_strt" to the HTML output stream. The function seems to read the value of a field/column in the current row of a database query (recordset), convert its type to String and/or test it against 'bad' (e.g. Null) values; in that case the default value ("", empty string) is returned.

Resources