User friendly error messages for "Write File" actions in process flows

  • 22 October 2020
  • 0 replies
  • 45 views

Userlevel 4
Badge +4

Goal

Process flows are great in flexibility. But when you don't add your own error handling, the user might not notice when something went wrong and strange issues might be reported. 

 

Solution

Automatically generate error handling for specific process actions.

 

Write File 

First, you need a process variable to store the error code. Then you need to link this error code to the output of the process action. And last, if not already done, use processes in this process action. This can all be set automatically in a dynamic procedure:

-- Add a process variable for every process flow with a "write file" action
insert into process_variable
(
project_id,
project_vrs_id,
process_flow_id,
process_variable_id,
dom_id,
insert_user,
insert_date_time,
update_user,
update_date_time
)
select
@project_id,
@project_vrs_id,
f.process_flow_id,
'write_file_status_code',
'status_code', -- Add this domain or replace it with another
dbo.tsf_user(),
sysdatetime(),
dbo.tsf_user(),
sysdatetime()
from process_flow f
where f.project_id = @project_id
and f.project_vrs_id = @project_vrs_id
and exists (select 1
from process_action a
where a.project_id = f.project_id
and a.project_vrs_id = f.project_vrs_id
and a.process_flow_id = f.process_flow_id
and a.process_action_type = 640 -- Write file
)
and not exists (select 1
from process_variable v
where v.project_id = f.project_id
and v.project_vrs_id = f.project_vrs_id
and v.process_flow_id = f.process_flow_id
and v.process_variable_id = 'write_file_status_code'
)

-- Link the parameter to the action output so it is filled with the error code in the process flow
insert into process_action_fixed_output_parmtr
(
project_id,
project_vrs_id,
process_flow_id,
process_action_id,
output_parmtr_id,
process_variable_id,
insert_user,
insert_date_time,
update_user,
update_date_time
)
select
a.project_id,
a.project_vrs_id,
a.process_flow_id,
a.process_action_id,
'status_code',
'write_file_status_code',
dbo.tsf_user(),
sysdatetime(),
dbo.tsf_user(),
sysdatetime()
from process_action a
where a.project_id = @project_id
and a.project_vrs_id = @project_vrs_id
and a.process_action_type = 640 -- Write file
and not exists (select 1
from process_action_fixed_output_parmtr p
where p.project_id = a.project_id
and p.project_vrs_id = a.project_vrs_id
and p.process_flow_id = a.process_flow_id
and p.process_action_id = a.process_action_id
and p.output_parmtr_id = 'status_code'
)

-- Enable the process procedure
update a
set use_processes = 1
from process_action a
where a.project_id = @project_id
and a.project_vrs_id = @project_vrs_id
and a.process_action_type = 640 -- Write file
and a.use_processes = 0

With a dynamic CP, it is possible to automatically add this error logging to ever process flow.

insert into prog_object_item
(
project_id,
project_vrs_id,
prog_object_id,
prog_object_item_id,
order_no,
control_proc_id,
template_id
)
select @project_id,
@project_vrs_id,
'prc_' + process_flow_id + '_' + process_action_id,
@control_proc_id,
10,
@control_proc_id,
@control_proc_id
from process_action p
where p.project_id = @project_id
and p.project_vrs_id = @project_vrs_id
and p.process_action_type = 640 -- Write file

I've used every error code from the documentation and given it a user friendly message. Feel free to modify the text for your own needs.

if @write_file_status_code <> 0 --error
begin
declare @msg_text varchar(500)

select @msg_text = '<text>'
+ case @write_file_status_code
when -1 then 'Writing to disk failed because of an unknown error.'
when -2 then 'Writing to disk failed because there is no path specified.'
when -3 then 'Writing to disk failed because the specified path is too long.'
when -4 then 'Writing to disk failed because the specified path is invalid.'
when -5 then 'Writing to disk failed because the specified disk could not be found.'
when -6 then 'Writing to disk failed because one or more sub-folders could not be found.'
when -7 then 'Writing to disk failed because the file could not be found.'
when -8 then 'Writing to disk failed because the file already exists.'
when -9 then 'Writing to disk failed because access refused.'
else 'Writing to disk failed. Status code: ' + coalesce(cast(@write_file_status_code as varchar(10)), 'unknown') + '.'
end
+ '</text>'

exec tsf_send_message 'default' , @msg_text, 1
end

For this template, I used ‘default’, but I would recommend changing it to a newly created message instead. This is for a product that is one-language, if you want multi-language you could create messages for every error code like this:

if @write_file_status_code <> 0 --error
begin
declare @msg_id tsf_msg_id

select @msg_id = case @write_file_status_code
when -1 then 'msg_write_file_unknown_error'
when -2 then 'msg_write_file_no_path_specified'
when -3 then 'msg_write_file_specified_path_too_long'
when -4 then 'msg_write_file_specified_path_invalid'
when -5 then 'msg_write_file_specified_disk_could_not_be_found'
when -6 then 'msg_write_file_subfolder_could_not_be_found'
when -7 then 'msg_write_file_file_could_not_be_found'
when -8 then 'msg_write_file_file_already_exists'
when -9 then 'msg_write_file_access_refused'
end

exec tsf_send_message @msg_id, null, 1
end

 

 


0 replies

Be the first to reply!

Reply