
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2022 09:33 PM
Hi Team,
Currently we are copying production over non-prod instance once in a month and we manually export/import update or created user/group records from production to non-prod instances. We have a requirement now that we need pull these newly created or updated records automatically from production instance.
Please share your inputs or solution if you have implemented similar set-up. Any input on this would be much appreciated.
Thanks,
Fedrick
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2022 11:16 PM
Hello Feddy,
You can use the something like below script to get the Record from your production instance and create the recods with same sys_id in your dev instance:
You need to replace the your PROD instance, tableName and sysparm_query (used name in this example) in the below script and can run this in background script for testing on your Dev instance and later on run in scheduled job.
You may need to create separate Scheduled Job for User, Group, Group Member, User Role etc to sync the data from required table and can use query created at or after yesterday something like this.
Also, you need to provide the username and password of the user from PROD instance.
This is a generic solution and you may need to make changes as per your requirement.
(function () {
var tableName = "cmdb_ci_server";
var RESOURCE_PATH = "/api/now/table/" + tableName;
var request = new sn_ws.RESTMessageV2();
request.setEndpoint("https://<YOUR_PROD_INSTNCE>.service-now.com/"+RESOURCE_PATH );
request.setHttpMethod('GET');
request.setQueryParameter("sysparm_query", "name=ApplicationServerHelpdesk");
//Eg. UserName="admin", Password="admin" for this code sample.
var user = 'admin';
var password = 'admin';
request.setBasicAuth(user,password);
//gs.print(JSON.stringify(requestBody));
//request.setRequestBody(JSON.stringify(requestBody));
request.setRequestHeader("Accept","application/json");
var response = request.execute();
var responseBody = response.getBody();
gs.print(responseBody);
var jsonResponse = JSON.parse(responseBody);
var responseResult = jsonResponse["result"];
for (var record in responseResult) {
var cmdbServer = new GlideRecord(tableName);
cmdbServer.newRecord();
var insertRecord = false;
var recordData = responseResult[record];
for (var data in recordData) {
var fieldName = "";
var fieldValue = "";
if (fieldName == "sys_id") {
cmdbServer.setNewGuidValue(fieldValue);
} else if (typeof recordData[data] == "object") {
fieldName = data;
fieldValue = recordData[data]["value"];
gs.print(fieldName + " : " + fieldValue);
} else {
fieldName = data;
fieldValue = recordData[data];
gs.print(fieldName + " : " + fieldValue);
}
if (fieldName && fieldValue) {
insertRecord = true;
cmdbServer.setValue(fieldName, fieldValue);
}
}
if (insertRecord) {
cmdbServer.insert()
}
}
})();
Please mark my respsone as helpful/correct, if it answer your question.
You can start with this and if you have any other question specific you your integration you can asked raise other question.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2022 04:05 AM
Hi,
It's just like a normal API call.
sharing links for help
Is there a way to synch up tables from Prod to all sub instances?
Integration between two SN instances
REST message integration between two SNow instances
Outbound REST message integration
How can I can integrate two ServiceNow instances ?
regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2022 08:33 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2022 03:45 AM
Hi,
you have to export the data of groups, group members, roles from different tables.
First you need to export users(sys_user) XML and import on target instance and then refer below link and export XML data accordingly and import on target instance of same table.
https://www.basicoservicenowlearning.in/2020/08/import-user-role-group-servicenow.html#:~:text=So%20first%20open%20Target%20instance,and%20click%20on%20upload%20button.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2022 04:04 AM
Hi Pavan,
Thank you for your inputs.
We have been doing this manually but we would like to automate this process. We would like to pull newly created user or group record from prod to lower instance and daily or with frequent interval. Right now, new users and groups are only copied down to the lower environments when clones are done (which is about once a month) and this is not often enough.
Could you please share with me some docs or any inputs on this above?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2022 04:46 AM
Hi,
Definitely Cloning is one option but you don't want that option.
Then if you planning for the data sync on the both the instance then you have to do Uni directional REST integration from prod to dev then once user is created it will be creates a user record in dev.
similarly you have to do for groups and roles.
I do not see any other options for this one only one that is REST web services.
REST calls between two ServiceNow instances is simple.
Target instance(Dev) you need to create inbound web services and source instance(Prod) you need to set those end points on REST message and trigger through business rule.
Links:
https://community.servicenow.com/community?id=community_question&sys_id=673c4b65db9cdbc01dcaf3231f961906
https://www.basicoservicenowlearning.in/2020/01/servicenow-integration-using-rest.html#:~:text=ServiceNow%20Integration%20Using%20Rest%20API%20%7C%20ServiceNow%20Rest%20Integration%3A,export%2C%20CTI%2C%20Email%20etc.
https://docs.servicenow.com/bundle/paris-application-development/page/integrate/outbound-rest/concept/c_OutboundRESTWebService.html
Hope you it helps you.
Please Mark ✅ Correct/helpful if applicable, Thanks!!
Regards
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
Hope you it helps you.
Please Mark ✅ Correct/helpful if applicable, Thanks!!
Regards
Pavankumar