how to sync user,group and role Production To Dev Instance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2018 10:22 AM
Hi All,
I'm looking sync user , group and roles from Production and QA.
Because daily creating new user adding groups and roles in the production again need to re-create in the development instance.
whether it can be automated task using the script by scheduling job/business script running the script weekly or monthly and also
user will be created specific domain or company.
Thanks in advance.
Regards,
Charan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2018 09:23 AM
Dear Charanraj,
Can you post the error message again.. I dont see it in the earlier comment.
Thanks
Anil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2018 10:37 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2018 12:18 PM
Dear Charanraj,
Please use this updated script
var tableName = 'sys_user';
var uniqueValue = 'sys_id'; // Provide Unique Value
var query = "sys_updated_on%3E%3Djavascript%3Ags.beginningOfLast3Months()";
var instanceUrl = 'https://dev38250.service-now.com/';
var restApiName = 'KingstonInstance';
var restApiMethodName = 'getUsers';
copyRecords(tableName, query,instanceUrl, restApiName, restApiMethodName, uniqueValue);
function copyRecords(tableName, query, instanceUrl, restApiName, restApiMethodName, uniqueValue) {
// if(uniqueValue == undefined) {
// //uniqueValue = getUniqueValue(tableName);
// }
var sDebug = '';
var endPointUrl = instanceUrl+ 'api/now/table/' + tableName + '?sysparm_query=' + query;
sDebug+= 'endPointUrl = ' + endPointUrl;
sDebug +='\n' + 'restApiName = ' + restApiName;
sDebug += '\n' + 'restApiMethodName = ' + restApiMethodName;
var r = new sn_ws.RESTMessageV2(restApiName, restApiMethodName);
r.setEndpoint(endPointUrl);
var response = r.execute();
var responseBody = response.getBody();
var jsonPayload = JSON.parse(responseBody);
var headers = response.getHeaders();
var rowCount = headers['X-Total-Count'];
sDebug += '\n' + 'Row Count = ' + rowCount;
for (var i=0; i< rowCount; i++) {
var grTable = new GlideRecord(tableName);
grTable.get(jsonPayload.result[i][uniqueValue]);
if(!grTable.isValid()) {
grTable.newRecord();
for (var j in jsonPayload.result[i]) {
//gs.print(j +"=" + jsonPayload.result[0][j]);
grTable[j] = jsonPayload.result[i][j] + '';
}
try {
grTable.insert();
}catch(e) {
gs.log("invalid insert");
}
}
}
gs.print(sDebug);
}
function getUniqueValue(tableName) {
var query ='unique=true^name=' + tableName;
var grDict = new GlideRecord('sys_dictionary');
grDict.addEncodedQuery(query);
grDict.query();
if(grDict.next()) {
}
}
Thanks
Anil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2018 02:39 PM
Hi Anil,
thanks for new updated script i will check and update on this.
small change condition whenever new user or group is created production automatically need to created in the development instance.
Thanks,
Charan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2018 02:51 PM
in order to achieve that you need to create a business rule in production and trigger a script that creates a record in dev instance. Pls let me know if you need help with the script.