2

assigned_to field is not getting filtered

Code:

__encoded_query = "assigned_toCONTAINSsteve"

Actually 2 records containing values with steve but not returned with above code. Also related_records field is not working with __encoded_query

Earth
  • 3,477
  • 6
  • 37
  • 78

1 Answers1

1

assigned_to is a reference field, which stores the sys_id of the referenced sys_user record, but you're querying on what I assume is the display value (name). If you want to query for records where the assigned_to field refers to a user with a name that contains "steve", try dot-walking through the reference like this:

__encoded_query = "assigned_to.nameCONTAINSsteve"

For what it's worth, that could be a poorly performing query, you might be better off doing a STARTSWITH query, which is more optimizable (from a database standpoint):

__encoded_query = "assigned_to.nameSTARTSWITHsteve"

Here's what the full SOAP request payload looks like in a test I just ran on a demo instance (where I didn't have any steves, but I had a Fred!):

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <Body>
        <getRecords xmlns="http://www.service-now.com/incident">
            <__encoded_query xmlns="">assigned_to.nameSTARTSWITHfred</__encoded_query>
        </getRecords>
    </Body>
</Envelope>
Joey
  • 2,901
  • 21
  • 22
  • Please give solution on how to acheive `related_records` – Earth Oct 15 '15 at 05:56
  • I want to get the record that contains the value `prj12345` in `related_records` field. I tried with `related_recordsCONTAINSprj12345` but not succeeded. Please provide solution. I also tried with `related_records.nameCONTAINSprj12345`. – Earth Oct 15 '15 at 06:08
  • It depends on the type of the `related_records` field. I'm assuming it's a glide_list, in which case it's probably going to store a comma-delimited list of sys_ids, so you'll first need to get the sys_id of the target record and then do a contains search with that (e.g. "related_recordsCONTAINS"). – Joey Oct 15 '15 at 17:24
  • Yes, I had achieved the task already as you mentioned. Thanks. – Earth Oct 16 '15 at 06:23