How can you use conv.user.entitlements ? it returns an object but it doesn't show the data - actions-on-google

When I use conv.user.entitlements it returns "[ { entitlements: [ [Object] ], packageName: 'com.Company.ProjectName' } ]" to console.log -- is there a way to search the data in Object?
I tried conv.user.entitlements[entitlements], conv.user.entitlements.entitlements, and conv.user.entitlements[0] thinking I can read it like an array but it didn't work and comes back undefined.

Have you tried serializing it to see the structure, e.g.
console.log(`entitlements: ${JSON.stringify(conv.user.entitlements)}`);
Based on the structure posted in comments, accessing specific properties requires navigating through multiple arrays, e.g.:
console.log(entitlements[0].entitlements[0].inAppDetails);
console.log(entitlements[0].entitlements[0].inAppDetails.inAppPurchaseData.purchaseTime);

Related

Load more records from Gatling feeder

I would like to inject n-rows from my csv file to Gatling feeder. The default approach of Gatling is to read and inject one row at a time. However, I cannot find anywhere, how to take and inject an eg. Array into a template.
I came up with creating a JSON template with Gatling Expressions as some of the fields. The issue is I have a JSON array with N-elements:
[
{"myKey": ${value}, "mySecondKey": ${value2}, ...},
{"myKey": ${value}, "mySecondKey": ${value2}, ...},
{"myKey": ${value}, "mySecondKey": ${value2}, ...},
{"myKey": ${value}, "mySecondKey": ${value2}, ...}
]
And my csv:
value,value2,...
value,value2,...
value,value2,...
value,value2,...
...
I would like to make it as efficient as possible. My data is in CSV file, so I would like to use csv feeder. Also, the size is large, so readRecords is not possible, since I'm getting out of memory.
Is there a way I can put N-records into the request body using Gatling?
From the documentation:
feed(feeder, 2)
Old Gatling versions:
Attribute names, will be suffixed. For example, if the columns are name “foo” and “bar” and you’re feeding 2 records at once, you’ll get “foo1”, “bar1”, “foo2” and “bar2” session attributes.
Modern Gatling versions:
values will be arrays containing all the values of the same key.
In this latter case, you can access a value at a given index with Gatling EL: #{foo(0)}, #{foo(1)}, #{bar(0)} and #{bar(1)}
It seems that the documentation on this front might have changed a bit since then:
It’s also possible to feed multiple records at once. In this case, values will be arrays containing all the values of the same key.
I personally wrote this in Java, but it is easy to find the syntax for scala as well in the documentation.
The solution I used for my CSV file is to add the feeder to the scenario like:
.feed(CoreDsl.csv("pathofyourcsvfile"), NUMBER_OF_RECORDS)
To apply/receive that array data during your .exec you can do something like this:
.post("YourEndpointPath").body(StringBody(session -> yourMethod(session.get(YourStringKey))))
In this case, I am using a POST and requestBody, but the concept remains similar for GET and their corresponding queryParameters. So basically, you can use the session lambda in combination with the session.get method.
"yourMethod" can then receive this parameter as an Object[].

how to insert node in JSON doc in Marklogic using xdmp:node-insert

I want to insert node in a JSON document like this:
{
"fileName": "l",
"user_id": "test",
"requestId": "1232",
"feedbackType": "cpd_mah"
}
Running this code:
let $old := $doc/filename
return
xdmp:node-insert-after($old, object-node{"isSaved": ""})
but this is throwing an error XDMP-CHILDUNNAMED.
I agree with Mads, that using node-insert-child makes more sense with JSON. You can use node-insert-after though. Your attempt is throwing an XDMP-CHILDUNNAMED error because you are passing in an unnamed object node (which is basically an anonymous wrapper for its properties), rather than the named property you'd like to insert. Mads code is giving away how you can make it work:
let $old := doc("/test.json")/filename
return
xdmp:node-insert-after($old, object-node{"isSaved": ""}/isSaved)
Note: if you run it multiple times, it will replace rather than insert, since properties should be unique.
HTH!
JSON properties don't have the concept of a sibling, the way that XML elements do.
A JSON object is basically a map with a set of properties. So, rather than inserting an object as a child node after one of the properties, you want to insert a child node (notice the XPath selecting isSaved from the constructed object) of the JSON document object-node()
let $old := doc("/test.json")/object-node()
return
xdmp:node-insert-child($old, object-node{"isSaved": ""}/isSaved)
A few examples of working with JSON in XQuery from the MarkLogic documentation:
https://docs.marklogic.com/guide/app-dev/json#id_60123

