GlideElement - 범위 지정됨

범위가 지정된 GlideElement API는 필드와 해당 값을 처리하기 위한 여러 가지 편리한 스크립트 메서드를 제공합니다. 현재 Glide 기록의 필드에는 범위가 지정된 GlideElement 메서드를 사용할 수 있습니다.

범위가 지정된 GlideElement - canCreate()

사용자의 역할에서 연결된 필드에 새 항목을 만들 수 있는지 여부를 결정합니다.

표 1. 매개변수
이름 유형 설명
안 함
표 2. 반환
유형 설명
부울 현재 사용자에게 연결된 필드에 새 항목을 작성할 수 있는 권한이 있는지 여부를 나타내는 플래그입니다.
가능한 값:
  • true: 사용자가 새 항목을 생성할 수 있습니다.
  • 아니오: 사용자가 새 항목을 만들 수 없습니다.

다음 예는 사용자에게 문제 [problem] 테이블의 최근 기록 3개에 대한 항목을 생성할 수 있는 권한이 있는지 확인하는 방법을 보여줍니다.

var gr = new GlideRecord('problem');

// Get records in new state in Problem Table
gr.addQuery('state','101');

// Sort records in order of recent to earlier Created Date
gr.orderByDesc('sys_created_on');

// Limit the query to three records
gr.setLimit(3); 
gr.query();

while(gr.next()){
  if(gr.short_description.canCreate()){ ///check to see if the current user is allowed to create the record
  gs.info("I can create new records for the field Problem statement for - " + gr.number);
  }
}

출력:

I can create new records for the field Problem statement for - PRB0000004
I can create new records for the field Problem statement for - PRB0001000
I can create new records for the field Problem statement for - PRB0001001

범위가 지정된 해당 항목

범위가 지정된 애플리케이션에서 canCreate() 메서드를 사용하려면 해당하는 범위가 지정된 메서드인 canCreate()를 사용합니다.

범위가 지정된 GlideElement - canRead()

사용자의 역할에서 연결된 GlideRecord를 읽을 수 있는지 여부를 나타냅니다.

표 3. 매개변수
이름 유형 설명
안 함
표 4. 반환
유형 설명
부울 필드를 읽을 수 있으면 예이고 그렇지 않으면 아니오입니다.

다음 예는 읽을 수 있는 간단한 설명 필드가 있는 활성 인시던트 기록 목록을 가져오는 방법을 보여줍니다.

var grIncident = new GlideRecord('incident');
grIncident.addEncodedQuery("active=true"); //Query the Incident table for active incidents
grIncident.orderByDesc('number');
grIncident.setLimit(3); // limit to three results for example
grIncident.query();

while (grIncident.next()) {
    if (grIncident.short_description.canRead()) { //check to see if the current user is allowed to read the record
        gs.info('You have permission to read the short description of: ' + grIncident.number + ' ' + grIncident.short_description);
    }
}

출력:

*** Script: You have permission to read the short description of: INC0009009 Unable to access the shared folder.
*** Script: You have permission to read the short description of: INC0009005 Email server is down.
*** Script: You have permission to read the short description of: INC0009001 Unable to post content on a Wiki page

범위가 지정된 GlideElement - canWrite()

사용자의 역할에서 연결된 GlideRecord에 쓸 수 있는지 여부를 결정합니다.

표 5. 매개변수
이름 유형 설명
안 함
표 6. 반환
유형 설명
부울 사용자가 필드에 쓸 수 있으면 예, 그렇지 않으면 아니오입니다.

다음 예는 쓰기 가능한 간단한 설명 필드가 있는 활성 인시던트 기록 목록을 가져오는 방법을 보여줍니다.

var grIncident = new GlideRecord('incident');
grIncident.addEncodedQuery("active=true"); //Query the Incident table for active incidents
grIncident.orderByDesc('number');
grIncident.setLimit(3); // limit to three results for example
grIncident.query();

while (grIncident.next()) {
    if (grIncident.short_description.canWrite()) { //check to see if the current user is allowed to write to the record
        gs.info('You have permission to write to the short description of: ' + grIncident.number + ' ' + grIncident.short_description);
    }
}

출력:

*** Script: You have permission to write to the short description of: INC0009009 Unable to access the shared folder.
*** Script: You have permission to write to the short description of: INC0009005 Email server is down.
*** Script: You have permission to write to the short description of: INC0009001 Unable to post content on a Wiki page

범위가 지정된 GlideElement - changes()

