Editing Schedule Work Order Numbers

Prev Next

Required PEI User roles for below: INSP WO SPEC, INSP CLERK/A, INSP GENERAL, or INSP ADMIN.

Civil currently does not support editing CMMS Work Order Number.

Schedule Notification Number and CMMS Work Order Number can both be freely edited if the SAP Interface Active application setting has BValue set to 0.

If SAP Interface Active BValue is set to 1 and Allow Schedule SAP Work Order Number BValue is set to 0, editing of number won’t be possible.

If SAP Interface Active BValue is set to 1 and Allow Schedule SAP Work Order Number BValue is set to 1, then only CMMS Work Order Number is editable and it requires validation (it is no longer a free text input) and only on CAIR schedules in DRAFT.

[Workflows.WorkflowMethod]
public static bool CanEditScheduleSAPOrderNr(DomainRepoBase domainRepo, DC.IPDescriptable ipd) {
	if (!ApplicationSettingsCache.SapInterfaceActive(domainRepo)) {
		return true;
	}
	if (!ApplicationSettingsCache.AllowScheduleSAPWONrUpdate(domainRepo as ISharedRepo) || !(ipd is Schedule schedule)) {
		return false;
	}
	if (ThreadData.Current.Dict.GetValue<bool>(AppCore.StringConstants.IgnoreMethodology) || schedule.IsNew) {
		return true;
	}
	var cairInDraft = domainRepo.GetRepository<Schedule>().AsNoTracking()
		.Where(x => x.ScheduleId == schedule.DBRef)
		.Where(x => x.InspectionEvent1.InspectionApprovalStatus.Name_Enum == "DRAFT")
		.Where(x => x.InspectionType.Name_Enum == "CAIR")
		.Any();
	return cairInDraft;
}
-- can schedule notification / work order number be edited?
select s.ScheduleId, s.Name, s.SAPNotificationNumber as [Notification Number], s.SAPOrderNbr as [CMMS Work Order Number], SAPInterfaceActive.BValue, SAPWONumberUpdate.BValue, CanEditScheduleSAPOrderNr
from Schedule as s
left join ApplicationSettings as SAPInterfaceActive on SAPInterfaceActive.Name_Enum = 'SAPINTERFACE_ACTIVE'
left join ApplicationSettings as SAPWONumberUpdate on SAPWONumberUpdate.Name_Enum = 'ALLOW_SCHEDULE_SAPWONUMBER_UPDATE'
inner join InspectionEvent as ie on ie.InspectionEventId = s.CurrentInspectionEventId
inner join InspectionApprovalStatus as ias on ias.InspectionApprovalStatusId = ie.inspectionApprovalStatusId
inner join InspectionType as it on it.InspectionTypeId = s.InspectionTypeId
cross apply ( select
	case
		when coalesce(SAPInterfaceActive.BValue, 0) = 0 then 1 -- "SAP Interface Active" application setting
		when coalesce(SAPWONumberUpdate.BValue, 0) = 0 then 0 -- "Allow Schedule SAP Work Order Number" application setting
		-- if (ThreadData.Current.Dict.GetValue<bool>(AppCore.StringConstants.IgnoreMethodology) || schedule.IsNew) -- ???
		when ias.Name_Enum = 'DRAFT' and it.Name_Enum = 'CAIR' then 1 -- DRAFT CAIR
		else 0 
	end as CanEditScheduleSAPOrderNr
) as r
where s.ScheduleId = 1188749