Skip to main content

parserecords(ep) = 
    foreach x in 0]
    let recordid = extractJsona{
        kind: String, selfLink: String, items:
            List<{
                subList:List
                    List<{
                        kind: String, selfLink: String, name: String
                }>
            }>
    }]

foreach hs in network.externalSources.httpSources
foreach ep in hs.endpoints
where ep.name == "endpointname" && ep.statusCode == 200
let recordItems = (min(parserecords(ep))).items
foreach i in recordItems
select {
    SrcName: hs.name,
    subListName: i.subList.name
}

///////////////////////// Oops! The query doesn't work ///////////////

Address the following issues:
    
    - Line xx, character xx: Can't access field 'name' from 'i.subList', because that is a List<{kind: String, selfLink: String, name:String}>.

A colleague provided a workable solution below; however, the subList also has a Bool field that I’d I didn’t include in my original example and I’d like to create a select violation.

 

subListName: (foreach p in i.subList select p.name)


That was correct.

  This

  subListName: (foreach p in i.subList select p.name)

  Instead of this

  subListName: i.subList.name

you need to “unpack” that list. if you could just put “name” by itself, then it would be okay. But since name is subelement “i.subList.name” then query will not unpack it for you.  I can’t think of good description for why this happens.  If you see that “ Can't access field 'name' from 'i.subList', because that is a List” it is NQE saying that you need to unpack that list yourself.

 

As for the violation.  Are you referring to this line?

  where ep.name == "endpointname" && ep.statusCode == 200

if that is what you want to make a violation, then use a “let” statement.

  let violation = "endpointname" && ep.statusCode == 200

 

if you make that a violation behind that “let” instead of a filter behind the “where” then you will see entries where this Bool is False and True not just True.


  let recordid = extractJsono{
        kind: String, selfLink: String, items:
            List<{
                subList:List
                    List<{
                        kind: String, selfLink: String, name: String, staged: Bool
                }>
            }>
    }]

 

My original example should have contained the subList field named called “staged” as type Bool. I would like to create a violation for any records where staged is true. 


Are you asking how to set that as a violation?  Just in case I’ll show you here.

Under the select statement.  Looks like it will be a list just like the “name”.  Which means you’ll need to unpack it.

  select {

      violation: (foreach x in i.subList.staged select x),

   }

It should only evaluate to “true” if all of the entries in the list are “true”.  If there is even one “false” then it will evaluate to “false”.


If I read it correctly, I think in @Tyson Henrie ‘s comment, the violation field will be a list of booleans. To have it be correctly interpreted as a violation field, it needs to be a boolean. You can do that by taking the min of the list of booleans. That works because min will be false if any of the items in the list are false. So it could be something like this:

select {

violation: min(foreach x in i.subList select x.staged),

}

 


If I read it correctly, I think in @Tyson Henrie ‘s comment, the violation field will be a list of booleans. To have it be correctly interpreted as a violation field, it needs to be a boolean. You can do that by taking the min of the list of booleans. That works because min will be false if any of the items in the list are false. So it could be something like this:

select {

violation: min(foreach x in i.subList select x.staged),

}

 

Perfect; thank you.


Reply