0

Get Import Set Result

by
Published 4 days ago

Fetch the outcome of a prior import row by the staging-row sys_id returned by Insert Into Import Set (result.sys_id).

Script servicenow Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 5 days ago
1
//native
2

3
function authHeader(auth: RT.Servicenow) {
4
  return auth.token
5
    ? `Bearer ${auth.token}`
6
    : `Basic ${btoa(`${auth.username}:${auth.password}`)}`
7
}
8

9
/**
10
 * Get Import Set Result
11
 * Fetch the outcome of a prior import row by the staging-row sys_id returned by Insert Into Import Set (result.sys_id), returning the transform result (target table, status, target record link).
12
 */
13
export async function main(
14
  auth: RT.Servicenow,
15
  staging_table: string,
16
  sys_id: string
17
) {
18
  const url = new URL(
19
    `${auth.instance_url}/api/now/import/${staging_table}/${sys_id}`
20
  )
21

22
  const response = await fetch(url, {
23
    method: "GET",
24
    headers: {
25
      Authorization: authHeader(auth),
26
      Accept: "application/json",
27
    },
28
  })
29

30
  if (!response.ok) {
31
    throw new Error(`${response.status} ${await response.text()}`)
32
  }
33

34
  return await response.json()
35
}
36