현재 필드가 수정되었는지 여부를 결정합니다. 이 기능은 저널 필드를 제외하고 사용 가능한 모든 데이터 유형에 사용할 수 있습니다.

주:
changes() 메서드는 ACL 스크립트 내에서 지원되지 않습니다.
주:
이 메서드를 수행하는 GlideRecord가 초기화 및 읽기만 되고 쓰기되지 않은 경우 기본 전후 값은 동일합니다. 이 경우 데이터 저장소가 변경되지 않았으므로 메서드는 "false"를 반환합니다.
비즈니스 규칙 실행
ServiceNow AI Platform 열(GlideElement 객체)의 내부 이전 값을 현재 값으로 재설정하기 전에 비즈니스 규칙(BEFORE 또는 AFTER)을 호출합니다.
이 시퀀스를 사용하면 다음 작업을 수행할 수 있습니다.
  • <column>.changes 조건에서 비즈니스 규칙을 트리거합니다 AFTER .
  • 스크립트 섹션의 이전 GlideRecord 객체에 액세스
비즈니스 규칙에서도 AFTERcurrent.<field>.changes() 는 내부 이전 값이 아직 재설정되지 않았기 때문에 true 를 반환합니다. current.<field>.value != previous.<field>.value 조건도 true를 반환합니다.
이전 값은 다음 활동 후에만 재설정됩니다.
  • 데이터베이스 업데이트가 완료되었습니다.
  • 모든 AFTER 비즈니스 규칙이 처리되었습니다.

AFTER 비즈니스 규칙 내에서 필드 값이 수정되면 changes() 메서드는 업데이트 후 규칙이 실행되더라도 여전히 true 를 반환합니다.

표 7. 매개변수
이름 유형 설명
안 함
표 8. 반환
유형 설명
부울 필드가 변경되었다면 True이고 필드가 변경되지 않았다면 False입니다.

비즈니스 규칙의 다음 예는 assigned_to 필드의 값이 변경될 경우 EventQueue에서 이벤트를 만드는 방법을 보여줍니다. 포괄적인 예는 다음 문서를 참조하십시오 Sample scripts from the change events business rule.

if (!current.assigned_to.nil() && current.assigned_to.changes()) {
  gs.eventQueue('incident.assigned', current, current.assigned_to.getDisplayValue(), previous.assigned_to.getDisplayValue());
}

범위가 지정된 GlideElement - changesFrom(Object o)

현재 필드의 이전 값이 지정된 객체와 일치하는지 여부를 결정합니다.

주:
이 메서드를 수행하는 GlideRecord가 초기화 및 읽기만 되고 쓰기되지 않은 경우 기본 전후 값은 동일합니다. 이 경우 데이터 저장소가 변경되지 않았으므로 메서드는 "false"를 반환합니다.
표 9. 매개변수
이름 유형 설명
o 객체 현재 필드의 이전 값과 비교하여 확인할 객체 값입니다.
표 10. 반환
유형 설명
부울 이전 값이 일치하면 True이고 그렇지 않으면 False입니다.
// The following example shows that in a business rule, if "active" field is changed from true, 
// insert a event in the EventQueue.
if (current.active.changesFrom(true)) {
  gs.eventQueue("incident.inactive", current, current.incident_state, previous.incident_state);
}

범위가 지정된 GlideElement - changesTo(Object o)

변경 후 필드의 새 값이 지정된 객체와 일치하는지 여부를 결정합니다.

주:
changesTo() 메서드는 ACL 스크립트 내에서 지원되지 않습니다.
주:
이 메서드를 수행하는 GlideRecord가 초기화 및 읽기만 되고 쓰기되지 않은 경우 기본 전후 값은 동일합니다. 이 경우 데이터 저장소가 변경되지 않았으므로 메서드는 "false"를 반환합니다.
표 11. 매개변수
이름 유형 설명
o 객체 현재 필드의 새 값과 비교하여 확인할 객체 값입니다.
표 12. 반환
유형 설명
부울 이전 값이 일치하면 True이고 그렇지 않으면 False입니다.
// The following example shows that in a business rule, if "active" field is changed to false, 
// insert a event in the EventQueue.
if (current.active.changesTo(false)) {
  gs.eventQueue("incident.inactive", current, current.incident_state, previous.incident_state);
}

범위가 지정된 GlideElement - dateNumericValue()

기간 필드에 대해 1970년 1월 1일 00:00:00 GMT 이후의 밀리초 수를 반환합니다. 기간 필드가 이미 GlideDateTime 객체이므로 GlideDateTime 객체를 생성할 필요가 없습니다.

