-- ABS-49087 / ABS-60073
insert into userinstructionperscreen
  (userinstructionperscreen_id,
   predefinedscreen_id,
   customeruserinstruction_id,
   generaluserinstruction_id,
   systemuser_id,
   timestamp,
   dialog_id)
  select seq_userinstructionperscreen.nextval,
         null,
         uis.customeruserinstruction_id,
         uis.generaluserinstruction_id,
         getminsystemuser(),
         sysdate,
         (select d.dialog_id
            from dialogs d
           where d.code = 'GarmentDeliveryNote')
    from userinstructionperscreen uis
   where uis.dialog_id =
         (select d.dialog_id
            from dialogs d
           where d.code = 'BatchDeliveryNote')
     and exists
   (select 1 from dialogs d where d.code = 'GarmentDeliveryNote')
     and not exists
   (select 1
            from userinstructionperscreen uis2
           where nvl(uis2.customeruserinstruction_id, -1) =
                 nvl(uis.customeruserinstruction_id, -1)
             and nvl(uis2.generaluserinstruction_id, -1) =
                 nvl(uis.generaluserinstruction_id, -1)
             and uis2.dialog_id =
                 (select d.dialog_id
                    from dialogs d
                   where d.code = 'GarmentDeliveryNote'));
commit;
