GlideAgentWorkspace (g_aw) - 클라이언트
g_aw API는 UI 작업 또는 클라이언트 스크립트가 탭에서 지정된 기록을 에이전트 작업 공간 열 수 있게 해주는 메서드를 제공합니다.
이 클래스에 대한 생성자가 없습니다. g_aw 전역 객체를 사용하여 GlideAgentWorkspace 메서드에 액세스합니다.
GlideAgentWorkspace - closeRecord()
의 하위 탭에서 에이전트 작업 공간양식과 같이 현재 열려 있는 기록을 닫습니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| 없음 |
| 유형 | 설명 |
|---|---|
| 안 함 |
함수 onClick(g_form) {function onClick(g_form) {
g_form.save().then(function(){
g_aw.closeRecord();
});
}
g_aw.closeRecord() 메서드를 사용하여 에서 단추를 클릭할 에이전트 작업 공간때 기록을 닫습니다. 다음과 같이 이 스크립트를 사용할 수 있습니다.- 에 대해 에이전트 작업 공간구성된 UI 작업(버튼)에 이 스크립트를 추가합니다.
- 버튼을 클릭하면 현재 기록을 닫으려고 시도합니다.
- 기본 로깅은 성공 또는 실패를 나타냅니다.
functioncloseCurrentRecord() {
if (typeof g_aw !== 'undefined' && g_aw.closeRecord) {
g_aw.closeRecord().then(function(response) {
console.log(response.success ? 'Record closed successfully.' : 'Failed to close the record.');
}).catch(function(error) {
console.error('Error closing the record:', error);
});
}
}
- 트리거 조건: 스크립트는 인시던트의 상태가 "해결됨"(
상태 = 6)으로 설정되어 있는지 확인합니다. - 작업 공간 유효성 검사:
코드가 typeof g_aw !== 'undefined'내에서만 에이전트 작업 공간 실행되도록 합니다. - 약속 처리: closeRecord()의 비동기 특성을 처리하기 위해 .then() 및 .catch()를 사용합니다.
- 오류 처리: 성공한 시도와 실패한 시도 모두에 대한 자세한 로깅을 제공합니다.
(function executeRule(current, gForm, gUser, gSNC) {
// Check if the incident state is 'Resolved' (state = 6 in default ServiceNow setup)
if (current.state == 6) {
// Ensure we're in Agent Workspace
if (typeof g_aw !== 'undefined' && g_aw.closeRecord) {
g_aw.closeRecord().then(function(response) {
if (response.success) {
console.log('Incident record closed successfully in Agent Workspace.');
} else {
console.error('Failed to close the record:', response.errorMessage);
}
}).catch(function(error) {
console.error('An error occurred while closing the record:', error);
});
}
}
})(current, gForm, gUser, gSNC);
GlideAgentWorkspace - openRecord(문자열 테이블, 문자열 sysId, 객체 매개변수)
양식과 같은 지정된 기록을 의 에이전트 작업 공간하위 탭에서 엽니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| 테이블 | 문자열 | 열려는 기록이 들어 있는 테이블의 이름입니다. |
| sysID | 문자열 | 오픈할 기록의 시스템 ID입니다. |
| 매개변수 | 객체 | 옵션입니다. 기록에 전달할 매개변수의 이름/값 쌍입니다. |
| params.readOnlyForm | 부울 | 열린 기록의 모든 필드가 읽기 전용인지 여부를 나타내는 플래그입니다. UI 정책 및 ACL에 관계 없이
기본값: false |
| params.defaultTab | 문자열 | 작업 공간에 표시할 초기 탭의 이름입니다. 관련 항목 또는 관련 목록만 지정할 수 있습니다. 지정하지 않으면 true로 설정하지 않는 한 hideDetails 상세 정보 탭이 나타납니다. 관련 목록 이름을 가져오는 데 사용할 메서드에 대한 자세한 내용은 getRelatedListNames()를 참조하십시오. |
| params.hideDetails | 부울 | 상세 정보 탭과 UI 작업을 숨길지 여부를 나타내는 플래그입니다.
기본값: false |
| 유형 | 설명 |
|---|---|
| 안 함 |
하위 탭에서 sys_user 기록을 엽니다.
g_aw.openRecord('sys_user', '62826bf03710200044e0bfc8bcbe5df1');
모든 필드가 읽기 전용인 하위 탭에서 기록을 엽니다.
g_aw.openRecord('sys_user', '62826bf03710200044e0bfc8bcbe5df1', {readOnlyForm: true});
하위 탭에서 기록을 열고 "그룹" 관련 목록으로 직접 이동합니다.
g_aw.openRecord('sys_user', '62826bf03710200044e0bfc8bcbe5df1', {defaultTab: "sys_user_grmember.user"});
하위 탭에서 기록을 열지만 양식 헤더와 다른 탭만 표시합니다.
g_aw.openRecord('sys_user', '62826bf03710200044e0bfc8bcbe5df1', {hideDetails: true});
- 동적 기록 열기: 스크립트가 현재 인시던트에서 관련 변경 요청의 sys_id 검색합니다.
- Agent Workspace 컨텍스트: 스크립트가 에서 실행 에이전트 작업 공간중인지 확인하는
데 사용할 g_aw있는지 확인합니다. - 사용자 지정 매개변수:
보기: '에이전트'는 특정 보기에서 기록을 엽니다(선택 사항).readOnly: true는 레코드를 읽기 전용 모드로 엽니다(선택 사항).
- 오류 처리: 응답 및 오류 처리를 위해 .then() 및 .catch() 를 사용합니다.
function openRelatedChangeRequest() {
// Get the sys_id of the related Change Request from the current incident
var changeRequestSysId = g_form.getValue('change_request'); // Assuming 'change_request' is the field name
if (changeRequestSysId && typeof g_aw !== 'undefined' && g_aw.openRecord) {
g_aw.openRecord('change_request', changeRequestSysId, {
view: 'agent', // Optional: Specify a custom view
readOnly: true // Optional: Open the record in read-only mode
}).then(function(response) {
if (response.success) {
console.log('Change Request opened successfully.');
} else {
console.error('Failed to open Change Request:', response.errorMessage);
}
}).catch(function(error) {
console.error('Error opening Change Request:', error);
});
} else {
console.warn('No related Change Request found or Agent Workspace is not available.');
}
}
GlideAgentWorkspace - setSectionExpanded(문자열 section_name, 부울 확장)
양식 섹션을 확장 또는 축소됨 상태로 설정합니다.
사용 사례는 다음 문서를 참조하십시오.
| 이름 | 유형 | 설명 |
|---|---|---|
| section_name | 문자열 | 에 있는 에이전트 작업 공간양식 섹션의 이름입니다. |
| 확장됨 | 부울 | 기본적으로 섹션을 확장 또는 축소할지 여부를 나타내는 플래그입니다.
|
| 유형 | 설명 |
|---|---|
| 안 함 |
다음 예제에서는 related_records 라는 양식 섹션을 기본적으로 축소하도록 설정하는 방법을 보여 줍니다.
function onLoad() {
g_aw.setSectionExpanded('related_records', false);
}
- 우선순위 기반 논리: 스크립트는
g_form.getValue('priority')를 사용하여 인시던트의 우선순위를 확인합니다. - 동적 섹션 통제: 우선순위가 1(중요) 또는 2(높음)인 경우 "작업 메모" 섹션을 확장합니다. 더 깔끔한 UI를 유지하기 위해 낮은 우선순위로 축소합니다.
- 에이전트 작업 공간 검사: 스크립트가 다음에서만 에이전트 작업 공간실행되도록 합니다.
javascriptCopyEdit(functiontoggleWorkNotesSection() {
// Check if we're in Agent Workspace and the method is availableif (typeof g_aw !== 'undefined' && g_aw.setSectionExpanded) {
// Get the incident priority from the formvar priority = g_form.getValue('priority');
// Automatically expand the "Work Notes" section for high-priority incidents (1 or 2)var shouldExpand = (priority == '1' || priority == '2');
// Expand or collapse the section based on priority
g_aw.setSectionExpanded('Work Notes', shouldExpand);
}
})(); 의 에이전트 작업 공간인시던트에 대해 유형을 "onLoad"로 설정하여 이 예시를 클라이언트 스크립트로 추가할 수 있습니다. 섹션 이름이 양식 레이아웃에 표시된 것과 정확히 일치하는지 확인합니다(예: "작업 메모").GlideAgentWorkspace - domainScopeProvider()
도메인 범위 상세 정보를 가져옵니다.
domainScopeProvider() 메서드는 도메인 범위에 대한 정보를 반환하기 위해 네 가지 함수에 액세스합니다. 자세한 내용은 Domain scope 문서를 참조하십시오.
필요한 역할 – domain_expand_scope.
| 함수 이름 | 수익 유형 | 설명 |
|---|---|---|
| getDomainScope() | 문자열 | 도메인 범위를 가져옵니다. 가능한 값:
기본값: false |
| hasDomainChanged() | 부울 | 도메인이 원래 도메인과 비교하여 현재 기록에 대해 변경되었는지 여부를 나타내는 플래그입니다. 유효한 값은 다음과 같습니다.
기본값: false |
| isDomainEnabledRecord() | 부울 | 메서드가 현재 기록이 도메인으로 분리되어 있는지(도메인 사용) 확인해야 하는지 여부를 나타내는 플래그입니다. 유효한 값은 다음과 같습니다.
기본값: false |
| toggleDomainScope() | 부울 | 기록에 대한 도메인 범위 컨텍스트를 활성화할지 또는 비활성화할지 여부를 나타내는 플래그입니다. 유효한 값은 다음과 같습니다.
기본값: true |
| 유형 | 설명 |
|---|---|
| 안 함 |
예제
다음 예에서는 UI 작업 작업 공간 클라이언트 스크립트에서 사용자 세션과 기록 간에 도메인 범위를 확장(세션 범위) 또는 축소(기록 범위)로 전환하는 방법을 보여줍니다.
function onClick(g_form) {
var provider = g_aw.domainScopeProvider();
provider.toggleDomainScope();
var domainScopeNow = provider.getDomainScope();
if (domainScopeNow === 'SESSION')
g_form.addInfoMessage(getMessage("Domain Scope Expanded"));
else if (domainScopeNow === 'RECORD')
g_form.addInfoMessage(getMessage("Domain Scope Collapsed"));
}
function onSubmit() {
if (typeof g_aw === 'undefined' || !g_aw.domainScopeProvider || typeof g_scratchpad === 'undefined') return true;
if (g_scratchpad._domainConfirmationPassed ||
g_scratchpad._domainCheckErrorBypass || g_scratchpad._domainCheckPassed) return true;
var provider = g_aw.domainScopeProvider();
if (!provider || !provider.isDomainEnabledRecord || !provider.isDomainEnabledRecord()) return true;
// if you change these messages, please change them in the above messages field var title = getMessage("Change Domain"); var message = getMessage("You are about to change the domain of this record which may result in data
loss.We will copy the information we can but you may need to replace the lost data.Do you want to proceed ? ");
var gFormRef = g_form;
var popModalConfirm = function() { g_modal.confirm(title, message , function(response) {
if (response) {
g_scratchpad._domainConfirmationPassed = true;
gFormRef.submit(gFormRef.getActionName());
}
});
return false;
};
var proceedWithSubmit = function() {
gFormRef.submit(gFormRef.getActionName());
};
var hasDomainChanged = provider.hasDomainChanged();
if (hasDomainChanged === false) return true;
if (hasDomainChanged === true) return popModalConfirm();
else {
hasDomainChanged.then(function(isChanged) {
if (isChanged)
return popModalConfirm();
else {
g_scratchpad._domainCheckPassed = true;
proceedWithSubmit();
}
}, function(error) {
g_scratchpad._domainCheckErrorBypass = true;
proceedWithSubmit();
});
return false;
}
}- 기본 검사:
typeof g_aw !=='undefined'는 스크립트가 에이전트 작업 공간.g_aw.domainScopeProvider는 메서드가 있는지 확인합니다. - 간단한 비동기 처리: 도메인 정보를 사용할 수 있을 때
.then()을 사용하여 결과를 처리합니다..catch()를 사용하여 오류(예: 도메인을 가져올 때 문제가 발생한 경우)를 처리합니다. - 사용자 친화적 경보: 간단하고 이해하기 쉬운 도메인 이름(
경보('도메인에서 작업하고 있습니다: ...'))과 함께 경보를 표시합니다. 도메인 정보를 찾을 수 없는 경우 사용자에게 "도메인 정보를 사용할 수 없습니다." - 오류 처리: 오류는 기본적인 문제 해결을 위해
console.error()를 사용하여 콘솔에 기록됩니다.
(function showDomainAlert() {
// Check if we're in Agent Workspace and the domainScopeProvider is available
if (typeof g_aw !== 'undefined' && g_aw.domainScopeProvider) {
// Get the current domain information
g_aw.domainScopeProvider().then(function(domainInfo) {
if (domainInfo && domainInfo.name) {
// Show an alert with the current domain name
alert('You are working in the domain: ' + domainInfo.name);
} else {
alert('Domain information is not available.');
}
}).catch(function(error) {
console.error('Error getting domain scope:', error);
});
}
})();
에서 이 스크립트를 "onLoad" 클라이언트 스크립트로 추가할 수 있습니다 에이전트 작업 공간. 에이전트가 기록을 열면 현재 도메인 이름을 보여주는 경보가 팝업됩니다.