표 13. 매개변수
이름 유형 설명
안 함
표 14. 반환
유형 설명
번호 1970년 1월 1일 00:00:00 GMT 이후의 밀리초 수입니다.
var inc = new GlideRecord('incident');
inc.get('17c90efb13418700cc36b1422244b05d');
gs.info(inc.calendar_duration.dateNumericValue());

출력:

98000

범위가 지정된 GlideElement - getAttribute(String attributeName)

딕셔너리에서 지정된 속성의 값을 반환합니다.

부울 속성의 경우 getBooleanAttribute() 메서드를 사용하여 문자열 대신 부울로 값을 반환할 수 있습니다.

표 15. 매개변수
이름 유형 설명
attributeName 문자열 속성의 이름입니다. 속성 이름은 딕셔너리 항목 [sys_dictionary] 테이블에 나열됩니다.
표 16. 반환
유형 설명
문자열 지정된 속성의 값입니다.

다음 예제에서는 사용자 [sys_user] 테이블의 열에 있는 location 속성 값을 tree_picker 문자열로 가져오는 방법을 보여 줍니다.

var now_GR = new GlideRecord('sys_user');
now_GR.query("user_name","admin");

if (now_GR.next()) {
   gs.info("The value of the tree_picker attribute in the location column is " + now_GR.location.getAttribute("tree_picker"));
}

출력:

The value of the tree_picker attribute in the location column is true

범위가 지정된 GlideElement - getBooleanAttribute(String attributeName)

사전에서 지정된 부울 유형 속성을 부울 값으로 반환합니다.

속성 값을 문자열로 반환하려면 getAttribute() 메서드를 사용합니다.

표 17. 매개변수
이름 유형 설명
attributeName 문자열 속성의 이름입니다. 속성 이름은 딕셔너리 항목 [sys_dictionary] 테이블에 나열됩니다.
표 18. 반환
유형 설명
부울 속성 값을 부울 true 또는 false로 지정합니다.

다음 예제에서는 두 필드에 대한 속성의 ignore_filter_on_new 부울 값을 가져오는 방법을 보여줍니다.

var inc = new GlideRecord('incident');
inc.query();

if (inc.next())
 {
   // opened_by field has attribute "ignore_filter_on_new = true"
   gs.info(inc.opened_by.getBooleanAttribute("ignore_filter_on_new"));

  // short_description field does not have attribute ignore_filter_on_new
   gs.info(inc.short_description.getBooleanAttribute("ignore_filter_on_new"));
 }

출력:

true
false

범위가 지정된 GlideElement - getChoices(문자열에 따라 다름)

지정된 필드에 대한 선택 목록을 반환합니다.

선택 목록을 반환할 필드는 메서드 호출에 지정됩니다. 예: var choices = glideRecord.urgency.getChoices();. 선택 목록 필드 유형 및 관련 기능에 대한 자세한 내용은 선택 목록 필드 유형을 참조하십시오.

표 19. 매개변수
이름 유형 설명
종속 문자열 옵션입니다. 선택 목록 필드가 종속된 연결된 기록 내의 필드입니다.
표 20. 반환
유형 설명
배열 선택 목록에 사용할 수 있는 값의 목록으로, 선택 [sys_choice] 테이블의 값입니다. 매개변수가 dependent 전달되면 반환 결과에는 지정된 종속 필드에 사용할 수 있는 선택 항목만 반영됩니다.
var glideRecord = new GlideRecord('incident'); 
glideRecord.query('priority','1'); 
glideRecord.next(); 
 
// urgency has choice list: 1 - High, 2 - Medium, 3 - Low, with value: 1, 2, 3
var choices = glideRecord.urgency.getChoices();

범위가 지정된 GlideElement - getChoiceValue()

현재 선택에 대한 선택 레이블을 반환합니다.

선택에는 값(숫자)과 레이블(문자열)이 있습니다. 이 메서드는 레이블을 반환합니다.

표 21. 매개변수
이름 유형 설명
안 함
표 22. 반환
유형 설명
문자열 선택한 선택의 레이블입니다.
var glideRecord = new GlideRecord('incident'); 
glideRecord.query('priority','1'); 
glideRecord.next(); 
 
// urgency has choice list: 1 - High, 2 - Medium, 3 - Low, with value: 1, 2, 3
var choiceLabel = glideRecord.urgency.getChoiceValue(); 
gs.info(choiceLabel);

출력:

1 - High

