GlideSysAttachment - 전역
GlideSysAttachment API는 첨부 파일을 처리하기 위한 메서드를 제공합니다.
getContentStream()이 호출되면 컨텐츠가 GlideScriptableInputStream 객체로 반환됩니다. GlideScriptableInputStream에는 문자열로 변환되지 않은 실제 바이트가 포함됩니다.
GlideSysAttachment - GlideSysAttachment()
GlideSysAttachment 클래스의 인스턴스를 작성합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| idAttachmentAttributes | 문자열 | 속성이 있는 첨부 파일의 Sys_id입니다. 첨부 파일에 속성이 있는지 확인하려면 을 사용합니다 GlideSysAttachment - fetchAllAttributes(). 테이블: 첨부 파일 [sys_attachment] |
다음 스크립트는 두 개의 첨부 파일이 있는 기록의 첨부 파일 이름을 나열합니다.
var attachment = new GlideSysAttachment();
var agr = attachment.getAttachments('<table_name>', '<record_sys_id>');
while(agr.next())
gs.info(agr.getValue('file_name'));
출력:
*** Script: filename1.txt
*** Script: filename2.txt
다음 예제에서는 지정된 첨부 파일에 할당된 모든 속성을 가져오는 방법을 보여 줍니다.
var attach = new GlideSysAttachment("04f48541083e2e50f877df7a115e31f3");
var result = attach.fetchAllAttributes();
while(result.next()) {
gs.info("Key: " + result.getValue('key') + ", Value: " + result.getValue('value'));
}
출력:
Key: title, Value: Add multiple attributes to an attachment
Key: author, Value: Abel Tuter
Key: category, Value: KB
Key: length, Value: 5000
GlideSysAttachment - addAttribute(String attrKey, String attrValue)
기존 첨부 파일 기록에 단일 속성을 추가합니다.
- addMultipleAttributes()
- deleteAllAttributes()
- delete속성()
- fetchAllAttributes()
- fetchAttribute()
- updateAllAttributes()
- updateAttribute()
| 이름 | 유형 | 설명 |
|---|---|---|
| attrKey | 문자열 | 첨부 파일 속성에 대한 키-값 쌍의 키 부분입니다. |
| attrValue | 문자열 | 첨부 파일 속성에 대한 키-값 쌍의 값 부분입니다. |
| 유형 | 설명 |
|---|---|
| 없음 |
다음 예제에서는 author 키와 Fred Luddy 값을 사용하여 지정된 첨부 파일에 특성을 추가하는 방법을 보여 줍니다. 결과는 첨부 파일 속성 [sys_attachment_attribute] 테이블에서 볼 수 있습니다.
var attach = new GlideSysAttachment("04f48541083e2e50f877df7a115e31f3");
attach.addAttribute("author", "Fred Luddy");
var result = attach.fetchAttribute("author");
while(result.next()) {
gs.info("Key: " + result.getValue('key') + " \nValue: " + result.getValue('value'));
}
출력:
Key: author
Value: Fred Luddy
GlideSysAttachment - addMultipleAttributes(객체 attrsKeyValuePair)
첨부 파일 기록에 여러 속성을 추가합니다.
- addAttribute()
- deleteAllAttributes()
- delete속성()
- fetchAllAttributes()
- fetchAttribute()
- updateAllAttributes()
- updateAttribute()
| 이름 | 유형 | 설명 |
|---|---|---|
| attrs키값쌍 | 객체 | 키-값 쌍 집합의 첨부 파일 속성입니다. 각 속성 키와 해당 값은 문자열로 제공되어야 합니다. 예: |
| 유형 | 설명 |
|---|---|
| 없음 |
다음 예제에서는 지정된 첨부 파일에 특성을 추가하는 방법을 보여 줍니다. 첨부 파일 속성 [sys_attachment_attribute] 테이블에서도 결과를 확인할 수 있습니다.
var attach = new GlideSysAttachment("04f48541083e2e50f877df7a115e31f3");
var attrsKeyValuePair = { };
attrsKeyValuePair["title"] = "Add multiple attributes to an attachment";
attrsKeyValuePair["category"] = "KB";
attrsKeyValuePair["length"] = "5000";
attach.addMultipleAttributes(attrsKeyValuePair);
var result = attach.fetchAllAttributes();
while(result.next()) {
gs.info("Key: " + result.getValue('key') + ", Value: " + result.getValue('value'));
}
출력:
Key: title, Value: Add multiple attributes to an attachment
Key: author, Value: Abel Tuter
Key: category, Value: KB
Key: length, Value: 5000
GlideSysAttachment - copy(String sourceTable, String sourceID, String targetTable, String targetID)
첨부 파일을 소스 기록에서 대상 기록으로 복사합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| sourceTable | 문자열 | 복사할 첨부 파일이 있는 테이블의 이름입니다. |
| 소스 ID | 문자열 | 소스 테이블의 sys_id. |
| targetTable | 문자열 | 첨부 파일을 추가할 테이블의 이름입니다. |
| targetID | 문자열 | 대상 테이블의 sys_id. |
| 유형 | 설명 |
|---|---|
| 문자열 | 복사된 첨부 파일 sys_ids의 배열입니다. |
var attachment = new GlideSysAttachment();
var incidentSysID = 'ab1b30031b04ec101363ff37dc4bcbfc';
var incGR = new GlideRecord('incident');
incGR.get(incidentSysID);
var copiedAttachments = attachment.copy('incident', incidentSysID, 'problem', incGR.getValue('problem_id'));
gs.info('Copied attachments: ' + copiedAttachments);
출력:
Copied attachments: 6e4621df1bc420501363ff37dc4bcbb0,a87769531b0820501363ff37dc4bcba2
GlideSysAttachment - deleteAllAttributes()
기존 첨부 파일 기록에서 모든 속성을 삭제합니다.
- addAttribute()
- addMultipleAttributes()
- delete속성()
- fetchAllAttributes()
- fetchAttribute()
- updateAllAttributes()
- updateAttribute()
| 이름 | 유형 | 설명 |
|---|---|---|
| 없음 |
| 유형 | 설명 |
|---|---|
| 부울 | 속성이 성공적으로 삭제되었는지 여부를 나타내는 플래그입니다. 유효한 값은 다음과 같습니다.
|
다음 예제에서는 지정된 첨부 파일에 할당된 모든 속성을 삭제하는 방법을 보여 줍니다. 첨부 파일 속성 [sys_attachment_attribute] 테이블에서도 결과를 확인할 수 있습니다.
var attach = new GlideSysAttachment("04f48541083e2e50f877df7a115e31f3");
attach.deleteAllAttributes();
var result = attach.fetchAllAttributes();
while(result.next()) {
gs.info("Key: " + result.getValue('key') + ", Value: " + result.getValue('value'));
}
출력:
Attribute "null" not found for attachment "04f48541083e2e50f877df7a115e31f3"
GlideSysAttachment - deleteAttachment(문자열, attachmentID)
지정된 첨부 파일을 삭제합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| 첨부 파일 ID | 문자열 | 첨부 파일의 sys_id |
| 유형 | 설명 |
|---|---|
| void |
var attachment = new GlideSysAttachment();
var attachmentSysID = 'a87769531b0820501363ff37dc4bcba2';
attachment.deleteAttachment(attachmentSysID);
GlideSysAttachment - deleteAttribute(String attrKey)
첨부 파일 기록에서 지정된 속성을 삭제합니다.
- addAttribute()
- addMultipleAttributes()
- deleteAllAttributes()
- fetchAllAttributes()
- fetchAttribute()
- updateAllAttributes()
- updateAttribute()
| 이름 | 유형 | 설명 |
|---|---|---|
| attrKey | 문자열 | 첨부 파일 속성에 대한 키-값 쌍의 키 부분입니다. |
| 유형 | 설명 |
|---|---|
| 부울 | 첨부 파일 속성이 성공적으로 삭제되었는지 여부를 나타내는 플래그입니다. 유효한 값은 다음과 같습니다.
|
다음 예제에서는 author 키를 사용하여 지정된 첨부 파일에 할당된 속성을 삭제하는 방법을 보여 줍니다. 첨부 파일 속성 [sys_attachment_attribute] 테이블에서도 결과를 확인할 수 있습니다.
var attach = new GlideSysAttachment("04f48541083e2e50f877df7a115e31f3v");
attach.deleteAttribute("author");
var result = attach.fetchAttribute("author");
while(result.next()) {
gs.info("Key: " + result.getValue('key') + " \nValue: " + result.getValue('value'));
}
출력:
Attribute "author" not found for attachment "04f48541083e2e50f877df7a115e31f3"
GlideSysAttachment - fetchAllAttributes()
지정된 첨부 파일 기록에서 모든 속성을 가져옵니다.
- addAttribute()
- addMultipleAttributes()
- deleteAllAttributes()
- delete속성()
- fetchAttribute()
- updateAllAttributes()
- updateAttribute()
| 이름 | 유형 | 설명 |
|---|---|---|
| 없음 |
| 유형 | 설명 |
|---|---|
| GlideRecord | 첨부 파일 기록과 모든 속성입니다. |
다음 예제에서는 지정된 첨부 파일에 할당된 모든 속성을 가져오는 방법을 보여 줍니다.
var attach = new GlideSysAttachment("04f48541083e2e50f877df7a115e31f3");
var result = attach.fetchAllAttributes();
while(result.next()) {
gs.info("Key: " + result.getValue('key') + ", Value: " + result.getValue('value'));
}
출력:
Key: title, Value: Add multiple attributes to an attachment
Key: author, Value: Abel Tuter
Key: category, Value: KB
Key: length, Value: 5000
GlideSysAttachment - fetchAttribute(String attrKey)
첨부 파일 기록에서 지정된 속성을 가져옵니다.
- addAttribute()
- addMultipleAttributes()
- deleteAllAttributes()
- delete속성()
- fetchAllAttributes()
- updateAllAttributes()
- updateAttribute()
| 이름 | 유형 | 설명 |
|---|---|---|
| attrKey | 문자열 | 첨부 파일 속성에 대한 키-값 쌍의 키 부분입니다. |
| 유형 | 설명 |
|---|---|
| GlideRecord | 첨부 파일 및 지정된 속성의 GlideRecord |
다음 예제에서는 author 키를 사용하여 첨부 파일 속성을 가져오는 방법을 보여 줍니다.
var attach = new GlideSysAttachment("04f48541083e2e50f877df7a115e31f3");
var result = attach.fetchAttribute("author");
while(result.next()) {
gs.info("Key: " + result.getValue('key') + " \nValue: " + result.getValue('value'));
}
출력:
Key: author
Value: Abel Tuter
GlideSysAttachment - getAttachments(String tableName, String sys_id)
이름, 유형 또는 크기와 같은 일치하는 첨부 파일 메타데이터가 포함된 GlideRecord를 반환합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| tableName | 문자열 | 첨부 파일이 속한 테이블의 이름입니다. 인시던트를 예로 들 수 있습니다. |
| sys_id | 문자열 | 첨부 파일이 속한 기록의 Sys_id입니다. |
| 유형 | 설명 |
|---|---|
| GlideRecord | 이름, 유형 또는 크기 등 일치하는 첨부 파일 메타데이터를 포함하는 GlideRecord 객체입니다. |
다음 스크립트는 두 개의 첨부 파일이 있는 기록의 첨부 파일 이름을 나열합니다.
var attachment = new GlideSysAttachment();
var agr = attachment.getAttachments('<table_name>', '<record_sys_id>');
while(agr.next())
gs.info(agr.getValue('file_name'));
출력:
*** Script: filename1.txt
*** Script: filename2.txt
GlideSysAttachment - getContentStream(문자열 sysID)
첨부 파일 sys_id이 지정된 GlideScriptableInputStream 객체를 반환합니다.
GlideTextReader API를 사용하여 콘텐츠 스트림을 읽을 수 있습니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| sysID | 문자열 | 첨부 파일 sys_id. |
| 유형 | 설명 |
|---|---|
| GlideScriptableInputStream | 첨부 파일 콘텐츠를 포함하는 스트림입니다. |
var attachment = new GlideSysAttachment();
var attachmentSysID = '6e4621df1bc420501363ff37dc4bcbb0';
var attachmentContentStream = attachment.getContentStream(attachmentSysID);
gs.info('Attachment content stream: ' + attachmentContentStream);
출력:
Attachment content stream: com.glide.communications.GlideScriptableInputStream@14bd299
GlideSysAttachment - updateAllAttributes(객체 attrsKeyValuePair)
기존 첨부 파일 기록의 모든 속성을 업데이트합니다.
- addAttribute()
- addMultipleAttributes()
- deleteAllAttributes()
- delete속성()
- fetchAllAttributes()
- fetchAttribute()
- updateAttribute()
| 이름 | 유형 | 설명 |
|---|---|---|
| attrs키값쌍 | 객체 | 키-값 쌍 집합의 첨부 파일 속성입니다. 각 속성 키와 해당 값은 문자열로 제공되어야 합니다. 예: |
| 유형 | 설명 |
|---|---|
| 없음 |
다음 예제에서는 지정된 첨부 파일에 대해 각 속성을 업데이트하는 방법을 보여 줍니다. 첨부 파일 속성 [sys_attachment_attribute] 테이블에서도 결과를 확인할 수 있습니다.
var attach = new GlideSysAttachment("04f48541083e2e50f877df7a115e31f3");
var attachmentAttributes = {
"category" : "Training",
"title" : "Updating attachment attributes",
"author" : "Abraham Lincoln",
"length" : "6000"
}
attach.updateAllAttributes(attachmentAttributes);
var result = attach.fetchAllAttributes();
while(result.next()) {
gs.info("Key: " + result.getValue('key') + ", Value: " + result.getValue('value'));
}
출력:
Key: title, Value: Updating attachment attributes
Key: author, Value: Abraham Lincoln
Key: category, Value: Training
Key: length, Value: 6000
GlideSysAttachment - updateAttribute(String attrKey, String attrValue)
기존 첨부 파일 기록에 대한 단일 속성을 업데이트합니다.
- addAttribute()
- addMultipleAttributes()
- deleteAllAttributes()
- delete속성()
- fetchAllAttributes()
- fetchAttribute()
- updateAllAttributes()
| 이름 | 유형 | 설명 |
|---|---|---|
| attrKey | 문자열 | 첨부 파일 속성에 대한 키-값 쌍의 키 부분입니다. |
| attrValue | 문자열 | 첨부 파일 속성에 대한 키-값 쌍의 값 부분입니다. |
| 유형 | 설명 |
|---|---|
| 없음 |
다음 예제에서는 지정된 첨부 파일에 할당된 특성을 author 키를 사용하여 업데이트하고 값을 Abel Tuter로 변경하는 방법을 보여 줍니다. 첨부 파일 속성 [sys_attachment_attribute] 테이블에서도 결과를 확인할 수 있습니다.
var attach = new GlideSysAttachment("04f48541083e2e50f877df7a115e31f3");
var originalVal = attach.fetchAttribute("author");
while(originalVal.next()) {
gs.info("Original attribute value: " + originalVal.getValue('value') + "\n");
}
attach.updateAttribute("author", "Abel Tuter");
var updatedVal = attach.fetchAttribute("author");
while(updatedVal.next()) {
gs.info("Updated attribute value: " + updatedVal.getValue('value'));
}
출력:
Original attribute value: Fred Luddy
Updated attribute value: Abel Tuter
GlideSysAttachment - write(GlideRecord record, String fileName, String contentType, String content)
지정된 첨부 파일을 지정된 기록에 첨부합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| 기록 | GlideRecord | 첨부 파일을 첨부할 기록입니다. |
| fileName | 문자열 | 첨부 파일 이름입니다. |
| contentType | 문자열 | 첨부 파일의 MIME 유형입니다(예: image/png). 콘텐츠 유형 필드의 첨부 파일 [sys_attachment] 테이블에 있습니다. |
| 컨텐츠 | 문자열 | 첨부 파일 컨텐츠. |
| 유형 | 설명 |
|---|---|
| 문자열 | 첨부 파일 sys_id. 첨부 파일이 추가되지 않은 경우 null을 반환합니다. |
var attachment = new GlideSysAttachment();
//set up inputs
var rec = new GlideRecord('incident');
rec.get('78271e1347c12200e0ef563dbb9a7109');
var fileName = 'example.txt';
var contentType = 'text/csv';
var content = 'The text that is stored inside my file';
var agr = attachment.write(rec, fileName, contentType, content);
gs.info('The attachment sys_id is: ' + agr);
출력:
The attachment sys_id is: 01271e4317c13311e0ef563dbb9abe34
GlideSysAttachment - writeContentStream(GlideRecord now_GR, String fileName, String contentType, GlideScriptableInputStream inputStream)
입력 스트림을 사용하여 첨부 파일을 삽입합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| now_GR | GlideRecord | 첨부 파일을 첨부할 기록입니다. |
| fileName | 문자열 | 첨부 파일 이름입니다. |
| contentType | 문자열 | 첨부 파일의 MIME 유형입니다(예: image/png). 콘텐츠 유형 필드의 첨부 파일 [sys_attachment] 테이블에 있습니다. |
| 컨텐츠 | GlideScriptableInputStream | 첨부 파일 컨텐츠. |
| 유형 | 설명 |
|---|---|
| 문자열 | 작성된 첨부 파일의 Sys_id입니다. |
sys_attachment 테이블의 컨텐츠 스트림을 test_table 기록에 첨부합니다.
function copyAttachmentToGlideRecord(conceptSysId) {
// Get record from test_table using sys_id
var targetGlideRecord = new GlideRecord("test_table");
if (!targetGlideRecord.get(conceptSysId)) {
throw ("Cannot find record created by test with sys_id: " + conceptSysId);
}
// Get record from sys_attachment table
var sourceAttachmentGlideRecord = new GlideRecord('sys_attachment');
sourceAttachmentGlideRecord.query();
sourceAttachmentGlideRecord.next();
// Get field values from retrieved sys_attachment record
var fileName = sourceAttachmentGlideRecord.getValue('file_name');
var contentType = sourceAttachmentGlideRecord.getValue('content_type');
var sourceAttachmentSysId = sourceAttachmentGlideRecord.getValue('sys_id');
// Attach sys_attachment record content stream to test_table record
var gsa = new GlideSysAttachment();
gsa.writeContentStream(
targetGlideRecord,
fileName,
contentType,
gsa.getContentStream(sourceAttachmentSysId));
gs.info("Attachment created");
}