- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
Hi All,
I read the below class today and found it is really helpful.
Live Example/Real Time Scenario : When you are using one application in more than one instances of your company and you want to update the tables in Instance 2 when the custom is customer 2 and want to update the Instance 1 when the customer is customer 1. Based on above scenario we are updating remote table.
Note: It is very useful and doesn't require any REST API to be created 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 the examples:
1) Reading Record From Remote Table:
var gRemoteget = 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.
gRemoteget.setBasicAuth(‘user_name’,’password’); //authentication
gRemoteget.query();
while(gRemoteget.next()){
gs.info(“Value : ” + gRemoteget.getValue(‘field_name’));
}
2) Creating a new Record From Remote Table:
var gRemotecreate = 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.
gRemotecreate.setBasicAuth(‘user_name’,’password’); //authentication
gRemotecreate.initialize();
gRemotecreate.setValue("field_name","field_value"); //Setting the values
gRemotecreate.insert();
3) Updating Records in Remote Table:
var gRemoteupdate = 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.
gRemoteupdate .setBasicAuth('user_name','password'); //authentication
gRemoteupdate .addQuery('field_name', 'field_value');
gRemoteupdate .query();
while (gRemoteupdate .next()) {
gRemoteupdate .setValue('field_name', 'new_field_value');
gRemoteupdate .update();
}
4) Deleting Records in Remote Table:
var gRemotedel = 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.
gRemotedel.setBasicAuth('user_name','password');
gRemotedel.addQuery("field_name","field_value");
gRemotedel.query();
while (gRemotedel.next()) {
gRemotedel.deleteRecord();
}
Hope it helps you.
I hope this article helpful. Please mark it as helpful and bookmark if you like it.
Regards,
Shamma Negi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