범위가 지정된 GlideElement - getDecryptedValue()

범위가 지정된 애플리케이션의 암호(양방향 암호화) 필드에 대한 일반 텍스트 값을 반환합니다.

표 23. 매개변수
이름 유형 설명
안 함
표 24. 반환
유형 설명
문자열 일반 텍스트 암호입니다.
var tablename = 'x_scoped_app_table'
var CI = new GlideRecord(tablename);  
CI.addQuery('number', '0001002'); 
CI.query(); 
CI.next(); 

var password = CI.password_field
var decrypted = password.getDecryptedValue(); 
gs.info(decrypted);
출력:
x_scoped_app: cleartextpassword

범위가 지정된 GlideElement - getDisplayValue(Number maxCharacters)

연결된 GlideRecord 객체에서 지정된 필드의 형식화된 표시 값을 반환합니다.

표시 값은 데이터베이스, 사용자 또는 시스템 설정과 기본 설정의 실제 값을 기반으로 조작됩니다.

반환되는 표시 값은 필드 유형에 따라 다릅니다.
  • 선택 필드: 데이터베이스 값은 숫자일 수 있지만 표시 값은 더 자세히 설명할 수 있습니다.
  • 날짜 필드: 데이터베이스 값은 UTC 형식이고 표시 값은 사용자의 시간대를 기준으로 합니다.
  • 암호화된 텍스트: 데이터베이스 값은 암호화되고 표시된 값은 사용자의 암호화 컨텍스트에 따라 암호화되지 않습니다.
  • 참조 필드: 데이터베이스 값은 sys_id지만 표시 값은 참조된 기록의 표시 필드입니다.

표시 값에 대한 자세한 내용은 표시 값을 참조하십시오.

표 25. 매개변수
이름 유형 설명
최대 문자 번호 옵션입니다. 필요한 최대 문자 수입니다.

기본값: 모두

표 26. 반환
유형 설명
문자열 지정된 필드의 표시 값입니다.

다음 예는 인시던트 기록에서 우선순위 필드의 표시 값을 검색하는 방법을 보여줍니다.

var glideRecord = new GlideRecord('incident');
glideRecord.query('priority','1');
glideRecord.next();
gs.info(glideRecord.priority.getDisplayValue());

출력:

1 - Critical

다음 예는 인시던트 데이터베이스에서 지정된 필드의 표시 값과 내부 값을 모두 검색하는 방법을 보여줍니다.

var now_GR = new GlideRecord('incident');
now_GR.get('9c573169c611228700193229fff72400'); //INC0000001
gs.info('Display Values:');
gs.info('Opened at ' + now_GR.opened_at.getDisplayValue());
gs.info('Opened by ' + now_GR.opened_by.getDisplayValue());
gs.info('Priority ' + now_GR.priority.getDisplayValue());
gs.info('Values:');
gs.info('Opened at ' + now_GR.opened_at.getValue());
gs.info('Opened by ' + now_GR.opened_by.getValue());
gs.info('Priority ' + now_GR.priority.getValue());

출력:

Display Values:
Opened at 2022-02-01 15:09:51
Opened by Joe Employee
Priority 1 - Critical
Values:
Opened at 2022-02-01 23:09:51
Opened by 681ccaf9c0a8016400b98a06818d57c7
Priority 1

범위가 지정된 GlideElement - getDisplayValueLang(문자열 언어)

언어로 된 필드의 표시 값을 가져옵니다.

결과는 선택, 번역된 필드번역된 텍스트와 같은 번역 가능한 필드 유형에만 적용할 수 있습니다. 다른 필드 유형의 경우 결과는 기본적으로 getDisplayValue()로 설정됩니다.

번역된 값을 검색하려면 해당 언어 플러그인이 있어야 합니다. 자세한 내용은 Activate a language 문서를 참조하십시오.

범위가 지정된 GlideElement - getLabelLang(문자열 언어) 또한 참조하십시오.

표 27. 매개변수
이름 유형 설명
언어 문자열 IETF BCP-47을 준수하는 언어 태그입니다.
표 28. 반환
유형 설명
문자열 전달된 언어로 된 필드의 값을 표시합니다. 번역을 사용할 수 없는 경우 메서드는 현재 사용자의 언어로 번역된 값을 검색합니다. 번역을 사용할 수 없는 경우 결과는 기본적으로 영어로 설정됩니다.

다음 예는 수락 (UI 뷰) 제목 필드에서 원본 텍스트와 독일어 번역 텍스트를 가져오는 방법을 보여줍니다.

