ScopedSessionDomain : client

  • Rversion finale: Yokohama
  • Mis à jour 30 janv. 2025
  • 2 minutes de lecture
  • L’include de script ScopedSessionDomain qui contient des méthodes côté client qui fournissent des fonctionnalités liées au domaine de session en cours.

    Cette API n’est disponible que si le module d’extension Prise en charge de domaine - Programme d’installation d’extensions de domaine (com.glide.domain.msp_extensions) a été activé dans l’instance. En outre, l’appelant doit avoir le rôle d’administrateur pour accéder à cette API.

    ScopedSessionDomain : getCurrentDomainID()

    Renvoie l’sys_id du domaine actuel pour la session d’utilisateur connectée.

    L’identificateur renvoyé dépend du type de domaine et de l’instanciation de ce domaine.
    • Si l’utilisateur est configuré dans le domaine global et n’utilise pas le sélecteur de domaine pour changer de domaine, la méthode renvoie null.
    • Si l’utilisateur utilise le sélecteur de domaine pour passer au domaine global, la méthode renvoie la chaîne « global ».
    • Pour tous les autres domaines, la méthode renvoie le sys_id de ce domaine.
    Pour accéder à cette méthode à partir d’un script côté client, vous devez utiliser GlideAjax() pour l’invoquer. Pour appeler cette méthode à partir d’un script côté serveur, utilisez quelque chose de similaire à ce qui suit pour instancier l’objet et accéder à la méthode.
    var ssg = new global.ScopedSessionDomain(); 
    domainID = ssg.getCurrentDomainID();
    Tableau 1. Paramètres
    Nom Type Description
    Aucun
    Tableau 2. Renvoie
    Type Description
    Chaîne Sys_id du domaine de session de l’utilisateur actuellement connecté. Il s’agit des mêmes informations qui apparaissent dans le sélecteur de domaine.

    Cet exemple montre comment appeler la méthode getCurrentDomainID() à partir d’un script côté client.

    // This example is calling the script include in a client script. 
    // This particular record is within the "Service Portal - Standard Ticket" scope. 
    // To reproduce this example: 
    //  1. Change application scope to "Service Portal - Standard Ticket" 
    //  2. Navigate to Client Script table and open a new form and name it anything 
    //  3. Set table=ticket_configuration (this table is within the same scope) 
    //  4. Set UI type=Desktop and Type=onLoad 
    //  5. Populate the script field with the script above 
    //  6. Navigate to the ticket_configuration table and open any form. 
    //
    // This will trigger the client script, invoke the API, and pop up a browser alert containing the sys_id of the user's current domain
    
    function onLoad() {	
      var ga = new GlideAjax("global.ScopedSessionDomain"); // Set the script include
      ga.addParam("sysparm_name", "getCurrentDomainID"); // Set the getCurrentDomainID method
      ga.getXML(getResponse);
    	
      function getResponse(response) {
         var answer = response.responseXML.documentElement.getAttribute('answer');
         alert(answer); // Pops up the sys_id of the domain record
      }
    }