Classe NowDataSDK : Android

  • Rversion finale: Xanadu
  • Mis à jour 1 août 2024
  • 3 minutes de lecture
  • La classe NowDataSDK fournit des fonctions qui permettent la création et l’initialisation de divers services de fonctionnalités tels que NowGraphQLService, NowAttachmentService, NowTableService et NowAPIService.

    NowDataSDK : makeGraphQLService(instanceURL : URL)

    Crée et initialise une instance de la fonctionnalité NowGraphQLService. Ce service permet d’accéder à l’API GraphQL sur votre ServiceNow instance.

    Pour plus d’informations sur l’API ServiceNow GraphQL, consultez Interroger les données des enregistrements à l’aide du cadre de travail de l’API GraphQL.

    Tableau 1. Paramètres
    Nom Type Description
    instanceURL URL URL de l’instance ServiceNow à laquelle accéder. Par exemple, « https://instance.servicenow.com »
    Tableau 2. Renvoie
    Type Description
    Résultat<NowGraphQLService> NowGraphQLService enveloppé dans un objet de résultat Kotlin.

    L’exemple de code suivant montre comment appeler cette fonction.

    private var nowGraphQLService: NowGraphQLService? = null
    
    /**
      * Create the NowGraphQLService once in the lifetime of the application, inside the Application class
      * or another manager class that will be injected into other classes via dagger/hilt.
      * NowGraphQLService should be created after initializing the NowSDK.
      */
    suspend fun getNowGraphQLService(): NowGraphQLService? {
      if (nowGraphQLService != null) return nowGraphQLService
    
      return NowDataSDK.makeGraphQLService(URL("https://instance-name.service-now.com")).getOrThrow()
        .also { this.nowGraphQLService = it }
    }

    NowDataSDK : makeNowAPIService(instanceURL : URL)

    Crée et initialise une instance du service NowAPIService. Ce service vous permet d’accéder aux API REST publiques exposées par votre ServiceNow instance.

    En outre, vous pouvez développer des API REST scriptées personnalisées au sein de votre ServiceNow instance et y accéder au sein de votre Android application à l’aide de l’API NowAPIService . Pour en savoir plus sur les API REST, reportez-vous ServiceNow à la section API REST basées sur un script.

    Tableau 3. Paramètres
    Nom Type Description
    instanceURL URL URL de l’instance ServiceNow à laquelle accéder. Par exemple, « https://instance.servicenow.com »
    Tableau 4. Renvoie
    Type Description
    Résultat <NowAPIService> NowAPIService enveloppé dans un objet de résultat Kotlin.

    L’exemple de code suivant montre comment appeler cette fonction.

    private var nowApiService: NowAPIService? = null
    
    /**
      * Create the NowAPIService once in the lifetime of the application inside the Application class
      * or another manager class that will be injected into other classes via dagger/hilt.
      * NowAPIService should be created after initializing the NowSDK
      */
    suspend fun getNowApiService(): NowAPIService? {
      if (nowApiService != null) return nowApiService
    
      return NowDataSDK.makeAPIService(URL("https://instance-name.service-now.com")).getOrThrow()
        .also { this.nowApiService = it }
    }

    NowDataSDK : makeNowAttachmentService(instanceURL : URL)

    Crée et initialise une instance de la fonctionnalité NowAttachmentService.

    Ce service vous permet de charger, de télécharger et de supprimer des fichiers en pièce jointe de votre ServiceNow instance. Une fois que vous avez chargé une pièce jointe sur votre instance, elle génère des métadonnées pour la pièce jointe que vous pouvez ensuite télécharger dans votre Android application.

    Pour en savoir plus sur les pièces jointes, reportez-vous ServiceNow à la section API de pièce jointe.

    Tableau 5. Paramètres
    Nom Type Description
    instanceURL URL URL de l’instance ServiceNow à laquelle accéder. Par exemple, « https://instance.servicenow.com »
    Tableau 6. Renvoie
    Type Description
    Résultat <NowAttachmentService> NowAttachmentService enveloppé dans un objet de résultat Kotlin.

    L’exemple de code suivant montre comment appeler cette méthode.

    private var nowAttachmentService: NowAttachmentService? = null
    
    /**
      * Create the NowAttachmentService once in the lifetime of the application inside the Application
      * class or another manager class that will be injected into other classes via dagger/hilt.
      * NowAttachmentService should be created after initializing the NowSDK.
      */
    suspend fun getNowAttachmentService(): NowAttachmentService? {
      if (nowAttachmentService != null) return nowAttachmentService
    
      return NowDataSDK.makeAttachmentService(URL("https://instance-name.service-now.com"))
        .getOrThrow()
        .also { this.nowAttachmentService = it }
    }

    NowDataSDK : makeTableService(instanceURL : URL)

    Crée et initialise une instance de la fonctionnalité NowTableService.

    Ce service vous permet d’accéder à l’API de table REST sur une ServiceNow instance. Pour plus d’informations sur l’API de table REST , consultez API de table.

    Tableau 7. Paramètres
    Nom Type Description
    instanceURL URL URL de l’instance ServiceNow à laquelle accéder. Par exemple, « https://instance.servicenow.com »
    Tableau 8. Renvoie
    Type Description
    Résultat <NowTableService> Objet NowTableService enveloppé dans un objet de résultat Kotlin.

    L’exemple de code suivant montre comment appeler cette fonction.

    private var nowTableService: NowTableService? = null
    
    /**
      * Create the NowTableService once in the lifetime of the application inside the Application
      * class or another manager class that will be injected into other classes via dagger/hilt.
      * NowTableService should be created after initializing the NowSDK.
      */
    suspend fun getNowTableService(): NowTableService? {
      if (nowTableService != null) return nowTableService
    
      return NowDataSDK.makeTableService(URL("https://instance-name.service-now.com")).getOrThrow()
        .also { this.nowTableService = it }
    }