var uiView = new GlideRecord("sys_ui_view");
uiView.get("fa776f6d97700100f309124eda2975bc");

gs.info("getDisplayValue: " + uiView.getElement("title").getDisplayValue());
gs.info("getDisplayValueLang: " + uiView.getElement("title").getDisplayValueLang("de"));

출력:

getDisplayValue: Accept
getDisplayValueLang: Akzeptieren

범위가 지정된 GlideElement - getED()

필드의 요소 설명자를 반환합니다.

표 29. 매개변수
이름 유형 설명
안 함
표 30. 반환
유형 설명
GlideElementDescriptor 필드의 요소 설명자입니다.
var grInc = new GlideRecord('incident');
grInc.query('priority', '1');
 
var field = grInc.getElement('priority');
var ed = field.getED();

범위가 지정된 GlideElement - getGlideObject()

필드 값과 연결된 플랫폼 객체를 검색합니다.

표 31. 매개변수
이름 유형 설명
안 함
표 32. 반환
유형 설명
객체 필드의 데이터 유형에 해당하는 플랫폼 객체입니다( 예: GlideDateTime). 값에 대한 형식별 작업에 이 객체를 사용할 수 있습니다. 예를 들어 필드 값을 일반 문자열로 액세스할 때 사용할 수 없는 날짜 산술, 형식 지정 및 시간대 변환이 있습니다.

다음 예는 인시던트 기록의 개시 날짜와 서비스 수준 계약(SLA) 기한 사이의 기간을 계산하는 방법을 보여줍니다.

// Query an incident record with both opened_at and sla_due populated
var incGr = new GlideRecord('incident');
incGr.addQuery('opened_at', '!=', '');
incGr.addQuery('sla_due', '!=', '');
incGr.setLimit(1);
incGr.query();

if (incGr.next()) {
    gs.info("Incident: " + incGr.getValue('number'));
    gs.info("Opened at: " + incGr.getValue('opened_at'));
    gs.info("SLA due: " + incGr.getValue('sla_due'));

    var duration = calcDateDelta(incGr.opened_at, incGr.sla_due);
    if (duration) {
        gs.info("Duration in seconds: " + duration.getNumericValue() / 1000);
        gs.info("Duration display value: " + duration.getDisplayValue());
    }
}

function calcDateDelta(start, end) {
    var realStart = start.getGlideObject();
    var realEnd = end.getGlideObject();

    // Use GlideDuration to calculate the difference between two GlideDateTime objects
    var startMS = realStart.getNumericValue();
    var endMS = realEnd.getNumericValue();
    var deltaMS = endMS - startMS;

    // Create a GlideDuration from the millisecond difference
    var duration = new GlideDuration(deltaMS);
    return duration;
}

출력:

Incident: INC0000031
Opened at: 2025-03-06 00:18:03
SLA due: 2025-03-06 08:18:03
Duration in seconds: 28800
Duration display value: 8 Hours

범위가 지정된 GlideElement - getGlobalDisplayValue()

전화 번호를 국제 형식으로 반환합니다.

표 33. 매개변수
이름 유형 설명
안 함
표 34. 반환
유형 설명
문자열 국제 형식의 전화 번호입니다.

다음 예시는 워크업 위치의 전화 번호를 가져오는 방법을 보여줍니다. 이 예시에는 플러그인이 필요합니다.워크업 경험

// Passing walkup location name and closed phone number in parameters
setWalkupLocPhone('Santa Clara Tech Lounge','phone_number');

function setWalkupLocPhone(locName, field) {
  var walkupLoc = new GlideRecord('wu_location_queue');
  walkupLoc.addQuery('name',locName);
  walkupLoc.query();
  walkupLoc.next();

  // Returns the phone number of walk-up location queue in international format
  gs.info(walkupLoc[field].getGlobalDisplayValue());
}

출력:

+91 98124 56789

범위가 지정된 GlideElement - getHTMLValue(Number maxChars)

필드의 HTML 값을 반환합니다.

표 35. 매개변수
이름 유형 설명
maxChars 번호 옵션입니다. 반환할 최대 문자 수입니다.
표 36. 반환
유형 설명
문자열 필드의 HTML 값입니다.
var inccause = new GlideRecord("incident");
inccause.short_description = current.short_description;
inccause.comments = current.comments.getHTMLValue();
inccause.insert();

범위가 지정된 GlideElement - getJournalEntry(Number mostRecent)

가장 최근의 저널 항목 또는 모든 저널 항목을 반환합니다.

