Hi @MFW-58 ,
one hack could be to:
- generate the externalMessageId in the event action
- generate the App Message - including generated externalMessageId
- update the Application Message to hold the externalMessageId you generated in the event action.
Below is a piece of PL/SQL code that would do just that:
DECLARE
attr_ VARCHAR2(32000);
sql_msg_ VARCHAR2(32000);
stmt_ VARCHAR2(32000);
job_id_ NUMBER;
task_seq_ VARCHAR2(100) := '&NEW:TASK_SEQ';
status_ VARCHAR2(100) := '&NEW:ROWSTATE';
BEGIN
stmt_ := q'[
DECLARE
url_params_ Plsqlap_Document_Api.Document;
query_parameters_ Plsqlap_Document_Api.Document;
header_params_ Plsqlap_Document_Api.Document;
auth_params_ Plsqlap_Document_Api.Document;
json_ CLOB;
rowkey_ VARCHAR2(100) := '&NEW:ROWKEY';
task_seq_ VARCHAR2(100) := '&NEW:TASK_SEQ';
req_id_ VARCHAR2(100);
external_message_id_ VARCHAR2(50) := Sys_Guid();
message_id_ NUMBER;
PROCEDURE Create_Application_Message
IS
BEGIN
req_id_ := Srv_Request_Scope_API.Get_Req_Id(Jt_Task_API.Get_Srv_Request_Scope_Id(task_seq_));
-- Build the JSON with the pre-allocated externalMessageId baked in
json_ := '{"eventName": "work_task_cancelled"
, "ifsEventName": "C_WORK_TASK_CANCELLED"
, "reportingEntityName": "IFSDesign"
, "externalMessageId": "' || external_message_id_ || '"
, "payload": { "ServiceRequestId": "' || req_id_ || '"
, "WorkTaskId": "' || task_seq_ || '"
}
}';
-- Create the application message and capture its application_message_id
Plsql_Rest_Sender_API.Call_Rest_EndPoint_Json(
rest_service_ => '',
json_ => json_,
message_id_ => message_id_,
url_params_ => url_params_,
callback_func_ => '',
http_method_ => '',
http_req_headers_ => '',
query_parameters_ => query_parameters_,
header_params_ => header_params_,
incld_resp_info_ => FALSE,
fnd_user_ => '',
key_ref_ => '',
sender_ => '***',
receiver_ => '***',
message_type_ => 'CONNECT',
subject_ => 'Info to ***- Task Cancelled for task: ' || task_seq_,
in_order_ => FALSE,
fail_notify_ => FALSE,
failed_callback_fun_ => '',
accepted_res_codes_ => '',
auth_params_ => auth_params_);
-- Overwrite the trigger-assigned sys_guid() with our pre-allocated id so the row and the JSON payload carry the same external_message_id.
UPDATE fndcn_application_message_tab
SET external_message_id = external_id_,
rowversion = rowversion + 1
WHERE application_message_id = message_id_;
END Create_Application_Message;
BEGIN
Create_Application_Message;
Transaction_SYS.Log_Progress_Info( '[Done] Application Message ' || message_id_ || ' created with EXTERNAL_MESSAGE_ID=' || external_id_);
END;
]';
sql_msg_ := Message_SYS.Construct('UPD');
Message_SYS.Add_Attribute(sql_msg_, 'SQL', stmt_);
Client_SYS.Clear_Attr(attr_);
Client_SYS.Add_To_Attr('SQL_DATA_', sql_msg_, attr_);
Client_SYS.Add_To_Attr('MSG_', '', attr_);
Transaction_SYS.Deferred_Call(
job_id_,
'Fnd_Event_Action_API.Action_Executeonlinesql',
'PARAMETER',
attr_,
'Event C_WORK_TASK_CANCELLED - Sending info to *** for task cancellation for Task: '
|| task_seq_ || ' status: ' || status_);
END;