Aravind Pillai
Aravind Pillai

Reputation: 771

How to select specific columns alone using Query.make()

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?

Upvotes: 0

Views: 3213

Answers (5)

shaher
shaher

Reputation: 21

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!

Upvotes: 0

shaher
shaher

Reputation: 21

You can try the below code.

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

Upvotes: 1

Py-Coder
Py-Coder

Reputation: 2234

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)`
}

Upvotes: 0

Thejaswini
Thejaswini

Reputation: 11

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.

Upvotes: 1

Aravind Pillai
Aravind Pillai

Reputation: 771

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

Upvotes: 1

Related Questions