표 37. 매개변수
이름 유형 설명
가장 최근 번호 1이면 가장 최근 항목을 반환합니다. -1이면 모든 저널 항목을 반환합니다.
표 38. 반환
유형 설명
문자열

가장 최근 항목의 경우 저널 항목의 필드 레이블, 타임스탬프 및 사용자 표시 이름을 포함하는 문자열을 반환합니다.

모든 저널 항목에 대해 "\n\n"으로 구분된 단일 문자열로 입력된 모든 저널 항목에 대해 동일한 정보를 반환합니다.

//gets all journal entries as a string where each entry is delimited by '\n\n'
var notes = current.work_notes.getJournalEntry(-1); 
//stores each entry into an array of strings
var na = notes.split("\n\n");  
                      
for (var i = 0; i < na.length; i++)                 
  gs.info(na[i]);

범위가 지정된 GlideElement - getLabel()

객체 레이블을 반환합니다.

표 39. 매개변수
이름 유형 설명
안 함
표 40. 반환
유형 설명
문자열 객체 레이블
var now_GR = new GlideRecord("sc_req_item");
now_GR.addQuery("request", current.sysapproval);
now_GR.query();
while(now_GR.next()) {
var nicePrice = now_GR.price.toString();
    if (nicePrice != ) {
        nicePrice = parseFloat(nicePrice);
        nicePrice = nicePrice.toFixed(2);
    }
    template.print(now_GR.number + ":  " + now_GR.quantity + " X " + now_GR.cat_item.getDisplayValue() + " at $" + nicePrice + " each \n");
    template.print("    Options:\n");
    var variables = now_GR.variables.getElements();    
    for (var key in variables) {
      var now_V = variables[key];
      if(now_V.getQuestion().getLabel() != ) {
         template.space(4);
         template.print('     ' +  now_V.getQuestion().getLabel() + " = " + now_V.getDisplayValue() + "\n");  
      }
    }
}

범위가 지정된 GlideElement - getLabelLang(문자열 언어)

매개변수로 전달된 언어로 된 필드의 레이블 값을 가져옵니다.

번역된 값을 검색하려면 해당 언어 플러그인이 있어야 합니다. 자세한 내용은 Activate a language 문서를 참조하십시오.

표 41. 매개변수
이름 유형 설명
언어 문자열 IETF BCP-47을 준수하는 언어 태그입니다.
표 42. 반환
유형 설명
문자열 전달된 언어의 필드 레이블 값입니다. 번역을 사용할 수 없는 경우 메서드는 현재 사용자의 언어로 번역된 값을 검색합니다. 번역을 사용할 수 없는 경우 결과는 기본적으로 영어로 설정됩니다.

다음 예는 원본 레이블 텍스트와 수락 (UI 뷰) 제목의 독일어 번역본을 가져오는 방법을 보여줍니다.

var uiView = new GlideRecord("sys_ui_view");
uiView.get("fa776f6d97700100f309124eda2975bc");

gs.info("getLabel: " + uiView.getElement("title").getLabel());
gs.info("getLabelLang: " + uiView.getElement("title").getLabelLang("de"));

출력:

getLabel: Title
getLabelLang: Titel

범위가 지정된 GlideElement - getName()

필드의 이름을 반환합니다.

표 43. 매개변수
이름 유형 설명
안 함
표 44. 반환
유형 설명
문자열 필드 이름입니다.

다음 예는 sys_user 기록의 각 필드에 대한 이름과 기타 값을 가져오는 방법을 보여줍니다.

var userRec = new GlideRecord("sys_user"); // GlideRecord to sys_user table

userRec.get("5137153cc611227c000bbd1bd8cd2005"); // Sys Id of user: Fred Luddy

var fields = userRec.getFields();

for (var i = 0; i < fields.size(); i++) {

    var field = fields.get(i);
    var name = field.getName(); // Name of the field
    var label = field.getLabel(); // Label of the field
    var value = field.getDisplayValue(); // Value of the field

    gs.info((Number(i) + 1) + ".\n" + "Field Label: " + label + "\n" + "Field Name: " + name + "\n" + "Field Value: " + value);

};

출력. 결과에는 62개의 필드가 포함되며 공간을 절약하기 위해 줄임표(...)로 잘렸습니다.

*** Script: 1.
Field Label: Country code
Field Name: country
Field Value: 
*** Script: 2.
Field Label: Calendar integration
Field Name: calendar_integration
Field Value: Outlook
...
*** Script: 47.
Field Label: First name
Field Name: first_name
Field Value: Fred
...
*** Script: 54.
Field Label: Last name
Field Name: last_name
Field Value: Luddy
...

범위가 지정된 GlideElement - getReferenceTable()

참조 요소의 테이블 이름을 가져옵니다.

표 45. 매개변수
이름 유형 설명
안 함
표 46. 반환
유형 설명
문자열 참조의 테이블 이름입니다.
var grINC = new GlideRecord('incident');
grINC.query('number','INC0010041'); // record assignment group assigned to "CAB Approval"
if (grINC.next()) { 
  // Get the table name 
  var tableName = grINC.assignment_group.getReferenceTable();
  gs.info( tableName ); 
}

범위가 지정된 GlideElement - getRefRecord()

지정된 참조 요소에 대한 GlideRecord 객체를 반환합니다.

계산된 필드의 경우 이 메서드는 참조된 기록을 가져오고 스크립팅된 기본값에 대한 계산을 실행합니다.

경고:
참조 요소에 값이 포함되어 있지 않으면 NULL 객체가 아닌 빈 GlideRecord 객체를 반환합니다.
표 47. 매개변수
이름 유형 설명
안 함
표 48. 반환
유형 설명
GlideRecord GlideRecord 객체

var grINC = new GlideRecord('incident'); 
grINC.addNotNullQuery('caller_id'); 
grINC.query(); 
if (grINC.next()) { 

// Get a GlideRecord object for the referenced sys_user record 
var grUSER = grINC.caller_id.getRefRecord(); 
if (grUSER.isValidRecord()) 
  gs.info(grUSER.getValue('name')); 

} 

범위가 지정된 GlideElement - getTableName()

필드가 들어 있는 테이블의 이름을 반환합니다.

표 49. 매개변수
이름 유형 설명
안 함
표 50. 반환
유형 설명
문자열 호출되는 필드가 들어 있는 테이블의 이름입니다. 반환된 값은 기록이 있는 테이블 클래스와 다를 수 있습니다. 자세한 내용은 Table extension and classes 문서를 참조하십시오.
if (current.approver.getTableName() == "sysapproval_approver") {
    if (current.approver == email.from_sys_id) {
        current.comments = "reply from: " + email.from + "\n\n" + email.body_text;

        // if it's been cancelled, it's cancelled.
        var doit = true;
        if (current.state == 'cancelled')
            doit = false;

        if (email.body.state != undefined)
            current.state = email.body.state;

        if (doit)
            current.update();
    } else {
        gs.log("Approval for task " + current.sysapproval.getDisplayValue() +
            " rejected because user sending email " + email.from +
            " does not match the approver " + current.approver.getDisplayValue());
    }
}

범위가 지정된 GlideElement - nil()

필드가 null인지 여부를 결정합니다.

표 51. 매개변수
이름 유형 설명
안 함
표 52. 반환
유형 설명
부울 필드가 null인지 여부를 나타내는 플래그입니다.
가능한 값:
  • true: 필드가 null입니다.
  • false: 필드가 null이 아닙니다.
var glideRecord = new GlideRecord('incident'); 
glideRecord.query('priority','1'); 
glideRecord.next(); 
gs.info(glideRecord.state.nil());

출력:

false

범위가 지정된 GlideElement - setDateNumericValue(숫자, 밀리초)

날짜/시간 요소의 값을 1970년 1월 1일 00:00:00 GMT 이후 지정된 시간(밀리초)으로 설정합니다.

호출되면 setDateNumericValue()가 자동으로 필요한 GlideDateTime/GlideDate/GlideDuration 객체를 생성한 다음 요소를 지정된 값으로 설정합니다.

주:
이 메서드를 호출하기 전에 기존 레코드를 쿼리하거나 now_GR.initialize() 메서드를 사용하여 새 레코드를 초기화하여 요소가 이미 존재해야 합니다.
표 53. 매개변수
이름 유형 설명
밀리초 번호 1970년 1월 1일 이후의 밀리초 수
표 54. 반환
유형 설명
무효
var now_GR = new GlideRecord("incident");
now_GR.initialize();
now_GR.opened_at.setDateNumericValue(10000);

범위가 지정된 GlideElement - setDisplayValue(객체 값)

필드의 표시 값을 설정합니다.

표 55. 매개변수
이름 유형 설명
객체 필드에 대해 설정할 값입니다.
표 56. 반환
유형 설명
무효
var glideRecord = new GlideRecord('incident'); 
glideRecord.query('priority','1'); 
glideRecord.next();
 
//change the urgency to 3 
glideRecord.urgency.setDisplayValue('3 - Low');
gs.info(glideRecord.urgency);

범위가 지정된 GlideElement - setError(문자열 errorMessage)

연결된 필드에 오류 메시지를 추가합니다.

표 57. 매개변수
이름 유형 설명
errorMessage 문자열 오류 메시지입니다.
표 58. 반환
유형 설명
없음

다음 예시에서는 짧은 설명이 비어 있는 우선순위 1 인시던트에 오류 메시지를 설정하는 방법을 보여줍니다.

var now_GR = new GlideRecord('incident');
now_GR.addQuery('priority', '1');
now_GR.query();

if (now_GR.next()) {
    var shortDesc = now_GR.short_description.toString();

    if (!shortDesc || shortDesc.trim() === '') {
        now_GR.short_description.setError(
            'A short description is required for all Priority 1 incidents. Please provide a brief summary of the issue.'
        );
    }
}

범위가 지정된 GlideElement - setPhoneNumber(Object phoneNumber, 부울 엄격)

필드를 지정된 전화 번호로 설정합니다.

이 방법은 GlideElement 전화 번호에서만 사용할 수 있습니다.

표 59. 매개변수
이름 유형 설명
phoneNumber 객체 설정할 전화 번호입니다. 이는 국제 형식 또는 로컬 형식일 수 있습니다.
엄격 부울 예일 때는 지정된 숫자가 올바른 형식과 일치해야 함을 지정합니다. false인 경우 시스템은 부적절한 형식의 전화 번호를 수정하려고 시도합니다.
표 60. 반환
유형 설명
부울 전화 번호 값이 설정되었는지 여부를 나타내는 플래그입니다.

가능한 값:

  • true: 값이 설정되었습니다.
  • false: 값이 설정되지 않았습니다.

다음 예는 워크업 위치의 전화 번호를 설정하는 방법을 보여줍니다. 이 예시에는 플러그인이 필요합니다.워크업 경험

setWalkupLocPhone('Santa Clara Tech Lounge','+91 9812456789'); 

function setWalkupLocPhone(locName, phoneNumber) {
  var walkupLoc = new GlideRecord('wu_location_queue');
  walkupLoc.addQuery('name', locName);
  walkupLoc.query();
  walkupLoc.next();
  
  // Set phone number of walk-up location
  var isPhoneNumberSet = walkupLoc.phone_number.setPhoneNumber(phoneNumber, true);
  walkupLoc.update();
  gs.info('Phone Number: ' + walkupLoc.phone_number);
  gs.info('Is phone number specified match the correct format: ' + isPhoneNumberSet);
}

출력:

Phone Number: +919812456789
Is phone number specified match the correct format: true

범위가 지정된 GlideElement - setValue(객체 값)

필드의 값을 설정합니다.

주:
이 메서드를 호출하기 전에 기존 레코드를 쿼리하거나 now_GR.initialize() 메서드를 사용하여 새 레코드를 초기화하여 요소가 이미 존재해야 합니다.
password2 필드를 사용한 인증 아님
setValue() 메서드는 password2 데이터를 일반 텍스트로 전달하므로 암호화된 데이터를 예상하는 것에 대한 오류가 발생합니다. 또한 password2 필드에 setValue() 메서드를 사용하면 암호화해야 하는 데이터가 노출됩니다.

password2 인증의 경우 setDisplayValue() 메서드를 대신 사용합니다.

표 61. 매개변수
이름 유형 설명
객체 필드를 설정할 객체 값입니다.
표 62. 반환
유형 설명
없음

문자열을 전달하는 값을 설정합니다.

var glideRecord = new GlideRecord('incident');
glideRecord.query('priority','1');
glideRecord.next();
glideRecord.short_description.setValue('Network failure');

객체를 전달하는 값을 설정합니다.

var now_GR  = new GlideRecord('student');
now_GR.initialize();
now_GR.setValue('first_name', 'Joe');
now_GR.setValue('last_name', 'Smith');
now_GR.insert();

범위가 지정된 GlideElement - toString()

GlideRecord 필드의 값을 문자열로 변환합니다.

표 63. 매개변수
이름 유형 설명
안 함
표 64. 반환
유형 설명
문자열 문자열로 값을 지정합니다.
var glideRecord = new GlideRecord('incident');
glideRecord.query('priority','1');
glideRecord.next();
gs.info(glideRecord.opened_at.toString());

출력:

2019-08-31 23:09:51