인스턴스에서 테이블 데이터와 ServiceNow 상호 작용
이를 Mobile SDK 사용하면 인스턴스에 있는 테이블의 데이터와 상호작용할 수 있습니다 ServiceNow . REST 인터페이스를 직접 호출하는 NowTableService() API를 사용하는 REST 테이블 API 또는 REST GraphQL API에 대해 지정된 GraphQL 쿼리를 실행하는 NowGraphQLService() API를 통해 이 데이터와 ServiceNow 상호작용할 수 있습니다.
단일 호출 내에서 여러 테이블의 데이터를 반환하려면 NowGraphQLService() API를 사용해야 합니다. 테이블 API 이외의 REST API와 ServiceNow 상호 작용해야 하는 경우 문서를 인스턴스에서 공용 REST API와 ServiceNow 상호 작용참조하십시오.
NowGraphQLService를 사용하여 테이블과 ServiceNow 상호작용
NowGraphQLService 클래스는 로그인한 사용자에게 적절한 권한이 있는 경우 인스턴스 내의 ServiceNow 지정된 테이블에서 GraphQL 쿼리를 구성하고 실행할 수 있는 메서드를 제공합니다. GraphQL 쿼리 내에서 모든 CRUD 작업을 정의할 수 있습니다.
/**
* 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 }
}
}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
})
}NowTableService를 사용하여 테이블과 ServiceNow 상호 작용
NowTableService 클래스는 인스턴스에 있는 ServiceNow 테이블의 기록에 대해 CRUD 작업을 수행하는 메서드를 제공합니다. 이 인터페이스를 통해 로그인한 사용자에게 권한이 부여된 테이블 ServiceNow 내의 기록에 직접 액세스할 수 있습니다. NowTableService 는 참조 필드에 대한 닷워킹을 지원합니다. 예를 들어 테이블에 사용자 테이블에 대한 참조가 포함되어 있으면 닷워킹 값 user.name 사용자의 이름을 반환합니다.
요청된 데이터를 반환하면 적용 가능한 모든 ACL(접근 제어 목록)이 데이터에 적용되어 예상보다 적은 결과가 발생하거나 인증된 사용자에게 지정된 테이블에 대한 액세스 권한이 없는 경우 권한 부여 오류가 발생할 수 있습니다.
/**
* 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
}
}사용 가능한 NowTableService 메서드를 사용하는 추가 코드 예제는 NowTableService API 설명서를 참조하세요.