Question
· 11 hr ago

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/>
                <a href="EnsPortal.VisualTrace.zen?SESSIONID=#(%task.%FormValues.GetAt("MsgHdrID"))#" target="_blank">View Message Trace</a><br/><br/>
                <button type='button' onclick='executeCacheCode();'>Resend Message</button>
                <script type="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$";

}
$ZV: HealthShare Provider Directory 2024.2.0 Build: 1009 [HealthShare Modules: Core:28.0 + Provider Directory:28.0] - IRIS for UNIX (Red Hat Enterprise Linux 8 for x86-64) 2024.1 (Build 267_2_24113U) Wed Jul 2 2025 16:36:55 EDT [Core:28.0|Provider Directory:28
Discussion (1)2
Log in or sign up to continue

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

  1. Define OnPage Method: The OnPage method of your %CSP.Page class 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
    }
    
  2. Class Methods for Backend Functionality: Implement ResendMessage method in the class. This method will receive the message ID and call the ResendDuplicatedMessage method.

    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 ResendDuplicatedMessage method in the Ens.MessageHeader class 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:
1. Use Visual Trace to monitor the resend operation and the associated messages [1].
2. Ensure the MsgHdrID parameter passed to the backend matches a valid message header ID.

References: [1][3][2]

Sources: