---
sourceDocument: Referência da API de Yokohama
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/pt-BR/yokohama/api-reference

 Release :

    - yokohama

ft:locale :

    - pt-BR

ft:publication_title :

    - Referência da API de Yokohama

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# Interaja com dados da tabela em um ServiceNowinstância

# Interaja com dados da tabela em um ServiceNowinstância {#ariaid-title1}

* Versão de lançamento: Yokohama
* 
* Atualizado 30 de jan. de 2025
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 3 min. de leitura

. Mobile SDKpermite interagir com dados em tabelas que residem no ServiceNowinstância. Você pode interagir com esses dados por meio do ServiceNowDESCANSO Tabela API que usa o. NowTableService() API que chama diretamente a interface REST ou por meio de NowGraphQLService() API que executa uma consulta GraphQL especificada em relação ao REST GraphQL API.
Se você quiser retornar dados de várias tabelas em uma única chamada, precisará usar o. NowGraphQLService() API. Se você precisar interagir com ServiceNowREST APIs diferentes de Tabela API, consulte [Interaja com a REST API pública em um ServiceNowinstância](https://servicenow-prod.fluidtopics.net/F_F6VC3EA9wVAIVbd6VblQ ". Mobile SDKfornece funcionalidade que habilita AndroidAplicações para chamar a REST API pública em um ServiceNowinstância.").

## Usando o NowGraphQLService para interagir com ServiceNowtabelas {#mobsdk-and-interact_data_instance__section_kxm_wdf_hqb}

. [NowGraphQLService](https://servicenow-prod.fluidtopics.net/q8F_VwViGM~1IvMS854gPA#NowGQLServiceAndroidInterface ". NowGraphQLService A interface fornece funções que permitem fazer solicitações GraphQL para o. ServiceNowatravés do its GraphQL API.")A classe fornece métodos que permitem construir e executar consultas GraphQL em uma tabela especificada no ServiceNowse o usuário conectado tiver a autorização adequada. Você pode definir todas as operações de CRUD em sua consulta GraphQL.  
O exemplo a seguir mostra como importar a estrutura NowData e inicializar um objeto NowGraphQLService que você pode usar para interagir com tabelas no ServiceNowinstância.

    /**
     * Helper class used to handle different Now service instances.
     */
    @Singleton
    class SdkManager @Inject constructor() {

        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 }
        }
    }

Este exemplo mostra como obter artigos da base de conhecimento publicados usando uma consulta GraphQL.

    suspend fun loadList() = withContext(Dispatchers.IO) {
        val kbArticlesQuery = """
        { 
            GlideRecord_Query {
                kb_knowledge(queryConditions: "active=true^ORDERBYpublishedDESC"
                pagination:{ limit: 10, offset: 0 }) {
                    _results {
                        sys_id { value },
                        number { displayValue },
                        short_description { displayValue },
                        author { displayValue }
                        published { displayValue }
                    }
                }
            }
         }
     """
        val graphQLService = sdkManager.getNowGraphQLService()

        //graphQLService?.graphQLRequest(kbArticlesQuery)?.execute() can also be used
        graphQLService?.graphQLRequest(kbArticlesQuery)?.enqueue(
            { response ->
                response.body?.let {
                    val resultString = String(it)
                }

            }, { nowDataError ->
                //handle error
            })
    }

## Usando o NowTableService para interagir com ServiceNowtabelas {#mobsdk-and-interact_data_instance__section_fgn_gy2_hqb}

. [NowTableService](https://servicenow-prod.fluidtopics.net/NMbDXGuK7MoZGqmhpCZfJw#NowTableServiceAndroidInterface ". NowTableService a interface fornece funções que permitem criar, ler, excluir e atualizar registros em uma tabela em um ServiceNowinstância.")A classe fornece métodos para executar operações de CRUD nos registros em tabelas que residem no ServiceNowinstância. Através desta interface, você pode acessar diretamente qualquer um dos registros em qualquer ServiceNowtabela para a qual o usuário conectado está autorizado. NowTableService compatível com referência com pontos para campos de referência. Por exemplo, se uma tabela contiver uma referência à tabela Usuário, o valor com referência a pontos `user.name `retorna o nome do usuário.

Ao retornar os dados solicitados, todas as listas de controle de acesso (ACLs) aplicáveis são aplicadas aos dados, o que pode resultar em menos resultados do que o esperado ou erros de autorização se o usuário autenticado não tiver direitos de acesso à tabela especificada.  
O exemplo a seguir mostra como importar o. NowData E, em seguida, inicialize um objeto NowTableServce que você pode usar para interagir com ServiceNowtabelas de instância.

    /**
     * Helper class used to handle different Now service instances. It has an application scope or is Singleton
     */
    @Singleton
    class SdkManager @Inject constructor() {

        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 }
        }
     }    


    suspend fun loadCases() = withContext(Dispatchers.IO) {
        val tableService = sdkManager.getNowTableService()

        //configure what data to pass back
        val fetchConfiguration =  FetchConfiguration(Filter("active=true"), 10)

        val response = runCatching {
            tableService?.records(
                "sn_customerservice_case",
                fetchConfiguration
            )?.execute()
        }

        if (response.isSuccess) {
            val resultString = response.getOrNull()?.body?.let { String(it) }
        } else {
            //handle unsuccessful result
        }
    }

Para obter exemplos de código adicionais usando o disponível NowTableService métodos, consulte [NowTableService](https://servicenow-prod.fluidtopics.net/NMbDXGuK7MoZGqmhpCZfJw#NowTableServiceAndroidInterface ". NowTableService a interface fornece funções que permitem criar, ler, excluir e atualizar registros em uma tabela em um ServiceNowinstância.")Documentação da API.

