GlideScopedEvaluator - 범위 지정
GlideScopedEvaluator API를 사용하면 범위 지정 서버 스크립트와 전역 서버 스크립트 모두에서 GlideRecord 필드의 스크립트를 평가할 수 있습니다.
이 API는 정의된 스크립트 필드로 기록을 평가합니다. 스크립트의 범위는 기록의 범위에 따라 정의됩니다.
GlideScopedEvaluator - evaluateScript(GlideRecord, grObj, 문자열 scriptField, 객체 변수)
GlideRecord 필드에 있는 스크립트를 평가합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| grObj | GlideRecord | 스크립트 표현식이 포함된 GlideRecord입니다. |
| 스크립트 필드 | 문자열 | 옵션입니다. 스크립트 표현식이 포함된 필드의 이름입니다. |
| variables | 객체 | 옵션입니다. 이름-값 쌍이 있는 변수의 맵입니다. 이러한 변수는 이 메서드를 실행하는 동안 스크립트에서 사용할 수 있습니다. |
| 유형 | 설명 |
|---|---|
| 객체 | 스크립트 실행의 결과입니다. |
// Setting up a record that contains the script to be executed.
var now_GR = new GlideRecord('u_global_table');
now_GR.u_short_description = 'Calculate Addition';
now_GR.u_test_script = "result = x + y";
now_GR.insert();
var evaluator = new GlideScopedEvaluator();
evaluator.putVariable('x', 100);
evaluator.putVariable('y', 200);
evaluator.evaluateScript(now_GR, 'u_test_script', null);
gs.info(evaluator.getVariable('result'));
출력:
300
GlideScopedEvaluator - getVariable(이름 문자열)
GlideScopedEvaluator 객체에서 지정된 변수를 반환합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| name | 문자열 | 반환할 변수의 이름입니다. |
| 유형 | 설명 |
|---|---|
| 객체 | 지정된 변수의 값입니다. |
다음 예제에서는 getVariable() 메서드를 호출하여 응답 변수의 값을 확인하는 방법을 보여 줍니다.
(function executeRule(current, previous /*null when async*/) {
var grAG = current.assignment_group.getRefRecord(); // Get the GlideRecord of the assignment group
if (grAG.isValidRecord()) {
var ge = new GlideScopedEvaluator();
ge.putVariable("current", current); // Pass through the "current" variable as "current"
ge.putVariable("group", grAG); // Pass through the "grAG" variable as "group"
ge.putVariable("answer", true); // default "answer" to TRUE
ge.evaluateScript(grAG, "u_assignment_condition"); // Run the script
// Abort the transaction if the "answer" variable was set to FALSE explicitly (undefined doesn't count)
if (ge.getVariable("answer") === false) {
gs.addErrorMessage("Assignment rule did not pass");
current.setAbortAction(true);
}
}
})(current, previous);
GlideScopedEvaluator - GlideScopedEvaluator()
GlideScopedEvaluator 객체를 인스턴스화합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| 없음 |
GlideScopedEvaluator - putVariable(문자열 이름, 객체 값)
변수를 GlideScopedEvaluator 객체로 설정합니다. 이 GlideScopedEvaluator 객체가 실행하는 스크립트에서 이러한 변수를 사용할 수 있습니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| name | 문자열 | 변수 이름입니다. |
| 값 | 객체 | 변수 값입니다. |
| 유형 | 설명 |
|---|---|
| 없음 |
다음 예제에서는 putVariable() 메서드를 호출하여 응답 변수를 true로 설정하는 방법을 보여 줍니다.
(function executeRule(current, previous /*null when async*/) {
var grAG = current.assignment_group.getRefRecord(); // Get the GlideRecord of the assignment group
if (grAG.isValidRecord()) {
var ge = new GlideScopedEvaluator();
ge.putVariable("current", current); // Pass through the "current" variable as "current"
ge.putVariable("group", grAG); // Pass through the "grAG" variable as "group"
ge.putVariable("answer", true); // Set default "answer" to TRUE
ge.evaluateScript(grAG, "u_assignment_condition"); // Run the script
// Abort the transaction if the "answer" variable was set to FALSE explicitly (undefined doesn't count)
if (ge.getVariable("answer") === false) {
gs.addErrorMessage("Assignment rule did not pass");
current.setAbortAction(true);
}
}
})(current, previous);