rbw / aiosnow

Asynchronous ServiceNow Library
MIT License
74 stars 12 forks source link

IN and NOT IN operators not implemented for Numeric field #34

Closed sulbig closed 4 years ago

sulbig commented 4 years ago

I needed to query for incidents in state 6, 7, or 8 as well as those not in state 6, 7, or 8. I did not see an obvious way to do this. I was able to add the following functions to the Numeric() class in the numeric.py module to get what I needed:

def in_list(self, value):
    """
    Example: impact.in_list([3, 4])

    All records in which the Impact field has one of the values 3 or 4.
    """

    value = ",".join(str(v) for v in value)
    return self._condition(NumericOperator.ONEOF, value)

def not_in_list(self, value):
    """
    Example: impact.not_in_list([3, 4])

    All records in which the Impact field does not have one of the values 3 or 4.
    """

    value = ",".join(str(v) for v in value)
    return self._condition(NumericOperator.NOT_ONEOF, value)

I used the following in my select() to use it:

Incident.incident_state.not_in_list([6, 7, 8])

Should I have done this a different way?

rbw commented 4 years ago

Added in https://github.com/rbw/snow/pull/41

Thanks for your contributions btw - appreciated.

rbw commented 4 years ago

Fixed in 0.2.1