Closed fartbagxp closed 4 years ago
It returns nothing, and I'm wondering if I have to create an Assignment Group schema created.
Yes, I'm aware of this. Relations are queried by sys_id if not using a PartialSchema
. While this is not a bug, I do agree automatically querying by name in this case would be more natural.
Currently, if you want to query by name, you can use a PartialSchema
:
class AssignmentGroup(PartialSchema):
sys_id = fields.Text()
name = fields.Text()
class Incident(Schema):
__location__ = "/api/now/table/incident"
number = fields.Text()
assignment_group = AssignmentGroup
selection = select(
Incident.assignment_group.name.equals("Service Desk")
).order_desc(Incident.number)
Building support for querying by a related table's field without using PartialSchema
shouldn't be too hard.
What's your take on something like this?:
assignment_group = fields.Text(pluck=Joined.DISPLAY_VALUE, query_by="assignment_group.name")
...or perhaps always use related table's name when plucking display value. That'd be somewhat inflexible and implicit though. Hmm.. need to do some pondering on this.
Ahh, I didn't know the existence of PartialSchema
.
The following is clear to me, provided that I use a PartialSchema
.
selection = select(
Incident.assignment_group.name.equals("Service Desk")
).order_desc(Incident.number)
I prefer not having something like query_by - it feels like a bit of a hack to put that in, but may be useful in some other cases.
This might be more of an example / nudge of how the users is intended to use the library. I much prefer the Incident.assignment_group.name.equals("Service Desk")
.
Thank you!
No problem.
It's covered in the documentation here: https://python-snow.readthedocs.io/en/latest/reference/resource/schema.html#nesting
I can't get any results using a query against a particular assignment group. It returns nothing, and I'm wondering if I have to create an Assignment Group schema created.
I have a simple schema.
I spun up a ServiceNow test instance and this assignment group seems like a common group.![image](https://user-images.githubusercontent.com/8839850/79503503-42a94900-7fff-11ea-87b2-1ff0e58c0cef.png)
I tried with datetime query selection and those are working, just not the one for assignment group.
Any help is much appreciated.