Adding a button to %CSP.Page to execute ResendDuplicatedMessage
Within Provider Data Management, I wanted a way to capture the Code Table mapping errors thrown by HSPD.MDM.FlowControl.Process into a Workflow Task for someone to work. However, because HSPD.MDM.FlowControl.Process can get overwritten during the upgrade process, I cloned it into another Business Process so we can use Workflow Tasks to troubleshoot mapping errors.
This new Business Process will send the Errors to the Workflow Task Operation, but because it is not the HSPD.MDM.FlowControl.Process resubmitting the message will not resubmit the record to be processed through HSPD.MDM.FlowControl.Process.
So, using a Workflow Template, I am attempting to create another way to Resend the originating message using
##class(Ens.MessageHeader).ResendDuplicatedMessage(MsgHdrID)If I add the button to the OSU.ExternalFiles.Forms.workFlowTaskTemplate, and tell it to use javascript to call the Class Method Resend, when the button is clicked its not resending the message like it should.
Has anyone added a Button to a %CSP.Page to have it do something similar?
Class OSU.ExternalFiles.Forms.workFlowTaskTemplate Extends%CSP.Page
{
ClassMethod OnPage() As%Status
{
&html<
<table><tr><td>
Message Source: #(%task.%FormValues.GetAt("MsgSource"))# <br/>
Provider: #(%task.%FormValues.GetAt("Provider"))# <br/>
NPI: #(%task.%FormValues.GetAt("NPI"))# <br/>
Error: #(%task.%FormValues.GetAt("ErrorMsg"))# <br/><ahref="EnsPortal.VisualTrace.zen?SESSIONID=#(%task.%FormValues.GetAt("MsgHdrID"))#" target="_blank">View Message Trace</a><br/><br/><buttontype='button'onclick='executeCacheCode();'>Resend Message</button><scripttype="text/javascript">
function resendMessage() {
const response = #server(OSU.ExternalFiles.Forms.workFlowTaskTemplate.ResendMessage(%task.%FormValues.GetAt("MsgHdrID")))#;
alert('Result: ' + response);
}
</script></td></tr></table>
>Quit$$$OK
}
ClassMethod ResendMessage(MsgHdrID As%String) As%String
{
try{
Set tSC = ##class(Ens.MessageHeader).ResendDuplicatedMessage(MsgHdrID)
IF$$$ISERR(tSC){throw tSC}
}
Catch exception {
Set tSC = exception.AsStatus()
W"ERROR:",tSC,!
}
QUIT$$$OK
}
/// Location and Revision of this file in Perforce (Auto-updating)Parameter SrcVer = "$Id$";
}
Comments
To add a button to a %CSP.Page and execute a method such as ResendDuplicatedMessage from the class Ens.MessageHeader, you need to correctly define the button's event handling and ensure the communication between the web interface and the ObjectScript server code.
Creating a %CSP.Page Class
Define OnPage Method: The OnPage method of your
%CSP.Pageclass needs to generate the HTML for the page. This includes creating the button and specifying the JavaScript for its functionality.Example (based on your description):
ClassMethod OnPage() As %Status { &html< <button onclick="resendMessage()">Resend Message</button> >html Quit $$$OK }Class Methods for Backend Functionality: Implement
ResendMessagemethod in the class. This method will receive the message ID and call theResendDuplicatedMessagemethod.ClassMethod ResendMessage(MsgHdrID As %String) As %String { Try { Set tSC = ##class(Ens.MessageHeader).ResendDuplicatedMessage(MsgHdrID) If $$$ISERR(tSC) { Throw tSC } } Catch ex { Set tSC = ex.AsStatus() Quit "ERROR: "_tSC } Quit "Message resent successfully." }
Ensuring the Correct Execution
- The
ResendDuplicatedMessagemethod in theEns.MessageHeaderclass is used to resend messages programmatically. This method takes a message header ID and processes it as described [1][2]. - Log errors and ensure the method catches exceptions properly to handle unforeseen issues.
Sending the Request from Button
The JavaScript code uses #server syntax for server communication, as demonstrated. This ensures the Resend logic is executed on the server side and the result is returned to the browser.
Testing and Debugging
To debug:
- Use Visual Trace to monitor the resend operation and the associated messages [1].
- Ensure the
MsgHdrIDparameter passed to the backend matches a valid message header ID.
Sources: