How to call REST API from fixscript/background script
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2023 07:39 AM
Hi everybody,
I'm attempting to use a fix script to call a REST API in order to copy data from instance 1 to instance 2. I have the following script, however, it removes data from instance 1 instead. What could possibly have gone wrong?
**export XML etc is not possible as data is transferring from oob table in instance1 to a custom table in instance2
var org = gs.getProperty('instance_name');
var gn = new GlideRecord('sys_user_has_role');
while(gn.next()){
var body ={
"u_organization": org,
"u_role": gn.role.getDisplayValue(),
"state": gn.allocated_status.toString(),
};
try {
var r = new sn_ws.RESTMessageV2('Role Integration', 'Record Update');
r.setRequestBody(JSON.stringify(body));
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
} catch (ex) {
var message = ex.message;
}
}
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2023 04:53 PM
Hi @tsoct ,
You should have gn.addQuery or gn.addEncodedQuery(if you need to filter the records from sys_user_has_role table. After that you also gn.query before gn.next().