Populate Import set row from API call
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2024 09:44 AM
Hey all. I need to use an outbound rest call to get UIPath job information and then populate a CMDB table with the info. I have the REST message set and can get data back with it, but I cannot seem to get the data out of it.
I need to loop through each value entry and populate a row with all the name/value pairs for each. No matter what i try, I just get
[object Object]
Anyone able to help me?
Example script call:
try {
gs.log("CDL: 1. Start");
var rProcess = new sn_ws.RESTMessageV2('Global_UIPathAPICalls', 'GET_Processes');
rProcess.setEccParameter('skip_sensor', true);
var processResponse = rProcess.execute();
gs.log("CDL: 2. rProcess\n" + rProcess);
processResponse.waitForResponse(360);
// var processResponseBody = processResponse.getBody();
// var processHttpStatus = processResponse.getStatusCode();
// parse initial response
var processResponseBody = processResponse.getBody();
var processHttpStatus = processResponse.getStatusCode();
var processParser = new JSONParser();
var processResponseParse = processParser.parse(processResponseBody);
gs.log("CDL: 3. processResponseParse\n" + processResponseParse);
var processData = processResponseParse.value;
gs.log("CDL: 4. processData\n" + processData);
for (var i = 0; i < processData.length; i++) {
gs.log("CDL: \n" + [i] + "\n" + processData[i]);
}
}
catch(ex) {
var message = ex.message;
}
Example of the returned data:
{
"@odata.context": "https://cloud.uipath.com/LazardInnovation/Sandlot/orchestrator_/odata/$metadata#Jobs",
"@odata.count": 738,
"value": [
{
"Key": "592ebe4a-ee91-4792-8bc0-4fe127d0f0f9",
"StartTime": "2023-09-28T04:13:00.087Z",
"EndTime": "2023-09-28T04:13:06.017Z",
"State": "Successful",
"JobPriority": "Normal",
"SpecificPriorityValue": 45,
"ResourceOverwrites": null,
"Source": "Manual",
"SourceType": "Manual",
"BatchExecutionKey": "3411435e-f624-49eb-bfc9-f7cc8aa45be7",
"Info": "Job completed",
"CreationTime": "2023-09-28T04:12:59.68Z",
"StartingScheduleId": null,
"ReleaseName": "PIB_LazardStorageCleanup",
"Type": "Unattended",
"InputArguments": null,
"OutputArguments": "{}",
"HostMachineName": "DESKTOP-9SNDI06",
"HasMediaRecorded": false,
"HasVideoRecorded": false,
"PersistenceId": null,
"ResumeVersion": null,
"StopStrategy": null,
"RuntimeType": "NonProduction",
"RequiresUserInteraction": true,
"ReleaseVersionId": 387287,
"EntryPointPath": "Main.xaml",
"OrganizationUnitId": 727682,
"OrganizationUnitFullyQualifiedName": "Sandlot/Shared/Unattended",
"Reference": "",
"ProcessType": "Process",
"ProfilingOptions": null,
"ResumeOnSameContext": false,
"LocalSystemAccount": "LAZARD\\RPA_UAT_704",
"OrchestratorUserIdentity": null,
"RemoteControlAccess": "None",
"StartingTriggerId": null,
"MaxExpectedRunningTimeSeconds": null,
"ServerlessJobType": null,
"ResumeTime": null,
"LastModificationTime": "2023-09-28T04:13:06.017Z",
"Id": 31750189
},
{
"Key": "00cdc1fc-38cf-48e1-a2ae-384fa477cb7b",
"StartTime": "2023-09-28T04:19:59.007Z",
"EndTime": "2023-09-28T04:20:05.5Z",
"State": "Successful",
"JobPriority": "Normal",
"SpecificPriorityValue": 45,
"ResourceOverwrites": null,
"Source": "Manual",
"SourceType": "Manual",
"BatchExecutionKey": "818ad175-9584-410d-b1d2-62764cf4f76b",
"Info": "Job completed",
"CreationTime": "2023-09-28T04:19:58.62Z",
"StartingScheduleId": null,
"ReleaseName": "PIB_LazardStorageCleanup",
"Type": "Unattended",
"InputArguments": null,
"OutputArguments": "{}",
"HostMachineName": "DESKTOP-9SNDI06",
"HasMediaRecorded": false,
"HasVideoRecorded": false,
"PersistenceId": null,
"ResumeVersion": null,
"StopStrategy": null,
"RuntimeType": "NonProduction",
"RequiresUserInteraction": true,
"ReleaseVersionId": 387287,
"EntryPointPath": "Main.xaml",
"OrganizationUnitId": 727682,
"OrganizationUnitFullyQualifiedName": "Sandlot/Shared/Unattended",
"Reference": "",
"ProcessType": "Process",
"ProfilingOptions": null,
"ResumeOnSameContext": false,
"LocalSystemAccount": "LAZARD\\RPA_UAT_704",
"OrchestratorUserIdentity": null,
"RemoteControlAccess": "None",
"StartingTriggerId": null,
"MaxExpectedRunningTimeSeconds": null,
"ServerlessJobType": null,
"ResumeTime": null,
"LastModificationTime": "2023-09-28T04:20:05.5Z",
"Id": 31751169
},
{
"Key": "a00c8088-14a2-4a91-9c88-3aa6f4576b98",
"StartTime": "2023-09-28T04:22:01.693Z",
"EndTime": "2023-09-28T04:22:05.293Z",
"State": "Successful",
"JobPriority": "Normal",
"SpecificPriorityValue": 45,
"ResourceOverwrites": null,
"Source": "Manual",
"SourceType": "Manual",
"BatchExecutionKey": "d35a6c58-ecd8-4343-82d9-f11d3f34d478",
"Info": "Job completed",
"CreationTime": "2023-09-28T04:22:01.5Z",
"StartingScheduleId": null,
"ReleaseName": "PIB_LazardStorageCleanup",
"Type": "Unattended",
"InputArguments": null,
"OutputArguments": "{}",
"HostMachineName": "DESKTOP-9SNDI06",
"HasMediaRecorded": false,
"HasVideoRecorded": false,
"PersistenceId": null,
"ResumeVersion": null,
"StopStrategy": null,
"RuntimeType": "NonProduction",
"RequiresUserInteraction": true,
"ReleaseVersionId": 387287,
"EntryPointPath": "Main.xaml",
"OrganizationUnitId": 727682,
"OrganizationUnitFullyQualifiedName": "Sandlot/Shared/Unattended",
"Reference": "",
"ProcessType": "Process",
"ProfilingOptions": null,
"ResumeOnSameContext": false,
"LocalSystemAccount": "LAZARD\\RPA_UAT_704",
"OrchestratorUserIdentity": null,
"RemoteControlAccess": "None",
"StartingTriggerId": null,
"MaxExpectedRunningTimeSeconds": null,
"ServerlessJobType": null,
"ResumeTime": null,
"LastModificationTime": "2023-09-28T04:22:05.293Z",
"Id": 31751653
},
{
"Key": "a0868fe3-2e76-40ff-b7d0-913a89b16f68",
"StartTime": "2024-01-12T14:00:06.26Z",
"EndTime": "2024-01-12T14:05:47.323Z",
"State": "Successful",
"JobPriority": "Normal",
"SpecificPriorityValue": 45,
"ResourceOverwrites": null,
"Source": "CyberArk Library Bot (Sandlot)",
"SourceType": "Schedule",
"BatchExecutionKey": "314534dc-2fdc-4241-bcc0-bfdfbfe5a902",
"Info": "Job completed",
"CreationTime": "2024-01-12T14:00:05.707Z",
"StartingScheduleId": 43444,
"ReleaseName": "CyberArk Library Bot (Sandlot)",
"Type": "Unattended",
"InputArguments": null,
"OutputArguments": "{}",
"HostMachineName": "DESKTOP-9SNDI06",
"HasMediaRecorded": false,
"HasVideoRecorded": false,
"PersistenceId": null,
"ResumeVersion": null,
"StopStrategy": null,
"RuntimeType": "NonProduction",
"RequiresUserInteraction": true,
"ReleaseVersionId": 422041,
"EntryPointPath": "Main.xaml",
"OrganizationUnitId": 727682,
"OrganizationUnitFullyQualifiedName": "Sandlot/Shared/Unattended",
"Reference": "",
"ProcessType": "Process",
"ProfilingOptions": null,
"ResumeOnSameContext": false,
"LocalSystemAccount": "LAZARD\\RPA_UAT_704",
"OrchestratorUserIdentity": null,
"RemoteControlAccess": "None",
"StartingTriggerId": null,
"MaxExpectedRunningTimeSeconds": null,
"ServerlessJobType": null,
"ResumeTime": null,
"LastModificationTime": "2024-01-12T14:05:47.323Z",
"Id": 58798630
}
]
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2024 12:55 PM
This worked for me in background scripts.
Are you able to try it out in background scripts of the isntance.
var jsonData = {
"@odata.context": "https://cloud.uipath.com/LazardInnovation/Sandlot/orchestrator_/odata/$metadata#Jobs",
"@odata.count": 738,
"value": [
{
"Key": "592ebe4a-ee91-4792-8bc0-4fe127d0f0f9",
"StartTime": "2023-09-28T04:13:00.087Z",
"EndTime": "2023-09-28T04:13:06.017Z",
"State": "Successful",
"JobPriority": "Normal",
"SpecificPriorityValue": 45,
"ResourceOverwrites": null,
"Source": "Manual",
"SourceType": "Manual",
"BatchExecutionKey": "3411435e-f624-49eb-bfc9-f7cc8aa45be7",
"Info": "Job completed",
"CreationTime": "2023-09-28T04:12:59.68Z",
"StartingScheduleId": null,
"ReleaseName": "PIB_LazardStorageCleanup",
"Type": "Unattended",
"InputArguments": null,
"OutputArguments": "{}",
"HostMachineName": "DESKTOP-9SNDI06",
"HasMediaRecorded": false,
"HasVideoRecorded": false,
"PersistenceId": null,
"ResumeVersion": null,
"StopStrategy": null,
"RuntimeType": "NonProduction",
"RequiresUserInteraction": true,
"ReleaseVersionId": 387287,
"EntryPointPath": "Main.xaml",
"OrganizationUnitId": 727682,
"OrganizationUnitFullyQualifiedName": "Sandlot/Shared/Unattended",
"Reference": "",
"ProcessType": "Process",
"ProfilingOptions": null,
"ResumeOnSameContext": false,
"LocalSystemAccount": "LAZARD\\RPA_UAT_704",
"OrchestratorUserIdentity": null,
"RemoteControlAccess": "None",
"StartingTriggerId": null,
"MaxExpectedRunningTimeSeconds": null,
"ServerlessJobType": null,
"ResumeTime": null,
"LastModificationTime": "2023-09-28T04:13:06.017Z",
"Id": 31750189
},
{
"Key": "00cdc1fc-38cf-48e1-a2ae-384fa477cb7b",
"StartTime": "2023-09-28T04:19:59.007Z",
"EndTime": "2023-09-28T04:20:05.5Z",
"State": "Successful",
"JobPriority": "Normal",
"SpecificPriorityValue": 45,
"ResourceOverwrites": null,
"Source": "Manual",
"SourceType": "Manual",
"BatchExecutionKey": "818ad175-9584-410d-b1d2-62764cf4f76b",
"Info": "Job completed",
"CreationTime": "2023-09-28T04:19:58.62Z",
"StartingScheduleId": null,
"ReleaseName": "PIB_LazardStorageCleanup",
"Type": "Unattended",
"InputArguments": null,
"OutputArguments": "{}",
"HostMachineName": "DESKTOP-9SNDI06",
"HasMediaRecorded": false,
"HasVideoRecorded": false,
"PersistenceId": null,
"ResumeVersion": null,
"StopStrategy": null,
"RuntimeType": "NonProduction",
"RequiresUserInteraction": true,
"ReleaseVersionId": 387287,
"EntryPointPath": "Main.xaml",
"OrganizationUnitId": 727682,
"OrganizationUnitFullyQualifiedName": "Sandlot/Shared/Unattended",
"Reference": "",
"ProcessType": "Process",
"ProfilingOptions": null,
"ResumeOnSameContext": false,
"LocalSystemAccount": "LAZARD\\RPA_UAT_704",
"OrchestratorUserIdentity": null,
"RemoteControlAccess": "None",
"StartingTriggerId": null,
"MaxExpectedRunningTimeSeconds": null,
"ServerlessJobType": null,
"ResumeTime": null,
"LastModificationTime": "2023-09-28T04:20:05.5Z",
"Id": 31751169
},
{
"Key": "a00c8088-14a2-4a91-9c88-3aa6f4576b98",
"StartTime": "2023-09-28T04:22:01.693Z",
"EndTime": "2023-09-28T04:22:05.293Z",
"State": "Successful",
"JobPriority": "Normal",
"SpecificPriorityValue": 45,
"ResourceOverwrites": null,
"Source": "Manual",
"SourceType": "Manual",
"BatchExecutionKey": "d35a6c58-ecd8-4343-82d9-f11d3f34d478",
"Info": "Job completed",
"CreationTime": "2023-09-28T04:22:01.5Z",
"StartingScheduleId": null,
"ReleaseName": "PIB_LazardStorageCleanup",
"Type": "Unattended",
"InputArguments": null,
"OutputArguments": "{}",
"HostMachineName": "DESKTOP-9SNDI06",
"HasMediaRecorded": false,
"HasVideoRecorded": false,
"PersistenceId": null,
"ResumeVersion": null,
"StopStrategy": null,
"RuntimeType": "NonProduction",
"RequiresUserInteraction": true,
"ReleaseVersionId": 387287,
"EntryPointPath": "Main.xaml",
"OrganizationUnitId": 727682,
"OrganizationUnitFullyQualifiedName": "Sandlot/Shared/Unattended",
"Reference": "",
"ProcessType": "Process",
"ProfilingOptions": null,
"ResumeOnSameContext": false,
"LocalSystemAccount": "LAZARD\\RPA_UAT_704",
"OrchestratorUserIdentity": null,
"RemoteControlAccess": "None",
"StartingTriggerId": null,
"MaxExpectedRunningTimeSeconds": null,
"ServerlessJobType": null,
"ResumeTime": null,
"LastModificationTime": "2023-09-28T04:22:05.293Z",
"Id": 31751653
},
{
"Key": "a0868fe3-2e76-40ff-b7d0-913a89b16f68",
"StartTime": "2024-01-12T14:00:06.26Z",
"EndTime": "2024-01-12T14:05:47.323Z",
"State": "Successful",
"JobPriority": "Normal",
"SpecificPriorityValue": 45,
"ResourceOverwrites": null,
"Source": "CyberArk Library Bot (Sandlot)",
"SourceType": "Schedule",
"BatchExecutionKey": "314534dc-2fdc-4241-bcc0-bfdfbfe5a902",
"Info": "Job completed",
"CreationTime": "2024-01-12T14:00:05.707Z",
"StartingScheduleId": 43444,
"ReleaseName": "CyberArk Library Bot (Sandlot)",
"Type": "Unattended",
"InputArguments": null,
"OutputArguments": "{}",
"HostMachineName": "DESKTOP-9SNDI06",
"HasMediaRecorded": false,
"HasVideoRecorded": false,
"PersistenceId": null,
"ResumeVersion": null,
"StopStrategy": null,
"RuntimeType": "NonProduction",
"RequiresUserInteraction": true,
"ReleaseVersionId": 422041,
"EntryPointPath": "Main.xaml",
"OrganizationUnitId": 727682,
"OrganizationUnitFullyQualifiedName": "Sandlot/Shared/Unattended",
"Reference": "",
"ProcessType": "Process",
"ProfilingOptions": null,
"ResumeOnSameContext": false,
"LocalSystemAccount": "LAZARD\\RPA_UAT_704",
"OrchestratorUserIdentity": null,
"RemoteControlAccess": "None",
"StartingTriggerId": null,
"MaxExpectedRunningTimeSeconds": null,
"ServerlessJobType": null,
"ResumeTime": null,
"LastModificationTime": "2024-01-12T14:05:47.323Z",
"Id": 58798630
}
]
}
var master = JSON.stringify(jsonData);
var parsedData = JSON.parse(master);
gs.print(parsedData.value.length)
// Loop through the "value" array using for loop
for (var i = 0; i < parsedData.value.length; i++) {
var job = parsedData.value[i];
// gs.print(job.Key)
gs.print("Job Key:" + job.Key);
// gs.print("Job State:", job.State);
// ... (access other properties as needed)
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2024 01:01 PM
Hello @conanlloyd ,
You can give a try to the script below and let me know how it works for you.
try {
gs.log("CDL: 1. Start");
// Make the REST call
var rProcess = new sn_ws.RESTMessageV2('Global_UIPathAPICalls', 'GET_Processes');
rProcess.setEccParameter('skip_sensor', true);
var processResponse = rProcess.execute();
gs.log("CDL: 2. rProcess\n" + rProcess);
processResponse.waitForResponse(360);
// Parse the response
var processResponseBody = processResponse.getBody();
var processHttpStatus = processResponse.getStatusCode();
var processParser = new JSONParser();
var processResponseParse = processParser.parse(processResponseBody);
gs.log("CDL: 3. processResponseParse\n" + processResponseParse);
var processData = processResponseParse.value;
gs.log("CDL: 4. processData\n" + processData);
// Iterate through the array and create records in the CMDB table
for (var i = 0; i < processData.length; i++) {
var cmdbRecord = new GlideRecord('your_cmdb_table'); // Replace 'your_cmdb_table' with the actual table name
// Map the UIPath data to your CMDB fields
cmdbRecord.setValue('key_field', processData[i].Key);
cmdbRecord.setValue('start_time', processData[i].StartTime);
cmdbRecord.setValue('end_time', processData[i].EndTime);
// Map other fields accordingly
// Insert the record
var recordSysId = cmdbRecord.insert();
gs.log("CDL: Created CMDB record with Sys ID: " + recordSysId);
}
}
catch(ex) {
var message = ex.message;
gs.log("CDL: Error - " + message);
}
Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2024 11:28 AM
Hello @conanlloyd
I wanted to check in regarding the response I provided. If my suggestions were beneficial in addressing your query or helped in resolving your issue, would you mind marking it as helpful, accepting the solution, and closing the thread? Your acknowledgment not only shows appreciation for the assistance but also assists future readers who might come across a similar problem.
Thank you for your consideration!
Best regards,
Aniket.