ScriptableDataStream - 범위가 지정됨, 전역

  • 릴리스 버전: Xanadu
  • 업데이트 날짜 2024년 08월 01일
  • 읽기11분
  • ScriptableDataStream API는 데이터 스트림과 상호 작용하는 메서드를 제공합니다.

    이 클래스는 다음 API 중 하나를 사용하여 ScriptableDataStream 객체를 검색한 후에만 서버 측 스크립트에서 사용할 수 있습니다.

    • FlowAPI 클래스의 executeDataStreamAction() 메서드입니다. FlowAPI를 참조하세요.
    • ScriptableFlowRunnerResult 클래스의 getDataStream() 메서드 ScriptableFlowRunnerResult를 참조하십시오.

    ScriptableDataStream 객체를 검색한 후 다음과 같은 특정 순서로 메서드를 호출합니다.

    1. hasNext() 메서드를 사용하여 데이터 스트림에 더 많은 항목이 있는지 여부를 확인합니다.
    2. next() 메서드를 사용하여 스트림의 다음 항목에 액세스합니다.
    3. getItemIndex(),getItemInPageIndex()getPageIndex() 메서드를 사용하여 스트림에서 정보를 가져옵니다.
    4. close() 메서드를 사용하여 스트림을 닫습니다.

    이 클래스 실행은 sn_fd 네임스페이스에 있습니다.

    주:
    항상 try/catch 블록에 데이터 스트림 논리를 래핑하여 오류를 catch합니다. 데이터 스트림을 닫고 성능 문제를 방지하기 위해 항상 ScriptableDataStream 클래스의 close() 메서드로 끝나는 finally 문을 포함하십시오.

    ScriptableDataStream - close()

    데이터 스트림에 대한 연결을 닫습니다. 항상 데이터 스트림에서 원하는 작업을 수행한 후에 이 메서드를 호출합니다.

    FlowAPI 클래스의 executeDataStreamAction() 메서드에서 반환된 ScriptableDataStream 객체에서만 이 메서드를 호출할 수 있습니다. FlowAPI를 참조하세요.

    표 1. 매개변수
    이름 유형 설명
    없음
    표 2. 반환
    유형 설명
    void
    (function() {
    	
    	try {
    ​
    		// Execute Data Stream Action. 
    		var stream = sn_fd.FlowAPI.executeDataStreamAction('x_snc_my_scope.data_stream_name');
    ​
    		// Process each item in the data stream
    		while (stream.hasNext()) {
    ​
    			// Get a single item from the data stream.
    			var user = stream.next();
    		
    			// Only log the first item in each page
    			if (stream.getItemInPageIndex() == 0) {
    				gs.info('first user on page is ' + user.name);
    			}
    		}		
    	} catch (ex) {
    		var message = ex.getMessage();
    		gs.error(message);
    	} finally {
    		stream.close();
    	}
    	
    })();

    ScriptableDataStream - getItemIndex()

    데이터 스트림에 있는 항목의 현재 인덱스를 반환합니다.

    FlowAPI 클래스의 executeDataStreamAction() 메서드에서 반환된 ScriptableDataStream 객체에서만 이 메서드를 호출할 수 있습니다. FlowAPI를 참조하세요.

    표 3. 매개변수
    이름 유형 설명
    없음
    표 4. 반환
    유형 설명
    번호 0부터 시작하는 인덱싱을 사용하는 데이터 스트림 항목의 현재 인덱스입니다.
    (function() {
    	
    	try {
    
    		// Execute Data Stream Action. 
    		var stream = sn_fd.FlowAPI.executeDataStreamAction('x_my_scope.data_stream_name');
    
    		// Process each item in the data stream
    		while (stream.hasNext()) {
    
    			// Get a single item from the data stream.
    			var User = stream.next();
    
    			// Use the item. Example:
    			// var now_GR = new GlideRecord(<table_name>);
    			// now_GR.<field_name> = User.<field_name>;
    			// now_GR.insert();
    		
    			// By default, this code snippet will terminate after 10 items.
    			// Remove or modify this limit after your code has been tested.
    			if (stream.getItemIndex() >= 9) {
    				break;
    			}
    		}		
    	} catch (ex) {
    		var message = ex.getMessage();
    		gs.error(message);
    	} finally {
    		stream.close();
    	}
    	
    })();

    ScriptableDataStream - getItemInPageIndex()

    데이터 스트림의 현재 페이지 내에 있는 항목의 현재 인덱스를 반환합니다.

    FlowAPI 클래스의 executeDataStreamAction() 메서드에서 반환된 ScriptableDataStream 객체에서만 이 메서드를 호출할 수 있습니다. FlowAPI를 참조하세요.

    표 5. 매개변수
    이름 유형 설명
    없음
    표 6. 반환
    유형 설명
    번호 0부터 시작하는 인덱싱을 사용하여 데이터 스트림의 현재 페이지 내에 있는 항목의 현재 인덱스입니다.
    (function() {
    	
    	try {
    ​
    		// Execute Data Stream Action. 
    		var stream = sn_fd.FlowAPI.executeDataStreamAction('x_snc_my_scope.data_stream_name');
    ​
    		// Process each item in the data stream
    		while (stream.hasNext()) {
    ​
    			// Get a single item from the data stream.
    			var user = stream.next();
    		
    			// Only log the first item in each page
    			if (stream.getItemInPageIndex() == 0) {
    				gs.info('first user on page is ' + user.name);
    			}
    		}		
    	} catch (ex) {
    		var message = ex.getMessage();
    		gs.error(message);
    	} finally {
    		stream.close();
    	}
    	
    })();

    ScriptableDataStream - getPageIndex()

    데이터 스트림에 있는 페이지의 현재 인덱스를 반환합니다.

    FlowAPI 클래스의 executeDataStreamAction() 메서드에서 반환된 ScriptableDataStream 객체에서만 이 메서드를 호출할 수 있습니다. FlowAPI를 참조하세요.

    표 7. 매개변수
    이름 유형 설명
    없음
    표 8. 반환
    유형 설명
    번호 0부터 시작하는 인덱싱을 사용하는 데이터 스트림 페이지의 현재 인덱스입니다.
    (function() {
    	
    	try {
    
    		// Execute Data Stream Action. 
    		var stream = sn_fd.FlowAPI.executeDataStreamAction('x_my_scope.data_stream_name');
    
    		// Process each item in the data stream
    		while (stream.hasNext()) {
    
    			// Get a single item from the data stream.
    			var item = stream.next();
    
    			// Use the item. 
    			var now_GR = new GlideRecord('incident');
    			now_GR.setValue('number',item.id);
    			now_GR.setValue('short_description',item.name);
    			now_GR.insert();
    		
    			// By default, this code snippet will terminate after 5 pages.
    			// Remove or modify this limit after testing your code.
    			if (stream.getPageIndex() >= 4) {
    				break;
    			}
    		}		
    	} catch (ex) {
    		var message = ex.getMessage();
    		gs.error(message);
    	} finally {
    		stream.close();
    	}
    	
    })();

    ScriptableDataStream - hasNext()

    데이터 스트림에 더 많은 항목이 있으면 예를 반환합니다.

    FlowAPI 클래스의 executeDataStreamAction() 메서드에서 반환된 ScriptableDataStream 객체에서만 이 메서드를 호출할 수 있습니다. FlowAPI를 참조하세요.

    주:
    기본적으로 인스턴스는 MID 서버에서 데이터의 단일 페이지를 검색하기 위해 600초 동안 대기합니다. MID 서버를 통해 데이터 스트림 동작을 실행할 동안 시간 제한이 발생할 경우 datastream_alternative_env_fetch_page_timeout_seconds 시스템 속성을 늘려 이 기본값을 변경하십시오.
    표 9. 매개변수
    이름 유형 설명
    없음
    표 10. 반환
    유형 설명
    부울 데이터 스트림에 더 많은 항목이 있는지 여부를 확인하는 플래그입니다. 값은 다음과 같습니다.
    • true: 데이터 스트림에서 반복할 항목이 더 있습니다.
    • false: 데이터 스트림에 더 이상 항목이 없습니다.

    이 예제에서는 데이터 스트림에 반환된 각 항목에 대한 인시던트 기록을 만듭니다.

    (function() {
    	
    	try {
    
    		// Execute Data Stream Action. 
    		var stream = sn_fd.FlowAPI.executeDataStreamAction('x_my_scope.data_stream_name');
    
    		// Process each item in the data stream
    		while (stream.hasNext()) {
    
    			// Get a single item from the data stream.
    			var item = stream.next();
    
    			// Use the item. 
    			var now_GR = new GlideRecord('incident');
    			now_GR.setValue('number',item.id);
    			now_GR.setValue('short_description',item.name);
    			now_GR.insert();
    		
    			// By default, this code snippet will terminate after 10 items.
    			// Remove or modify this limit after testing your code.
    			if (stream.getItemIndex() >= 9) {
    				break;
    			}
    		}		
    	} catch (ex) {
    		var message = ex.getMessage();
    		gs.error(message);
    	} finally {
    		stream.close();
    	}
    	
    })();

    ScriptableDataStream - 다음()

    데이터 스트림의 다음 항목을 반환합니다.

    FlowAPI 클래스의 executeDataStreamAction() 메서드에서 반환된 ScriptableDataStream 객체에서만 이 메서드를 호출할 수 있습니다. FlowAPI를 참조하세요.

    주:
    기본적으로 인스턴스는 MID 서버에서 데이터의 단일 페이지를 검색하기 위해 600초 동안 대기합니다. MID 서버를 통해 데이터 스트림 동작을 실행할 동안 시간 제한이 발생할 경우 datastream_alternative_env_fetch_page_timeout_seconds 시스템 속성을 늘려 이 기본값을 변경하십시오.
    표 11. 매개변수
    이름 유형 설명
    없음
    표 12. 반환
    유형 설명
    객체 데이터 스트림의 다음 항목입니다. 이 객체에는 데이터 스트림 작업에서 정의한 출력이 포함됩니다. 데이터 스트림 작업 출력을 보려면 플로우 디자이너 인터페이스에서 데이터 스트림 작업의 출력 섹션으로 이동합니다.

    이 예제에서는 데이터 스트림에 반환된 각 항목에 대한 인시던트 기록을 만듭니다.

    (function() {
    	
    	try {
    
    		// Execute Data Stream Action. 
    		var stream = sn_fd.FlowAPI.executeDataStreamAction('x_my_scope.data_stream_name');
    
    		// Process each item in the data stream
    		while (stream.hasNext()) {
    
    			// Get a single item from the data stream.
    			var item = stream.next();
    
    			// Use the item. 
    			var now_GR = new GlideRecord('incident');
    			now_GR.setValue('number',item.id);
    			now_GR.setValue('short_description',item.name);
    			now_GR.insert();
    		
    			// By default, this code snippet will terminate after 10 items.
    			// Remove or modify this limit after testing your code.
    			if (stream.getItemIndex() >= 9) {
    				break;
    			}
    		}		
    	} catch (ex) {
    		var message = ex.getMessage();
    		gs.error(message);
    	} finally {
    		stream.close();
    	}
    	
    })();