Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to fetch record details from another instance using Rest API, on a button click

Manikandan2
Kilo Expert

Hello, The requirement is:

1. Create a UI Page: Provide a textbox to enter the incident number and a button "Search" to click

2. Upon Button click - I would need to query Incident table from " Instance2 " and search for that incident. Extract certain details of that Incident and display in the same UI page.

3. Provide an option to create a New Incident in "Instance1" using these fetched incident details.

I need not have to UI page, if there is any other method of displaying data. What is the best approach i should take?

I am new to REST API's, could anyone suggested code to "GET" details?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Manikandan,

so use following approach:

1) create UI page with text box as Incident Number

2) have a button; on click of button call a function and send the value of incident number to the client script section of UI page

3) from that Client script; call a script include function using GlideAjax and send the incident number

4) consume the instance 2 table api for incident with query as number=INC00001

5) parse the response and send it back to client script

6) display that inside a paragraph tag

6) have a new button and onclick of that show a custom form where user will fill the details

7) when used hits submit/update on that form then call the table API for creating a record in instance 2

sample endpoint for GET: I have fetched values for INC0010153 and fetched column values for short_description, assignment_group, assigned_to

https://instanceName.service-now.com/api/now/table/incident?sysparm_query=number%3DINC0010153&sysparm_display_value=true&sysparm_exclude_reference_link=true&sysparm_fields=short_description%2Cassignment_group%2Cassigned_to

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Manikandan,

so use following approach:

1) create UI page with text box as Incident Number

2) have a button; on click of button call a function and send the value of incident number to the client script section of UI page

3) from that Client script; call a script include function using GlideAjax and send the incident number

4) consume the instance 2 table api for incident with query as number=INC00001

5) parse the response and send it back to client script

6) display that inside a paragraph tag

6) have a new button and onclick of that show a custom form where user will fill the details

7) when used hits submit/update on that form then call the table API for creating a record in instance 2

sample endpoint for GET: I have fetched values for INC0010153 and fetched column values for short_description, assignment_group, assigned_to

https://instanceName.service-now.com/api/now/table/incident?sysparm_query=number%3DINC0010153&sysparm_display_value=true&sysparm_exclude_reference_link=true&sysparm_fields=short_description%2Cassignment_group%2Cassigned_to

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Thanks Ankur.

Thanks for marking answer as correct.

Can you also mark it as helpful.

Regards

Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader