---
sourceDocument: Référence API Brésil
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/fr-FR/api-reference

 Release :

    - brazil

ft:locale :

    - fr-FR

ft:publication_title :

    - Référence API Brésil

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# GlideSysAttachment : global

# GlideSysAttachment : global {#ariaid-title1}

Rversion finale: Brazil  
Mis à jour 10 sept. 2026  
![](https://www.servicenow.com/docs/portal-asset/ico-clock) 11 minutes de lecture  
L'API GlideSysAttachment fournit des méthodes de gestion des pièces jointes.

Le contenu est renvoyé en tant qu'objet GlideScriptableInputStream lorsque getContentStream() est appelé. GlideScriptableInputStream contient les octets réels non convertis en chaîne.

## Restriction du périmètre de l'API de chiffrement {#GlideSysAttachmentGlobalAPI__encryption-restrictions}

Les méthodes qui gèrent les contextes de chiffrement, les modules de chiffrement ou l'état de chiffrement ne sont disponibles que dans l'application globale. Ces API sont intentionnellement restreintes, car elles modifient la configuration de sécurité au niveau de la plateforme.

## GlideSysAttachment : GlideSysAttachment() {#ariaid-title2}

Crée une instance de la classe GlideSysAttachment.
Remarque :  
Ce constructeur ne prend pas de paramètre sauf s'il gère les attributs de pièce jointe.  
Utilisez les méthodes suivantes pour gérer les attributs de pièce jointe :

* [addAttribute()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-addAttribute_S_S "Ajoute un attribut unique à un enregistrement de pièce jointe existant.")
* [addMultipleAttributes()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-addMultipleAttributes_O "Ajoute plusieurs attributs à un enregistrement de pièce jointe.")
* [deleteAllAttributes()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-deleteAllAttributes "Supprime tous les attributs d’un enregistrement de pièce jointe existant.")
* [deleteAttribute()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-deleteAttribute_S "Supprime un attribut spécifié de l’enregistrement de pièce jointe.")
* [fetchAllAttributes()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-fetchAllAttributes "Récupère tous les attributs à partir d’un enregistrement de pièce jointe spécifié.")
* [fetchAttribute()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-fetchAttribute "Récupère un attribut spécifié à partir d’un enregistrement de pièce jointe.")
* [updateAllAttributes()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-updateAllAttributes_O "Met à jour tous les attributs d’un enregistrement de pièce jointe existant.")
* [updateAttribute()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-updateAttribute_S_S "Met à jour un attribut unique pour un enregistrement de pièce jointe existant.")
{#GSA-GlideSysAttachment__ul_uwj_4yq_zfc}
{#GSA-GlideSysAttachment__table_iys_ctb_fv__entry__3}

| Nom | Type | Description |
|-|-|-|
| idAttachmentAttributes | Chaîne | Ce paramètre n'est utilisé que lors de la gestion des attributs de pièce jointe, sinon laissez vide. Sys_id d'une pièce jointe avec des attributs. Table : pièces jointes \[sys_attachment\] |
[Tableau 1. Paramètres]

{#GSA-GlideSysAttachment__table_iys_ctb_fv}  
Le script suivant répertorie les noms de fichier de pièce jointe pour un enregistrement avec deux pièces jointes.

    var attachment = new GlideSysAttachment();

    var agr = attachment.getAttachments('<table_name>', '<record_sys_id>');

    while(agr.next())
    gs.info(agr.getValue('file_name'));

Sortie :

    *** Script: filename1.txt
    *** Script: filename2.txt

L'exemple suivant montre comment obtenir tous les attributs affectés à une pièce jointe spécifiée.

    var attach = new GlideSysAttachment("04f48541083e2e50f877df7a115e31f3");

    var result = attach.fetchAllAttributes();

    while(result.next()) {
       gs.info("Key: " + result.getValue('key') + ", Value: " + result.getValue('value')); 
    }

Sortie :

    Key: title, Value: Add multiple attributes to an attachment
    Key: author, Value: Abel Tuter
    Key: category, Value: KB
    Key: length, Value: 5000

## GlideSysAttachment : addAttribute(String attrKey, String attrValue) {#ariaid-title3}

Ajoute un attribut unique à un enregistrement de pièce jointe existant.
Voir aussi :

* [addMultipleAttributes()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-addMultipleAttributes_O "Ajoute plusieurs attributs à un enregistrement de pièce jointe.")
* [deleteAllAttributes()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-deleteAllAttributes "Supprime tous les attributs d’un enregistrement de pièce jointe existant.")
* [deleteAttribute()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-deleteAttribute_S "Supprime un attribut spécifié de l’enregistrement de pièce jointe.")
* [fetchAllAttributes()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-fetchAllAttributes "Récupère tous les attributs à partir d’un enregistrement de pièce jointe spécifié.")
* [fetchAttribute()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-fetchAttribute "Récupère un attribut spécifié à partir d’un enregistrement de pièce jointe.")
* [updateAllAttributes()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-updateAllAttributes_O "Met à jour tous les attributs d’un enregistrement de pièce jointe existant.")
* [updateAttribute()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-updateAttribute_S_S "Met à jour un attribut unique pour un enregistrement de pièce jointe existant.")

{#GSA-addAttribute_S_S__ul_uwj_4yq_zfc}Fou l'équivalent inclus dans le champ d'application de cette méthode, utilisez [GlideSysAttachment inclus dans le champ d'application : addAttribute (chaîne sysAttachmentID, chaîne attrKey, chaîne attrValue)](https://servicenow-prod.fluidtopics.net/ZQqM7iRaz_Cuu6Y4oyjHDA#SGSA-addAttribute_S_S_S "Ajoute un attribut unique à un enregistrement de pièce jointe existant.").
{#GSA-addAttribute_S_S__table_rql_3mg_5fc__entry__3}

| Nom | Type | Description |
|-|-|-|
| attrKey | Chaîne | Portion clé d'une paire clé-valeur pour un attribut de pièce jointe. |
| attrValue | Chaîne | Portion de valeur d'une paire clé-valeur pour un attribut de pièce jointe. |
[Tableau 2. Paramètres]

{#GSA-addAttribute_S_S__table_rql_3mg_5fc} {#GSA-addAttribute_S_S__table_sql_3mg_5fc__entry__2}

| Type | Description |
|-|-|
| Aucune |   |
[Tableau 3. Renvoie]

{#GSA-addAttribute_S_S__table_sql_3mg_5fc}  
L'exemple suivant montre comment ajouter un attribut à une pièce jointe spécifiée avec <kbd class="ph userinput">l’auteur</kbd> et valeur de clé <kbd class="ph userinput">Fred Luddy</kbd>. Les résultats peuvent être visualisés dans le tableau Attributs de pièce jointe \[sys_attachment_attribute\].

    var attach = new GlideSysAttachment("04f48541083e2e50f877df7a115e31f3");
    attach.addAttribute("author", "Fred Luddy");

    var result = attach.fetchAttribute("author");

    while(result.next()) {
       gs.info("Key: " + result.getValue('key') + " \nValue: " + result.getValue('value')); 
    }

Sortie :

    Key: author 
    Value: Fred Luddy

## GlideSysAttachment : addMultipleAttributes(Object attrsKeyValuePair) {#ariaid-title4}

Ajoute plusieurs attributs à un enregistrement de pièce jointe.
Voir aussi :

* [addAttribute()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-addAttribute_S_S "Ajoute un attribut unique à un enregistrement de pièce jointe existant.")
* [deleteAllAttributes()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-deleteAllAttributes "Supprime tous les attributs d’un enregistrement de pièce jointe existant.")
* [deleteAttribute()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-deleteAttribute_S "Supprime un attribut spécifié de l’enregistrement de pièce jointe.")
* [fetchAllAttributes()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-fetchAllAttributes "Récupère tous les attributs à partir d’un enregistrement de pièce jointe spécifié.")
* [fetchAttribute()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-fetchAttribute "Récupère un attribut spécifié à partir d’un enregistrement de pièce jointe.")
* [updateAllAttributes()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-updateAllAttributes_O "Met à jour tous les attributs d’un enregistrement de pièce jointe existant.")
* [updateAttribute()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-updateAttribute_S_S "Met à jour un attribut unique pour un enregistrement de pièce jointe existant.")

{#GSA-addMultipleAttributes_O__ul_uwj_4yq_zfc}Pour l'équivalent dans le champ d'application de cette méthode, utilisez [GlideSysAttachment inclus dans le champ d'application : addMultipleAttributes(String, sysAttachmentID, objet attrsKeyValuePair)](https://servicenow-prod.fluidtopics.net/ZQqM7iRaz_Cuu6Y4oyjHDA#SGSA-addMultipleAttributes_S_O "Ajoute plusieurs attributs à un enregistrement de pièce jointe.").
{#GSA-addMultipleAttributes_O__table_rql_3mg_5fc__entry__3}

| Nom | Type | Description |
|-|-|-|
| attrsKeyValuePair | Objet | Attributs de pièce jointe dans un ensemble de paires clé-valeur. Chaque clé d'attribut et sa valeur doivent être fournies sous forme de chaîne. Par exemple : var attachmentAttributes = { "description" : "Photo of the solar system", "dimensions" : "1600 x 300" } |
[Tableau 4. Paramètres]

{#GSA-addMultipleAttributes_O__table_rql_3mg_5fc} {#GSA-addMultipleAttributes_O__table_sql_3mg_5fc__entry__2}

| Type | Description |
|-|-|
| Aucune |   |
[Tableau 5. Renvoie]

{#GSA-addMultipleAttributes_O__table_sql_3mg_5fc}  
L'exemple suivant montre comment ajouter des attributs à une pièce jointe spécifiée. Les résultats peuvent également être vérifiés dans le tableau Attributs de pièce jointe \[sys_attachment_attribute\].

    var attach = new GlideSysAttachment("04f48541083e2e50f877df7a115e31f3");

    var attrsKeyValuePair = { };
      attrsKeyValuePair["title"]  = "Add multiple attributes to an attachment";
      attrsKeyValuePair["category"] =  "KB";
      attrsKeyValuePair["length"] =  "5000";

    attach.addMultipleAttributes(attrsKeyValuePair);

    var result = attach.fetchAllAttributes();

    while(result.next()) {
       gs.info("Key: " + result.getValue('key') + ", Value: " + result.getValue('value'));
    }

Sortie :

    Key: title, Value: Add multiple attributes to an attachment
    Key: author, Value: Abel Tuter
    Key: category, Value: KB
    Key: length, Value: 5000

## GlideSysAttachment : copy(chaîne sourceTable, chaîne sourceID, chaîne targetTable, chaîne targetID) {#ariaid-title5}

Copie les pièces jointes de l'enregistrement source vers l'enregistrement cible.
Remarque :  
La copie d'une pièce jointe copie également tous les attributs qui lui sont affectés. Vous pouvez afficher la liste des attributs affectés dans la table Attributs de pièce jointe \[sys_attachment_list\] ou exécuter la méthode fetchAllAttributes( ).
{#GSA-copy_S_S_S_S__id_g4d_yjz_g5b__entry__3}

| Nom | Type | Description |
|-|-|-|
| sourceTable | Chaîne | Nom de la table avec les pièces jointes à copier. |
| ID source | Chaîne | sys_id de la table source. |
| targetTable | Chaîne | Nom de la table sur laquelle ajouter les pièces jointes. |
| targetID | Chaîne | sys_id de l'enregistrement dans la table cible sur laquelle copier la pièce jointe. |
[Tableau 6. Paramètres]

{#GSA-copy_S_S_S_S__id_g4d_yjz_g5b} {#GSA-copy_S_S_S_S__id_afm_yjz_g5b__entry__2}

| Type | Description |
|-|-|
| Chaîne | Tableau des sys_ids des pièces jointes copiées. Table : pièces jointes \[sys_attachment\] |
[Tableau 7. Renvoie]

{#GSA-copy_S_S_S_S__id_afm_yjz_g5b}  
Cet exemple montre comment copier des pièces jointes d'un enregistrement d'incident vers un enregistrement de problème.

    var attachment = new GlideSysAttachment();
    var incidentSysID = 'ab1b30031b04ec101363ff37dc4bcbfc';
    var incGR = new GlideRecord('incident');
    incGR.get(incidentSysID);

    var copiedAttachments = attachment.copy('incident', incidentSysID, 'problem', incGR.getValue('problem_id'));
    gs.info('Copied attachments: ' + copiedAttachments);

Sortie :

    Copied attachments: 6e4621df1bc420501363ff37dc4bcbb0,a87769531b0820501363ff37dc4bcba2

## GlideSysAttachment : deleteAllAttributes() {#ariaid-title6}

Supprime tous les attributs d'un enregistrement de pièce jointe existant.
Voir aussi :

* [addAttribute()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-addAttribute_S_S "Ajoute un attribut unique à un enregistrement de pièce jointe existant.")
* [addMultipleAttributes()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-addMultipleAttributes_O "Ajoute plusieurs attributs à un enregistrement de pièce jointe.")
* [deleteAttribute()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-deleteAttribute_S "Supprime un attribut spécifié de l’enregistrement de pièce jointe.")
* [fetchAllAttributes()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-fetchAllAttributes "Récupère tous les attributs à partir d’un enregistrement de pièce jointe spécifié.")
* [fetchAttribute()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-fetchAttribute "Récupère un attribut spécifié à partir d’un enregistrement de pièce jointe.")
* [updateAllAttributes()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-updateAllAttributes_O "Met à jour tous les attributs d’un enregistrement de pièce jointe existant.")
* [updateAttribute()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-updateAttribute_S_S "Met à jour un attribut unique pour un enregistrement de pièce jointe existant.")

{#GSA-deleteAllAttributes__ul_uwj_4yq_zfc}Pour l'équivalent dans le champ d'application de cette méthode, utilisez [GlideSysAttachment dans le champ d'application : deleteAllAttributes(String sysAttachmentID)](https://servicenow-prod.fluidtopics.net/ZQqM7iRaz_Cuu6Y4oyjHDA#SGSA-deleteAllAttributes_S "Supprime tous les attributs d’un enregistrement de pièce jointe existant.").
{#GSA-deleteAllAttributes__table_rql_3mg_5fc__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucune |   |   |
[Tableau 8. Paramètres]

{#GSA-deleteAllAttributes__table_rql_3mg_5fc} {#GSA-deleteAllAttributes__table_sql_3mg_5fc__entry__2}

| Type | Description |
|-|-|
| Booléen | Marqueur indiquant si les attributs ont été supprimés avec succès. Valeurs valides : * vrai : les attributs ont été supprimés avec succès. * false : les attributs n'ont pas été supprimés avec succès. {#GSA-deleteAllAttributes__ul_kwy_cth_5fc} |
[Tableau 9. Renvoie]

{#GSA-deleteAllAttributes__table_sql_3mg_5fc}  
L'exemple suivant montre comment supprimer tous les attributs affectés à une pièce jointe spécifiée. Les résultats peuvent également être vérifiés dans le tableau Attributs de pièce jointe \[sys_attachment_attribute\].

    var attach = new GlideSysAttachment("04f48541083e2e50f877df7a115e31f3");

    attach.deleteAllAttributes();

    var result = attach.fetchAllAttributes();

    while(result.next()) {
       gs.info("Key: " + result.getValue('key') + ", Value: " + result.getValue('value')); 
    }

Sortie :

    Attribute "null" not found for attachment "04f48541083e2e50f877df7a115e31f3"

## GlideSysAttachment : deleteAttachment(chaîne attachmentID) {#ariaid-title7}

Supprime la pièce jointe spécifiée.
Remarque :  
La suppression d'une pièce jointe supprime également tous les attributs qui lui sont affectés. Vous pouvez afficher une liste des attributs affectés dans la table Attributs de pièce jointe \[sys_attachment\] ou exécuter la méthode fetchAllAttributes( ).
{#GSA-deleteAttachment_S__id_ywb_ykz_g5b__entry__3}

| Nom | Type | Description |
|-|-|-|
| ID pièce jointe | Chaîne | La pièce jointe sys_id. Table : pièces jointes \[sys_attachment\] |
[Tableau 10. Paramètres]

{#GSA-deleteAttachment_S__id_ywb_ykz_g5b} {#GSA-deleteAttachment_S__table_gjy_lyb_fv__entry__2}

| Type | Description |
|-|-|
| Aucune |   |
[Tableau 11. Renvoie]

{#GSA-deleteAttachment_S__table_gjy_lyb_fv}  

    var attachment = new GlideSysAttachment();
    var attachmentSysID = 'a87769531b0820501363ff37dc4bcba2';
    attachment.deleteAttachment(attachmentSysID);

## GlideSysAttachment : deleteAttribute(String attrKey) {#ariaid-title8}

Supprime un attribut spécifié de l'enregistrement de pièce jointe.
Voir aussi :

* [addAttribute()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-addAttribute_S_S "Ajoute un attribut unique à un enregistrement de pièce jointe existant.")
* [addMultipleAttributes()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-addMultipleAttributes_O "Ajoute plusieurs attributs à un enregistrement de pièce jointe.")
* [deleteAllAttributes()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-deleteAllAttributes "Supprime tous les attributs d’un enregistrement de pièce jointe existant.")
* [fetchAllAttributes()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-fetchAllAttributes "Récupère tous les attributs à partir d’un enregistrement de pièce jointe spécifié.")
* [fetchAttribute()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-fetchAttribute "Récupère un attribut spécifié à partir d’un enregistrement de pièce jointe.")
* [updateAllAttributes()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-updateAllAttributes_O "Met à jour tous les attributs d’un enregistrement de pièce jointe existant.")
* [updateAttribute()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-updateAttribute_S_S "Met à jour un attribut unique pour un enregistrement de pièce jointe existant.")

{#GSA-deleteAttribute_S__ul_uwj_4yq_zfc}Pour l'équivalent dans le champ d'application de cette méthode, utilisez [GlideSysAttachment dans le champ d'application : deleteAllAttributes(String sysAttachmentID)](https://servicenow-prod.fluidtopics.net/ZQqM7iRaz_Cuu6Y4oyjHDA#SGSA-deleteAllAttributes_S "Supprime tous les attributs d’un enregistrement de pièce jointe existant.").
{#GSA-deleteAttribute_S__table_rql_3mg_5fc__entry__3}

| Nom | Type | Description |
|-|-|-|
| attrKey | Chaîne | Portion clé d'une paire clé-valeur pour un attribut de pièce jointe. |
[Tableau 12. Paramètres]

{#GSA-deleteAttribute_S__table_rql_3mg_5fc} {#GSA-deleteAttribute_S__table_sql_3mg_5fc__entry__2}

| Type | Description |
|-|-|
| Booléen | Marqueur indiquant si l'attribut de pièce jointe a été supprimé avec succès. Valeurs valides : * vrai : l'attribut de pièce jointe a été supprimé avec succès. * faux : l'attribut de pièce jointe n'a pas été supprimé avec succès. {#GSA-deleteAttribute_S__ul_val_cth_5fc} |
[Tableau 13. Renvoie]

{#GSA-deleteAttribute_S__table_sql_3mg_5fc}  
L'exemple suivant montre comment supprimer un attribut affecté à une pièce jointe spécifiée avec <kbd class="ph userinput">l’auteur</kbd> de clé. Les résultats peuvent également être vérifiés dans le tableau Attributs de pièce jointe \[sys_attachment_attribute\].

    var attach = new GlideSysAttachment("04f48541083e2e50f877df7a115e31f3v");

    attach.deleteAttribute("author");

    var result = attach.fetchAttribute("author");

    while(result.next()) {
       gs.info("Key: " + result.getValue('key') + " \nValue: " + result.getValue('value')); 
    }

Sortie :

    Attribute "author" not found for attachment "04f48541083e2e50f877df7a115e31f3"

## GlideSysAttachment : fetchAllAttributes() {#ariaid-title9}

Récupère tous les attributs à partir d'un enregistrement de pièce jointe spécifié.
Voir aussi :

* [addAttribute()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-addAttribute_S_S "Ajoute un attribut unique à un enregistrement de pièce jointe existant.")
* [addMultipleAttributes()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-addMultipleAttributes_O "Ajoute plusieurs attributs à un enregistrement de pièce jointe.")
* [deleteAllAttributes()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-deleteAllAttributes "Supprime tous les attributs d’un enregistrement de pièce jointe existant.")
* [deleteAttribute()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-deleteAttribute_S "Supprime un attribut spécifié de l’enregistrement de pièce jointe.")
* [fetchAttribute()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-fetchAttribute "Récupère un attribut spécifié à partir d’un enregistrement de pièce jointe.")
* [updateAllAttributes()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-updateAllAttributes_O "Met à jour tous les attributs d’un enregistrement de pièce jointe existant.")
* [updateAttribute()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-updateAttribute_S_S "Met à jour un attribut unique pour un enregistrement de pièce jointe existant.")

{#GSA-fetchAllAttributes__ul_uwj_4yq_zfc}Pour l'équivalent dans le champ d'application de cette méthode, utilisez [GlideSysAttachment dans le champ d'application : fetchAllAttributes(String sysAttachmentID)](https://servicenow-prod.fluidtopics.net/ZQqM7iRaz_Cuu6Y4oyjHDA#SGSA-fetchAllAttributes_S "Récupère tous les attributs à partir d’un enregistrement de pièce jointe spécifié.").
{#GSA-fetchAllAttributes__table_rql_3mg_5fc__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucune |   |   |
[Tableau 14. Paramètres]

{#GSA-fetchAllAttributes__table_rql_3mg_5fc} {#GSA-fetchAllAttributes__table_sql_3mg_5fc__entry__2}

| Type | Description |
|-|-|
| [GlideRecord](https://servicenow-prod.fluidtopics.net/S5zmm8bYM5xdD9WY9215zQ#c_GlideRecordScopedAPI "L’API GlideRecord incluse dans le périmètre est utilisée pour les opérations de base de données.") | L'enregistrement de pièce jointe et tous ses attributs. |
[Tableau 15. Renvoie]

{#GSA-fetchAllAttributes__table_sql_3mg_5fc}  
L'exemple suivant montre comment obtenir tous les attributs affectés à une pièce jointe spécifiée.

    var attach = new GlideSysAttachment("04f48541083e2e50f877df7a115e31f3");

    var result = attach.fetchAllAttributes();

    while(result.next()) {
       gs.info("Key: " + result.getValue('key') + ", Value: " + result.getValue('value')); 
    }

Sortie :

    Key: title, Value: Add multiple attributes to an attachment
    Key: author, Value: Abel Tuter
    Key: category, Value: KB
    Key: length, Value: 5000

## GlideSysAttachment : fetchAttribute(String attrKey) {#ariaid-title10}

Récupère un attribut spécifié à partir d'un enregistrement de pièce jointe.
Voir aussi :

* [addAttribute()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-addAttribute_S_S "Ajoute un attribut unique à un enregistrement de pièce jointe existant.")
* [addMultipleAttributes()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-addMultipleAttributes_O "Ajoute plusieurs attributs à un enregistrement de pièce jointe.")
* [deleteAllAttributes()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-deleteAllAttributes "Supprime tous les attributs d’un enregistrement de pièce jointe existant.")
* [deleteAttribute()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-deleteAttribute_S "Supprime un attribut spécifié de l’enregistrement de pièce jointe.")
* [fetchAllAttributes()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-fetchAllAttributes "Récupère tous les attributs à partir d’un enregistrement de pièce jointe spécifié.")
* [updateAllAttributes()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-updateAllAttributes_O "Met à jour tous les attributs d’un enregistrement de pièce jointe existant.")
* [updateAttribute()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-updateAttribute_S_S "Met à jour un attribut unique pour un enregistrement de pièce jointe existant.")

{#GSA-fetchAttribute__ul_uwj_4yq_zfc}Pour l'équivalent dans le champ d'application de cette méthode, utilisez [GlideSysAttachment dans le champ d'application : fetchAttribute(String sysAttachmentID, String attrKey)](https://servicenow-prod.fluidtopics.net/ZQqM7iRaz_Cuu6Y4oyjHDA#SGSA-fetchAttribute_S_S "Récupère un attribut spécifié à partir d’un enregistrement de pièce jointe.").
{#GSA-fetchAttribute__table_rql_3mg_5fc__entry__3}

| Nom | Type | Description |
|-|-|-|
| attrKey | Chaîne | Portion clé d'une paire clé-valeur pour un attribut de pièce jointe. |
[Tableau 16. Paramètres]

{#GSA-fetchAttribute__table_rql_3mg_5fc} {#GSA-fetchAttribute__table_sql_3mg_5fc__entry__2}

| Type | Description |
|-|-|
| [GlideRecord](https://servicenow-prod.fluidtopics.net/S5zmm8bYM5xdD9WY9215zQ#c_GlideRecordScopedAPI "L’API GlideRecord incluse dans le périmètre est utilisée pour les opérations de base de données.") | GlideRecord de la pièce jointe et de l'attribut spécifié. |
[Tableau 17. Renvoie]

{#GSA-fetchAttribute__table_sql_3mg_5fc}  
L'exemple suivant montre comment obtenir un attribut de pièce jointe avec <kbd class="ph userinput">l’auteur</kbd> de clé.

    var attach = new GlideSysAttachment("04f48541083e2e50f877df7a115e31f3");

    var result = attach.fetchAttribute("author");

    while(result.next()) {
       gs.info("Key: " + result.getValue('key') + " \nValue: " + result.getValue('value')); 
    }

Sortie :

    Key: author 
    Value: Abel Tuter

## GlideSysAttachment : getAttachments(String tableName, String sys_id) {#ariaid-title11}

Renvoie un GlideRecord contenant les métadonnées de pièce jointe correspondantes telles que le nom, le type ou la taille.
{#GSA-getAttachments_S_S__id_m5v_14z_g5b__entry__3}

| Nom | Type | Description |
|-|-|-|
| tableName | Chaîne | Nom de la table à laquelle appartient la pièce jointe ; Par exemple, incident. |
| sys_id | Chaîne | Sys_id d'enregistrement auquel la pièce jointe appartient. |
[Tableau 18. Paramètres]

{#GSA-getAttachments_S_S__id_m5v_14z_g5b} {#GSA-getAttachments_S_S__id_qr3_c4z_g5b__entry__2}

| Type | Description |
|-|-|
| GlideRecord | Objet GlideRecord contenant les métadonnées de pièce jointe correspondantes telles que le nom, le type ou la taille. |
[Tableau 19. Renvoie]

{#GSA-getAttachments_S_S__id_qr3_c4z_g5b}  
Le script suivant répertorie les noms de fichier de pièce jointe pour un enregistrement avec deux pièces jointes.

    var attachment = new GlideSysAttachment();

    var agr = attachment.getAttachments('<table_name>', '<record_sys_id>');

    while(agr.next())
    gs.info(agr.getValue('file_name'));

Sortie :

    *** Script: filename1.txt
    *** Script: filename2.txt

## GlideSysAttachment : getContentStream(sysID de la chaîne) {#ariaid-title12}

Renvoie un objet GlideScriptableInputStream compte tenu de l'sys_id d'une pièce jointe.
Vous pouvez utiliser l'API [GlideTextReader](https://servicenow-prod.fluidtopics.net/KBnMx5_0pd~Awd2xhF7K6Q#c_GlideTextReaderScopedAPI "L’API GlideTextReader permet de lire des lignes individuelles à partir d’un flux d’entrée. Étant donné qu’un flux d’entrée est utilisé, il n’est pas soumis à la limite de taille de pièce jointe de 5 Mo.") pour lire le flux de contenu.
{#GSA-getContentStream_S__id_sdc_44z_g5b__entry__3}

| Nom | Type | Description |
|-|-|-|
| sysID | Chaîne | Pièce jointe sys_id. |
[Tableau 20. Paramètres]

{#GSA-getContentStream_S__id_sdc_44z_g5b} {#GSA-getContentStream_S__id_nqx_44z_g5b__entry__2}

| Type | Description |
|-|-|
| GlideScriptableInputStream | Flux contenant le contenu de la pièce jointe. |
[Tableau 21. Renvoie]

{#GSA-getContentStream_S__id_nqx_44z_g5b}  

    var attachment = new GlideSysAttachment();
    var attachmentSysID = '6e4621df1bc420501363ff37dc4bcbb0';
    var attachmentContentStream = attachment.getContentStream(attachmentSysID);
    gs.info('Attachment content stream: ' + attachmentContentStream);

Sortie :

    Attachment content stream: com.glide.communications.GlideScriptableInputStream@14bd299

## GlideSysAttachment : updateAllAttributes(Object attrsKeyValuePair) {#ariaid-title13}

Met à jour tous les attributs d'un enregistrement de pièce jointe existant.
Voir aussi :

* [addAttribute()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-addAttribute_S_S "Ajoute un attribut unique à un enregistrement de pièce jointe existant.")
* [addMultipleAttributes()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-addMultipleAttributes_O "Ajoute plusieurs attributs à un enregistrement de pièce jointe.")
* [deleteAllAttributes()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-deleteAllAttributes "Supprime tous les attributs d’un enregistrement de pièce jointe existant.")
* [deleteAttribute()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-deleteAttribute_S "Supprime un attribut spécifié de l’enregistrement de pièce jointe.")
* [fetchAllAttributes()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-fetchAllAttributes "Récupère tous les attributs à partir d’un enregistrement de pièce jointe spécifié.")
* [fetchAttribute()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-fetchAttribute "Récupère un attribut spécifié à partir d’un enregistrement de pièce jointe.")
* [updateAttribute()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-updateAttribute_S_S "Met à jour un attribut unique pour un enregistrement de pièce jointe existant.")

{#GSA-updateAllAttributes_O__ul_uwj_4yq_zfc}Pour l'équivalent dans le champ d'application de cette méthode, utilisez [GlideSysAttachment inclus dans le champ d'application : updateAllAttributes(String, sysAttachmentID, objet attrsKeyValuePair)](https://servicenow-prod.fluidtopics.net/ZQqM7iRaz_Cuu6Y4oyjHDA#SGSA-updateAllAttributes_S_O "Met à jour tous les attributs d’un enregistrement de pièce jointe existant.").
{#GSA-updateAllAttributes_O__table_rql_3mg_5fc__entry__3}

| Nom | Type | Description |
|-|-|-|
| attrsKeyValuePair | Objet | Attributs de pièce jointe dans un ensemble de paires clé-valeur. Chaque clé d'attribut et sa valeur doivent être fournies sous forme de chaîne. Par exemple : var attachmentAttributes = { "description" : "Photo of the solar system", "dimensions" : "1600 x 300" } |
[Tableau 22. Paramètres]

{#GSA-updateAllAttributes_O__table_rql_3mg_5fc} {#GSA-updateAllAttributes_O__table_sql_3mg_5fc__entry__2}

| Type | Description |
|-|-|
| Aucune |   |
[Tableau 23. Renvoie]

{#GSA-updateAllAttributes_O__table_sql_3mg_5fc}  
L'exemple suivant montre comment mettre à jour chaque attribut pour une pièce jointe spécifiée. Les résultats peuvent également être vérifiés dans le tableau Attributs de pièce jointe \[sys_attachment_attribute\].

    var attach = new GlideSysAttachment("04f48541083e2e50f877df7a115e31f3");

    var attachmentAttributes = {
        "category" : "Training",
        "title" : "Updating attachment attributes", 
        "author" : "Abraham Lincoln",
        "length" : "6000"
    }

    attach.updateAllAttributes(attachmentAttributes);

    var result = attach.fetchAllAttributes();

    while(result.next()) {
       gs.info("Key: " + result.getValue('key') + ", Value: " + result.getValue('value'));
    }

Sortie :

    Key: title, Value: Updating attachment attributes
    Key: author, Value: Abraham Lincoln
    Key: category, Value: Training
    Key: length, Value: 6000

## GlideSysAttachment : updateAttribute(String attrKey, String attrValue) {#ariaid-title14}

Met à jour un attribut unique pour un enregistrement de pièce jointe existant.
Voir aussi :

* [addAttribute()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-addAttribute_S_S "Ajoute un attribut unique à un enregistrement de pièce jointe existant.")
* [addMultipleAttributes()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-addMultipleAttributes_O "Ajoute plusieurs attributs à un enregistrement de pièce jointe.")
* [deleteAllAttributes()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-deleteAllAttributes "Supprime tous les attributs d’un enregistrement de pièce jointe existant.")
* [deleteAttribute()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-deleteAttribute_S "Supprime un attribut spécifié de l’enregistrement de pièce jointe.")
* [fetchAllAttributes()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-fetchAllAttributes "Récupère tous les attributs à partir d’un enregistrement de pièce jointe spécifié.")
* [fetchAttribute()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-fetchAttribute "Récupère un attribut spécifié à partir d’un enregistrement de pièce jointe.")
* [updateAllAttributes()](https://servicenow-prod.fluidtopics.net/ezOaKCyOZzKvHVydfLOMMQ#GSA-updateAllAttributes_O "Met à jour tous les attributs d’un enregistrement de pièce jointe existant.")

{#GSA-updateAttribute_S_S__ul_uwj_4yq_zfc}Pour l'équivalent dans le champ d'application de cette méthode, utilisez [GlideSysAttachment inclus dans le champ d'application : updateAttribute (chaîne sysAttachmentID, chaîne attrKey, chaîne attrValue)](https://servicenow-prod.fluidtopics.net/ZQqM7iRaz_Cuu6Y4oyjHDA#SGSA-updateAttribute_S_S_S "Met à jour un attribut unique pour un enregistrement de pièce jointe existant.").
{#GSA-updateAttribute_S_S__table_rql_3mg_5fc__entry__3}

| Nom | Type | Description |
|-|-|-|
| attrKey | Chaîne | Portion clé d'une paire clé-valeur pour un attribut de pièce jointe. |
| attrValue | Chaîne | Portion de valeur d'une paire clé-valeur pour un attribut de pièce jointe. |
[Tableau 24. Paramètres]

{#GSA-updateAttribute_S_S__table_rql_3mg_5fc} {#GSA-updateAttribute_S_S__table_sql_3mg_5fc__entry__2}

| Type | Description |
|-|-|
| Aucune |   |
[Tableau 25. Renvoie]

{#GSA-updateAttribute_S_S__table_sql_3mg_5fc}  
L'exemple suivant montre comment mettre à jour un attribut affecté à une pièce jointe spécifiée avec <kbd class="ph userinput">l’auteur</kbd> de clé et change la valeur en Abel Tuter. Les résultats peuvent également être vérifiés dans le tableau Attributs de pièce jointe \[sys_attachment_attribute\].

    var attach = new GlideSysAttachment("04f48541083e2e50f877df7a115e31f3");

    var originalVal = attach.fetchAttribute("author");
    while(originalVal.next()) {
       gs.info("Original attribute value: " + originalVal.getValue('value') + "\n"); 
    }

    attach.updateAttribute("author", "Abel Tuter");

    var updatedVal = attach.fetchAttribute("author"); 
    while(updatedVal.next()) {
       gs.info("Updated attribute value: " + updatedVal.getValue('value')); 
    }

Sortie :

    Original attribute value: Fred Luddy

    Updated attribute value: Abel Tuter

## GlideSysAttachment : écriture (enregistrement GlideRecord, nom de fichier de chaîne, contentType de chaîne, contenu de chaîne) {#ariaid-title15}

Joint une pièce jointe spécifiée à l'enregistrement spécifié.
{#GSA-write_GR_S_S_S__id_odn_1pz_g5b__entry__3}

| Nom | Type | Description |
|-|-|-|
| enregistrement | GlideRecord | Enregistrement auquel joindre la pièce jointe. |
| fileName | Chaîne | Nom de fichier de la pièce jointe. |
| contentType | Chaîne | Type MIME de la pièce jointe, tel que `image/png`. Situé dans la table Pièce jointe \[sys_attachment\] dans le champ Type de contenu . |
| contenu | Chaîne | Contenu de la pièce jointe. |
[Tableau 26. Paramètres]

{#GSA-write_GR_S_S_S__id_odn_1pz_g5b} {#GSA-write_GR_S_S_S__id_kbx_1pz_g5b__entry__2}

| Type | Description |
|-|-|
| Chaîne | Pièce jointe sys_id. Renvoie null si la pièce jointe n'a pas été ajoutée. |
[Tableau 27. Renvoie]

{#GSA-write_GR_S_S_S__id_kbx_1pz_g5b}  

    var attachment = new GlideSysAttachment();

    //set up inputs
    var rec = new GlideRecord('incident');
    rec.get('78271e1347c12200e0ef563dbb9a7109');
    var fileName = 'example.txt';
    var contentType = 'text/csv';
    var content = 'The text that is stored inside my file';

    var agr = attachment.write(rec, fileName, contentType, content);

    gs.info('The attachment sys_id is: ' + agr);

Sortie :

    The attachment sys_id is: 01271e4317c13311e0ef563dbb9abe34

## GlideSysAttachment : writeContentStream(GlideRecord now_GR, chaîne fileName, chaîne contentType, GlideScriptableInputStream inputStream) {#ariaid-title16}

Insère une pièce jointe à l'aide du flux d'entrée.
{#GSA-writeContentStrm_GR_S_S_GSIS__id_trk_jpz_g5b__entry__3}

| Nom | Type | Description |
|-|-|-|
| now_GR | GlideRecord | Enregistrement auquel joindre la pièce jointe. |
| fileName | Chaîne | Nom de fichier de la pièce jointe. |
| contentType | Chaîne | Type MIME de la pièce jointe, tel que `image/png`. Situé dans la table Pièce jointe \[sys_attachment\] dans le champ Type de contenu . |
| contenu | GlideScriptableInputStream | Contenu de la pièce jointe. |
[Tableau 28. Paramètres]

{#GSA-writeContentStrm_GR_S_S_GSIS__id_trk_jpz_g5b} {#GSA-writeContentStrm_GR_S_S_GSIS__id_ncv_jpz_g5b__entry__2}

| Type | Description |
|-|-|
| Chaîne | Sys_id de la pièce jointe créée. |
[Tableau 29. Renvoie]

{#GSA-writeContentStrm_GR_S_S_GSIS__id_ncv_jpz_g5b}  
Joint un flux de contenu de la table sys_attachment à un enregistrement test_table.

    function copyAttachmentToGlideRecord(conceptSysId) {

      // Get record from test_table using sys_id
      var targetGlideRecord = new GlideRecord("test_table");
      if (!targetGlideRecord.get(conceptSysId)) {
         throw ("Cannot find record created by test with sys_id: " + conceptSysId);
      }

      // Get record from sys_attachment table
      var sourceAttachmentGlideRecord = new GlideRecord('sys_attachment');    
      sourceAttachmentGlideRecord.query();
      sourceAttachmentGlideRecord.next();

      // Get field values from retrieved sys_attachment record
      var fileName = sourceAttachmentGlideRecord.getValue('file_name');
      var contentType = sourceAttachmentGlideRecord.getValue('content_type');
      var sourceAttachmentSysId = sourceAttachmentGlideRecord.getValue('sys_id');

      // Attach sys_attachment record content stream to test_table record
      var gsa = new GlideSysAttachment();
      gsa.writeContentStream(
        targetGlideRecord,
        fileName,
        contentType,
        gsa.getContentStream(sourceAttachmentSysId));
      gs.info("Attachment created");
    }


