CMDB and REST API

davidbaileyritn
Kilo Contributor

I am using the REST API to get details of a CI instance :

Example https://dev20622.service-now.com/api/now/cmdb/instance/cmdb_ci_appl/82992eb60ad337024fbb6d06a866c636

 

In the response received I can see the link to the Maintenance Schedule for the CI, but when I query the Maintenance Schedule, I cannot seem to extract the start and end dates of the schedule. Can you please let me know how to go about getting all Maintenance windows associated with a CI using REST API?

 

Thanks

1 ACCEPTED SOLUTION

Rahul Priyadars
Tera Sage
Tera Sage

Hi ,

I see in Table cmn_schedule_span Two Fields:

Name:- Actual Name of Schedule Window 

Schedule- Name of Maintenance Schedule (Stored In this Table-cmn_schedule_maintenance)

Now Store the Name of Maintenance Schedule  and do lookup in Table cmn_schedule_span based on this value.

You will get the name of Schedule Window and from here you can fetch the data for Start and End Date.

Attaching Screen shot for More Clarity.

find_real_file.png

Regards

RP

View solution in original post

9 REPLIES 9

Alikutty A
Tera Sage

Hello,

You can dot walk rest APIs using the sysparm_fields parameter in the URL. I believe it cannot be done using the API explorer as URL cannot be modified. You need to specify all dot walked field at the end of URL eg:

https://<instance>.service-now.com/api/now/table/cmdb_ci_appl?sysparm_fields=maintenance_schedule.start_date,maintenance_schedule.end_date

Please see its documentation in the link: https://docs.servicenow.com/bundle/london-application-development/page/integrate/inbound-rest/concept/c_DotWalkingInRESTAPI.html

Thank you very much for the response.

Using the approach suggested I could get the name and type details of the maintenance schedule, but not the start and end dates.

For instance, when I append 

?sysparm_fields=maintenance_schedule.start_date,maintenance_schedule.end_date

to the request URL, I get an empty response. I can query name and type using the same approach

?sysparm_fields=maintenance_schedule.name,maintenance_schedule.type

Could you please let me know about the exact field names for the start/end dates of the maintenance schedule or other fields that would indicate if it repeats and such?

Thank you

 

Hello,

Inorder to get the start and end dates, you need to make multiple rest calls as these values are available in a different related table of schedules.

Your first query should fetch the maintenance schedule which will return a Sys_ID.

?sysparm_fields=maintenance_schedule

The second query should be made of cmn_schedule_span table with your sysparm_query=sys_id=value_of maintenance_schedule returned from first query along with sysparm_fields as

?sysparm_fields=end_date_time, start_date_time

Thanks!

 

Rahul Priyadars
Tera Sage
Tera Sage

Hi,

Schedule Name is stored in Table- cmn_schedule_maintenance

But actual Schedules are stored in Table -cmn_schedule_span,

You need to fetch the data from  cmn_schedule_span Table.

find_real_file.png