0

In guidewire, Query.make(EntityName).select() returns the entire column values, How should be the code if I need column specific result.

For eg, If I just need PolicyNumber , PublicID and ID alone from Policy table, How should I write the code?

Aravind Pillai
  • 739
  • 7
  • 21

5 Answers5

1

can you please try the below code.

var temp=Query.make(entity.Claim).select( \ row -> row.ClaimNumber)

Still not sure about it though.

shaher
  • 21
  • 2
1
var op = Query.make(PolicyPeriod).select({
    QuerySelectColumns.pathWithAlias("PolicyNumber", Paths.make(PolicyPeriod#PolicyNumber)),
    QuerySelectColumns.pathWithAlias("OfferNumber", Paths.make(PolicyPeriod#OfferNumber)),
    QuerySelectColumns.pathWithAlias("Id", Paths.make(PolicyPeriod#ID))
})

foreach(o in op){
  print(" Policy No : "+o.getColumn("PolicyNumber") +" | Offer No : "+o.getColumn("OfferNumber")+" | ID : "+o.getColumn("Id"))
}

enter image description here

Aravind Pillai
  • 739
  • 7
  • 21
1

I had the some question and I found the answer for this. It is already commented above and I agree with them, adding left out code.

var temp=Query.make(entity.Claim).select( \ row -> {return { row.ClaimNumber} as String[]})
for(row in temp){
print("Claim Number = " + row[0])
}

where \ is lambda.

I have tested this and it is working fine.

Thejaswini
  • 11
  • 1
0

You never mentioned that you wanted to optimize. Please try the below code.

var temp=Query.make(entity.Policy).compare("PolicyNumber" , Equals, "123456").select()

You can use other functions like Joins. Please let me know if it works or my understanding is right!

shaher
  • 21
  • 2
  • Brother, What your code will do is, it will return the results where "policy No" = '12345'. To be little more clear, it returns the particular (or group of) row where policy matches the given value along with the other fields . SQL Query for ur code will be like "SELECT * FROM TABLENAME WHERE xxx = yyy". But in my requirement I dont what that '*' in SELECT query. I just want the "PolicyNo" field alone. hope this makes sense. In my question I have clearly mentioned like "HOW TO SELECT SPECIFIC COLUMNS" from table – Aravind Pillai May 17 '17 at 08:27
  • Thanks Shaher, Please let me know , how to use joins . Say we have ABContact and Banks table. – shrikanth Jun 21 '19 at 05:46
0

It's simple,

Uses GW.api.database.Query
Var d=Query.make(PolicyPeriod).select()
For ( a in d){
Print ( d.PolicyNumber +" = " + d.ID +" = " + `d.PublicID)`
}
Py-Coder
  • 2,024
  • 1
  • 22
  • 28