jasper: listing all key-values pairs of a collection

In jasper I have to print a collection without knowing in advance the keys, because they are programmatic and can change over time. Let me do an example of this list:
formData[0]={addictions=1, workout=0, allergies=1, selfSufficiency=0}
formData[1]={gastricNose=1, weightChange=1, diet=XXXX}
[...]
formData[12]={dailyAmount=12, latestDate={type=date, value=1542582000000}, ostomy=1, ostomyType=AA, ostomyBag=BB}
How can I print a list of all these keys/values so that they get all listed properly like this? I can already print these objects raw in a list but they obviously look pretty much like the example I wrote above, while instead I need jasper to cycle through each of the elements by itself and retrieve the keys and the value for each element.
This is what I'm trying to print:
addictions: 1
workout: 0
[...]
gastricNose: 1
weightChange: 1
[...]
dailyAmount: 12
latestDate: 18/11/2018
[...]
In all posts I've looked into I'm required to know at least the name of the keys, but in my case I can't. And I cannot modify the data source structure either (for instance formatting the collection to be {key:"addictions",value:"1"} can't do that).
Thanks for your hints

Data factory lookup (dot) in the item() name

I am having lookup wherein salesforce query is there. I am using elements (item()) in subsequent activities. Till now i had item().name or item().email but now i have item().NVMStatsSF__Related_Lead__r.FirstName which has (dot) in the field name.
How should i parse it through body tag so that it reads it correctly?
So I have the following data in item()
{
"NVMStatsSF__Related_Lead__c": "00QE000egrtgrAK",
"NVMStatsSF__Agent__r.Name": "ABC",
"NVMStatsSF__Related_Lead__r.Email": "geggegg#gmail.com",
"NVMStatsSF__Related_Lead__r.FirstName": "ABC",
"NVMStatsSF__Related_Lead__r.OwnerId": "0025434535IIAW"
}
now when i use item().NVMStatsSF__Agent__r.Name it will not parse because of (dot) after NVMStatsSF__Agent__r. And it is giving me the following error.
'item().NVMStatsSF__Related_Lead__r.Email' cannot be evaluated because property 'NVMStatsSF__Related_Lead__r' doesn't exist, available properties are 'NVMStatsSF__Related_Lead__c, NVMStatsSF__Agent__r.Name, NVMStatsSF__Related_Lead__r.Email, NVMStatsSF__Related_Lead__r.FirstName, NVMStatsSF__Related_Lead__r.OwnerId'.",
"failureType": "UserError",
"target": "WebActivityToAddPerson"
this is because ADF uses '.' for object reading.
Could you find a way to rename the field name which contains '.'?
Seems like you need a built-in function to get the value of an object according to the key. Like getValue(item(), 'key.nestkey'). But unfortunately, seems there isn't such a function. You may need handle your key first.
Finally, it worked. I was being silly.
Instead of taking the value from the child table with the help of (dot) operator I just used subquery. Silly see.
And it worked.

What is [ ] in google chrome developer console?

While testing code in the google chrome developer console, i get
[]
and sometimes i get "".
The later shows up,when i think there not such strings available with the current selector combinations.But i still couldn't figure out the meaning of the former [] square brakets.
Please help.
With the information that you've given, all we can do is make assumptions. However, when you're logging things to the console, [] is an empty array, whereas "" is an empty string.
[] are returned whenever you jquery returns empty object. i.e. you selector expression cant locate what you are trying to search.
whereas "" is just simple string
i looked into your given site..
when i tried :
$('.four columns alpha') i get object[] (which means there jquery is returning empty object)
but when you write correct expression like :
$('.four.columns') you will get array of Div's which can be used like object.
Hope i'm able to make you understand. if any doubts do write.
And $('.four columns alpha') this is not the right way to select div's with more than one css class right way is to do something like below:
$('.four.columns.alpha')