How to Filter ServiceNow Incidents by Multiple Affected CIs in UiPath Integration Service?

How to filter ServiceNow Incidents by Affected CI in UiPath Integration Service?

Hi everyone,

I am trying to retrieve Incident records from ServiceNow using UiPath Integration Service.

I need to apply the following filter:

Affected CI = APP-001
OR Affected CI = APP-002
AND Created on = Last 6 months
AND Assignment group = Example Support Group

However, Affected CI is not available in the Filter Builder for the List All Incident Activity. I also tried List All Records, but it is not returning the expected results.

Can I use a ServiceNow encoded query / sysparm_query in UiPath Integration Service to achieve this?

If yes, could someone please provide the correct query syntax for the above requirement?

Thanks!

Hi @Deeksha ,
Yes, if the Affected CI field is not exposed in the Integration Service filter builder, you can use a ServiceNow encoded query (sysparm_query) instead.

Try these Approach

  1. Use List All Records instead of List All Incidents.
  2. Target the Incident table (incident).
  3. Pass the encoded query in the query/filter parameter (sysparm_query).
  4. Test the query directly in ServiceNow first to verify the returned records.
  5. If cmdb_ci.name does not work in your instance, use the CI’s sys_id:

cmdb_ci=<CI_SYS_ID_1>^ORcmdb_ci=<CI_SYS_ID_2>^assignment_group=<GROUP_SYS_ID>^sys_created_on>=javascript:gs.daysAgoStart(180)

Thanks

I am trying to retrieve Incident records from ServiceNow using the UiPath ServiceNow Integration Service – List All Records activity.

I am using the Incident table and passing an encoded query in the Sysparm_query field.

My query is:“cmdb_ci=CI_SYS_ID_1^ORcmdb_ci=CI_SYS_ID_2^ORcmdb_ci=CI_SYS_ID_3^ORcmdb_ci=CI_SYS_ID_4^ORcmdb_ci=CI_SYS_ID_5^ORcmdb_ci=CI_SYS_ID_6^ORcmdb_ci=CI_SYS_ID_7^ORcmdb_ci=CI_SYS_ID_8^ORcmdb_ci=CI_SYS_ID_9^ORcmdb_ci=CI_SYS_ID_10^ORcmdb_ci=CI_SYS_ID_11^ORcmdb_ci=CI_SYS_ID_12^ORcmdb_ci=CI_SYS_ID_13^assignment_group=GROUP_SYS_ID^sys_created_on>=javascript:gs.daysAgoStart(180)”

However, I am getting the following error:

List All Records: One or more errors occurred.
(Unexpected character encountered while parsing value: <.
Path ‘’, line 0, position 0.)

I also tried using a simple query with only the Assignment Group, but I am still getting the same error.

Is this the correct way to pass a ServiceNow encoded query in the Sysparm_query field of the UiPath List All Records activity?

Could this error be related to the ServiceNow connection, API access, or ACL permissions rather than the query itself?

Any guidance would be appreciated.

Thanks!

Hi,

You can try using the Sysparm_query option instead of the Filter Builder.

For your case, something like this should work:

cmdb_ciIN<CI_SYS_ID_1>,<CI_SYS_ID_2>^sys_created_onRELATIVEGE@month@ago@6^assignment_group=<GROUP_SYS_ID>

cmdb_ci is the Affected CI field.

Since Affected CI and Assignment Group are reference fields in ServiceNow, I would recommend using the sys_id values instead of the display names.

If you already have the filter working in ServiceNow, the easiest way is to build the filter there and use Copy Query. Then paste that encoded query into the Sysparm_query field in UiPath.

Also, no need to add sysparm_query= in the value. Just paste the query itself.

Please check once if Sysparm_query is available under Manage Properties for the activity you are using.

I am getting the outcome in the output variable.

how can i now extact the exact data from that variable.

Hi @Deeksha

Yes, you can use a ServiceNow encoded query with sysparm_query for this.

For your requirement, the query would be:

cmdb_ci.nameINAPP-001,APP-002^sys_created_on>=javascript:gs.monthsAgoStart(6)^assignment_group.name=Example Support Group

If you are filtering by the actual CI sys_id instead of the CI name, use the sys_ids in the IN condition.

The IN operator handles the OR condition for the two affected CIs, while the ^ conditions work as AND.

How do i print the incident number from the output

Hi @Deeksha,

Instead of using the Filter Builder, you can pass query through the “sysparm_query” parameter.

As the Affected CI and Assignment Group are reference fields in ServiceNow, it’s better to use their sys_id values rather than the display values.

Now since the List All Records activity is returning an array of Incidents from your snap; you can use a For Each activity to iterate through the results.

Pass the output variable from the List All Records activity as the input to the For Each activity. Inside the For Each loop, add a Log Message activity and use currentItem., it will show all the values you have in the incident.

I hope this helps.

Cheers!

The currentItem is not printing the exact value

i want to print incident number

message": “UiPath.ServiceNow.IntegrationService.Activities.SWEntities.C88de8f3ed1024fe49e57c0fa3667c5e3_incident.Bundle.incident”

Hi,

Just trying to log CurrentItem would give you the type of the variable as it cannot be logged directly.

Try logging CurrentItem.number. It should return you the incident number.

Cheers!


I dont find the number property for my iterating variable

@Anil_G
can you please help me with this ?

@Deeksha

Where is that output variable from…As per local variables screenshot looks like variable has empty values

if you are getting this from some service now activity please check if you have selected columns to retreive if present in the properties of that activity

cheers

the output variable is the output of list all records activity,

i am getting results and the output varibale is of type incident and it has the data. But im struck on how to get the incident number from this.

when im iteration using fro each loop and printing the current incident its giving me the below message

“UiPath.ServiceNow.IntegrationService.Activities.SWEntities.C88de8f3ed1024fe49e57c0fa3667c5e3_incident.Bundle.incident”

@Deeksha

can you open locals panel and open the variable from there and see if it has values

because as per screenshot above it is returning list but an empty list

cheers

@Deeksha

Exactly this is the problem..the returned output is empty

May I know in the activity properties did you check what details you need

Cheers


this is the activity with the properties,

Im passing the sysparm_Query and the object is incident -/incident

@Deeksha

Can you add a variable tof irst incident as well..looks like list of incidents is giving empty values

try to change the package version and check if that resolves

cheers

@Deeksha When iterating through entity objects returned by List All Records in Integration Service, logging currentItem prints the full CLR class name because the entity object doesn’t override ToString(). In the Locals panel, the generated entity wrappers often show empty preview properties until specific fields are requested.

The simplest fix is to look at the Properties panel of your List All Records activity and click Switch to Data Table. That switches the output to a standard DataTable where you can directly access row(“number”).ToString in your loop.

If you keep the entity output, access the field using currentItem(“number”).ToString or check the exact property name in the Expression Editor by typing currentItem. and inspecting the auto-complete list for Number or sys_id.