WorkSharing API
Las integraciones nativas a nivel de incidencia proporcionan una API para interactuar con la API HTTP de la herramienta, obtener acciones de entidades, compartir entidades, eliminar acciones de entidades (desvincular), etc.
Utilice getService la función para obtener el WorkSharingAPI:
context.getService('workSharing/v2')
Esta función devuelve un objeto con WorkSharingV2Api interfaz. Tiene la siguiente definición:
export interface WorkSharingV2Api {
/**
Returns an HTTP proxy object for a specified tool
@param tool Tool descriptor.
@return Http client for provided tool descriptor
*/
getProxy(tool: { id: string; type: 'Targetprocess' | 'Jira' | 'Azure' | string }): HttpApi
/**
Returns an array of entities given entity is syncing with
@param entity.
@return Shares for the provided entity.
*/
getEntityShares(entity: EntityRef): Promise<{
sourceId: string
sourceType: string
tool: ToolRef
}[]>
/**
Shares entity to a specified tool with specified mappings and overrides
@param entity.
@return EntityRef of a synced entity in another tool.
*/
shareEntity(shareCommand: {
sourceEntity: {
sourceId: string,
sourceType: string,
tool: ToolRef
},
targetId?: string | undefined
/// Using profile's target tool if not specified
targetTool?: ToolRef
mappingId: string
targetOverrides?: any | undefined
stateTransfer?: StateTransferPayload | undefined
}): Promise<EntityRef[]>
/**
Shares entity to a specified tool with specified mappings and overrides
@param entity.
@return EntityRef of a synced entity in another tool.
*/
shareEntities(shareCommands: {
sourceEntity: {
sourceId: string,
sourceType: string,
tool: ToolRef
},
targetId?: string | undefined
/// Using profile's target tool if not specified
targetTool?: ToolRef
mappingId: string
targetOverrides?: any | undefined
stateTransfer?: StateTransferPayload | undefined
}[]): Promise<ShareEntityResponse[]>
/**
Remove entity share (unlink)
@param entity.
*/
deleteEntitySharing(entity: {
sourceId: string,
sourceType: string,
tool: ToolRef
} | DeleteEntitySharePayload): Promise<void>
/**
Get work sharing integration profiles for this account
@return Successful response
*/
getProfiles(): Promise<Profile[]>
}
La definición completa de los tipos se puede encontrar en https\:// {{account_name}}. tpondemand.com/svc/js-executor/types
getProxy
La función recibeToolRef y devuelve HttpApi objeto. Puede utilizar este objeto para realizar solicitudes get/post/put/patch/delete a la API de HTTP herramientas del perfil. El siguiente ejemplo muestra cómo se puede utilizar esta función para interactuar con la API de Jira utilizando getProxy// create workSharing service
const workSharing = context.getService('workSharing/v2')
// fetch integration profiles for account. For example, the first profile has a Jira type.
const jiraProfile = (await workSharing.getProfiles())[0]
// create proxy to interact with Jira API
const jiraApi = workSharing.getProxy(jiraProfile.targetTool)
// fetch issue from Jira
const issue = await jiraApi.getAsync('/rest/api/2/issue/TEST-52')
getEntityShares
Devuelve una matriz con todas las entidades con las que se está sincronizando la entidad dada. El siguiente ejemplo muestra cómo se puede utilizar esta API en las reglas de automatización:const service = context.getService('workSharing/v2')
const shares = service.getEntityShares({
sourceType: args.ResourceType,
sourceId: args.ResourceId.toString(),
tool: {
id: args.Account,
type: 'Targetprocess'
}
})
shareEntity/shareEntities
Estas funciones se pueden utilizar para compartir una sola entidad o una matriz de entidades con la herramienta de destino/origen del perfil de integración o para vincularlas a un elemento existente.const sync = context.getService("workSharing/v2")
const entity = {
sourceType: args.Current.ResourceType,
sourceId: ___PROTECTED_5___,
tool: {
type: 'Targetprocess',
id: args.Account
}
}
const profiles = await sync.getProfiles()
const currentProfile = profiles[0]
const mappingId = currentProfile.mappings[0].id
await sync.shareEntity({
sourceEntity: entity,
mappingId,
stateTransfer: {
kind: "source"
},
targetTool: currentProfile.targetTool
})No se espera que esta función se utilice en JavaScript rutas y asignaciones de campos. Esto puede dar lugar a situaciones en las que una entidad se comparta con otra herramienta más de una vez o se produzcan bucles en los scripts.deleteEntitySharing
Desvincular: elimina la participación de la entidad dada. Ejemplo:const service = context.getService('workSharing/v2')
const shares = service.deleteEntitySharing({
sourceType: args.ResourceType,
sourceId: args.ResourceId.toString(),
tool: {
id: args.Account,
type: 'Targetprocess'
}
})
getProfiles
Devuelve una matriz de perfiles de integración a nivel de incidencia para la cuenta actualconst sync = context.getService("workSharing/v2")
const profiles = await sync.getProfiles()