- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 12-10-2023 09:53 AM
When aiming to synchronize data between instances, our primary focus naturally shifts to REST/SOAP API integration.
While going through from one of the requirement, I've explored a way that allows seamless data synchronization between different ServiceNow instances. It's a bit like using "GlideRecord," and it's called "GlideRemoteGlideRecord." This adds an interesting twist to how we can smoothly perform CRUD operations between instances.
Using "GlideRemoteGlideRecord," it is possible to connect to tables in other instances, allowing for the retrieval/creation/updation/deletion of records. Below are examples demonstrating these functionalities:
1) Reading Record From Remote Table:
var gRemote = new GlideRemoteGlideRecord('https://devXXXXX.service-now.com',’table_name’); // Param 1 is the servicenow instance of which you want to access the table, param 2 is the name of the table.
gRemote.setBasicAuth(‘user_name’,’password’); //authentication
gRemote.query();
while(gRemote.next()){
gs.info(“Value : ” + gRemote.getValue(‘field_name’));
}
2) Creating a new Record From Remote Table:
var gRemote = new GlideRemoteGlideRecord('https://devXXXXX.service-now.com',’table_name’); // Param 1 is the servicenow instance of which you want to access the table, param 2 is the name of the table.
gRemote.setBasicAuth(‘user_name’,’password’); //authentication
gRemote.initialize();
gRemote.setValue("field_name","field_value"); //Setting the values
gRemote.insert();
3) Updating Records in Remote Table:
var gRemote = new GlideRemoteGlideRecord('https://devXXXXX.service-now.com',’table_name’); // Param 1 is the servicenow instance of which you want to access the table, param 2 is the name of the table.
gRemote.setBasicAuth('user_name','password'); //authentication
gRemote.addQuery('field_name', 'field_value');
gRemote.query();
while (gRemote.next()) {
gRemote.setValue('field_name', 'new_field_value');
gRemote.update();
}
4) Deleting Records in Remote Table:
var gRemote = new GlideRemoteGlideRecord('https://devXXXXX.service-now.com',’table_name’); // Param 1 is the servicenow instance of which you want to access the table, param 2 is the name of the table.
gRemote.setBasicAuth('user_name','password');
gRemote.addQuery("field_name","field_value");
gRemote.query();
while (gRemote.next()) {
gRemote.deleteRecord();
}
Happy Reading!! 😊
If you find the above article helpful , Please give me a 👍 on the post!!
- 1,877 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Very helpful!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@Prince Arora The username and password in the authentication part are the ones that used in order to login to the desired instance? It could be any user ? Or he needs to have specific roles ?