Using Zen Mojo
Submitting Data to the Server
[Home] [Back] [Next]
InterSystems: The power behind what matters   
Class Reference   
Search:    

This chapter describes how to submit data from a Zen Mojo page to the server. It discusses the following:

For an overview, see Submitting Data,” in the first chapter.
Submitting Data to the Server
To enable your page to send data to the server, do the following:
Example
The following shows a simple example for a method that sends a submit object to the server:
ClientMethod myMainViewSelect(key, value) [ Language = javascript ]
{
    var mainView = zen('mainView');

    switch(key) {
    case 'submitEdits':
        var controlvalue1=mainView.getControlValue('enterName');
        var controlvalue2=mainView.getControlValue('enterCity');
        var submitobject={name:controlvalue1,city:controlvalue2};
        var response = zenPage.submitData('submitEdits',submitobject);
        if (response && response.message) {
            zenPage.showMessage(response.message);
        }
        mainView.updateLayout('fade');
        break;
    }
The template class defines the %OnSubmitData() method as follows:
ClassMethod %OnSubmitData(pKey As %String, pID As %String, pSubmitObject As %RegisteredObject, 
                          ByRef pResponseObject As %RegisteredObject) As %Status
{
    Set tSC = $$$OK
    Try {
        if pKey="submitEdits"{
            set id=1
            set tPerson           = ##class(Sample.Person).%OpenId(id)
            set tPerson.Name      = pSubmitObject.name
            set tPerson.Home.City = pSubmitObject.city

            Set pResponseObject = ##class(%ZEN.proxyObject).%New()
            Set tSC = tPerson.%Save()
            If $$$ISERR(tSC) { 
                Set pResponseObject.message = "Your changes were not successfully saved"
                Quit}

            Set pResponseObject.message = "Your changes have been successfully saved"
        }
    }
    Catch(ex) {
        Set tSC = ex.AsStatus()
    }
    Quit tSC
}