다양한 작업 항목 유형에 대한 날짜/시간 입력 설정
입력 양식 화면을 만들고 날짜/시간 입력에 대한 IncludeTimezone 속성을 정의한 후에는 입력 양식 화면을 작업 항목과 연결해야 합니다. 날짜/시간 입력을 설정하는 방법은 사용하는 작업 항목의 유형에 따라 다릅니다.
| 작업 항목 유형 | 설정 |
|---|---|
| 신규 또는 업데이트 | 날짜/시간 입력이 백엔드 인스턴스의 날짜/시간 필드에 매핑되어 있는지 확인합니다. 백엔드 인스턴스는 입력 양식 화면에서 보낸 장치 시간대 정보를 사용합니다. 그런 다음 백엔드 인스턴스는 날짜/시간 값을 데이터베이스에 저장하기 전에 UTC/GMT(조정된 범용 시간)로 변환합니다. |
| 스크립트 | 날짜/시간 입력 값을 UTC/GMT로 변환해야 합니다. 자세한 내용은 다음 스크립트 예시를 참조하십시오. 에 대한 ServiceNow일반적인 스크립팅에 대한 자세한 내용은 스크립팅을 참조하십시오. 주: 관련된 사용 케이스에 따라 사용자 지정이 필요할 수 있습니다. |
GlideDateTime 스크립트 예
다음 예제에서는 GlideDateTime 형식의 필드를 설정합니다.
/sys_sg_write_back_action_step.do?sys_id=b390e6a7c1120110fa9b5abd6a7dbb64
(function WriteBackAction(parm_input, parm_variable, actionResult) {
var shortDescription = parm_input.shortdescription;
var scheduledStart = parm_input.expectedstart;
var estimatedEnd = parm_input.estimatedend;
var description = parm_input.description;
var wotSysId = parm_variable['sys_id'];
var wotGr = new GlideRecord("wm_task");
wotGr.get(wotSysId);
wotGr.setValue("description", description);
wotGr.setValue("short_description", shortDescription);
var newEnd = new GlideDateTime(estimatedEnd);
var endMS = newEnd.getNumericValue();
var newStart = new GlideDateTime(scheduledStart);
var startMS = newStart.getNumericValue();
if (endMS - startMS < 0) {
gs.addErrorMessage(gs.getMessage("The start date should come before the end date"));
} else {
//set the time on screen all the time
wotGr.setValue("expected_start", newStart);
wotGr.setValue("estimated_end", newEnd);
var duration = endMS - startMS;
var newDur = new GlideDuration();
newDur.setValue(duration);
wotGr.setValue("estimated_work_duration", newDur);
//check double booking no matter which field is changed. set needs_attention so that dispatcher can review it.
var info = new global.FSMAgentInfo(gs.getUserID());
var doubleBooking = info.allowAgentDoubleBookingTask();
if (doubleBooking){
var conflict = !(new global.SMDDateValidation().checkSchedulingConflictSimple(wotGr));
if (conflict) {
//BR Date Checks will display conflict message as Warning: {0} has been scheduled for a time the assigned
//only when time change.
wot.Gr.setValue("needs_attention", true);
}
}
- 이 예제에서
expected_start필드와estimated_end필드는expectedstart및estimatedend의 대응하는 날짜/시간 입력값에 따라 편집됩니다. - IncludeTimezone 속성이 true로 설정되어 있으므로
parm_input.expectedstart변수는 YYYY-MM-DDThh:mm:ss.sssTZD 형식의 날짜/시간 문자열을 반환합니다. 시스템에서 이 날짜/시간 형식을 처리할 수 있도록 하려면 문자열을 생성자에 전달하여 GlideDateTime 개체를 초기화합니다. expected_start및estimated_end는 데이터베이스의 날짜 시간 열이므로 GlideRecord.setValue()를 직접 호출하고GlideDateTime객체를 값으로 전달할 수 있습니다.
GlideScheduleDateTime 스크립트 예시
다음 예제에서는 GlideScheduleDateTime 유형의 필드를 설정합니다.
/sys_sg_write_back_action_item.do?sys_id=539b20d6b72120107be0e34e9e11a971
(function WriteBackAction(parm_input,parm_variable,actionResult) {
var personalSchedule = new global.FSMMobileUtil().getUserSchedule(parm_variable.user);
if (gs.nil(personalSchedule)) {
gs.error("create_event: personal schedule id is not found.");
gs.addErrorMessage(gs.getMessage("Create Event Failed"));
return;
}
if(gs.nil(parm_input.type))
parm_input.type = "";
var scheduleEntryGR = new GlideRecord("cmn_schedule_span");
scheduleEntryGR.initialize();
scheduleEntryGR.setValue("name", parm_input.name);
var start_time = new GlideDateTime(parm_input.start_time);
scheduleEntryGR.start_date_time = start_time.getDisplayValueInternal();
var end_time = new GlideDateTime(parm_input.end_time);
scheduleEntryGR.end_date_time = end_time.getDisplayValueInternal();
scheduleEntryGR.setValue("show_as", parm_input.show_as);
scheduleEntryGR.setValue("type", parm_input.type);
scheduleEntryGR.setValue("user", parm_variable.user);
scheduleEntryGR.setValue("schedule", personalSchedule);
scheduleEntryGR.setValue("repeat_type", parm_input.repeats);
if(parm_input.repeats!=""){
scheduleEntryGR.setValue("repeat_count", parm_input.repeat_every);
scheduleEntryGR.repeat_until = parm_input.repeat_until;
}
scheduleEntryGR.insert();
})(parm_input,parm_variable,actionResult);
- 이 예에서 일정 항목의
start_date_time및end_date_time필드는start_time및end_time의 해당 날짜/시간 입력 값을 기반으로 설정됩니다. - IncludeTimezone 속성이 true로 설정되어 있기 때문에
parm_input.start_time변수는 YYYY-MM-DDThh:mm:ss.sssTZD 형식으로 날짜/시간 문자열을 반환합니다. 시스템에서 이 날짜/시간 형식을 처리할 수 있도록 하려면 문자열을 생성자에 전달하여GlideDateTime개체를 초기화합니다. start_date_time및end_date_time는 데이터베이스의 날짜 시간 열이 아니므로(대신 일정 날짜/시간 열) 해당 값은gr.start_date_time = {date_time_value}로 설정됩니다.주:date_time_value는 사용자 프로필 시간대에 있어야 합니다(제공된 값은GlideDateTime의표시 값이어야 함). 이 구성을 사용하면 YYYY-MM-DD hh:mm:ss의 내부 형식과 사용자 프로필 시간대로 날짜/시간 문자열을 반환하는 GlideDateTime.getDisplayValueInternal() 메서드를 호출할 수 있습니다.