-
I have a script that finds all tasks associated with a specific queue (let's call it XGroup) and a string in the short description. The task search/retrieval takes about 6 minutes since there are almost 300 tasks that meet the criteria. I then need to loop those task IDs through the requested items to get data from the custom variable. Doing this causes the script to run for so long that I end up killing it and only getting about 70 results. Is there a faster way to perform this process? Example:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
@DrMarkX, apologize for the delay, here are a few thoughts:
Give this a try... $filter = @('active', '-eq', 'true'),
'-and', @('u_resolved_date', '-eq', '')
'-and', @('assignment_group.name', '-eq', 'XGroup'),
'-and', @('short_description', '-like', 'Access Request')
$tasks = gsnr -table 'catalog task' -Property number, short_description, sys_created_on, sys_updated_on, request_item.number -IncludeTotalCount
$ritms = gsnr -table sc_req_item -filter @('number', '-in', ($tasks.'request_item.number' -join ',')) -IncludeCustomVariable -Property number -IncludeTotalCount
$taskList = [System.Collections.Generic.List[object]]::new()
foreach ($task in $tasks) {
$ritm = $ritms.where{ $_.number -eq $task.'request_item.number' } | Select-Object -ExpandProperty CustomVariable
$requestFor = Get-ServiceNowRecord -Table 'sys_user' -ID $($ritm.Where({ $_.name -eq 'reqfor_id' })).value -Property user_name -AsValue
$modelAfter = Get-ServiceNowRecord -Table 'sys_user' -ID $($ritm.Where({ $_.name -eq 'basic_copy_id' })).value -Property user_name -AsValue
$taskList.Add(
[PSCustomObject]@{
Number = $task.number
Description = $task.short_description
Created = $task.sys_created_on
Updated = $task.sys_updated_on
StartDate = [DateTime]$($ritm.Where({ $_.name -eq 'basic_start_date' })).value
RequestFor = $requestFor
Model = $modelAfter
RITM = $ritm.number
}
)
} |
Beta Was this translation helpful? Give feedback.
@DrMarkX, apologize for the delay, here are a few thoughts:
-AsValue