• If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Announcement

Collapse
No announcement yet.

[SOLVED] DomHelper Listener for Failure Error

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • [SOLVED] DomHelper Listener for Failure Error

    I do not know if this possible as my research has turned up nothing. Here is my HTML code.
    Code:
                    var MergeDocument = function(){
                        PMID = currentRecord.data.PMID;
                        PEID = Ext.getCmp('DOCUMENT').getValue()
                        Ext.DomHelper.append(document.body, {
                            tag: 'iframe',
                            frameBorder: 0,
                            width: 0,
                            height: 0,
                            css: 'display:none;visibility:hidden;height:1px;',
                            src: 'vvcall.pgm?sid=' + sid + '&opt=' + opt + '&pgm=prmergesb&action=mergeDocument&PMID=' + PMID + '&PEID=' + PEID
                        });
                        Ext.getCmp('mergeWindow').hide();
                        parent.showMessage('', '<b><center>Your document will be available shortly<\/b><\/center>');
                    };
    Here is my RPG code.
    Code:
             // If document created successfully
             // Then send the file to the browser
             // Else send error to the browser
    
             If Type = 'S';
               vvOut.download='Y';
               vvOut.file = %Char(Name) + '.docx';
               vvOut.contentType = 'application/x-download';
               vvout.binary='Y';
               vvOut_file(NewDoc:vvOut);
             Else;
               vvOut_toJsonPair('SUCCESS:0,MSG:' + %TrimR(Message));
             EndIf;
    If my document creation fails how can I pick up the error message so it displays a proper message to the end user.

    Thanks in advance

  • #2
    You could break the process into 2 steps. First use an ajax request to submit your request and params to merge the document and return 'success'. Check success returned - if the document merge fails then display a message, if 'success', then use the Ext.DomHelper code above to download the document.

    Comment


    • #3
      Thanks for the help. Based on your response here is what my client side code looks like.

      Code:
                      function MergeDocument(){
                          Ext.Ajax.request({
                              url: 'vvcall.pgm',
                              params: {
                                  action: 'mergeDoc',
                                  pgm: 'PRMERGESB',
                                  PMID: currentRecord.data.PMID,
                                  PEID: Ext.getCmp('DOCUMENT').getValue()
                              },
                              success: function(response){
                                  var check = response.responseText;
                                  if (check) {
                                      var data = Ext.util.JSON.decode(response.responseText);
                                      if (data.SUCCESS == '1') {
                                          Ext.getCmp('mergeWindow').hide();
                                          parent.showMessage('', '<b><center>Your document will be available shortly<\/b><\/center>');
                                          Ext.DomHelper.append(document.body, {
                                              tag: 'iframe',
                                              frameBorder: 0,
                                              width: 0,
                                              height: 0,
                                              css: 'display:none;visibility:hidden;height:1px;',
                                              src: 'vvcall.pgm?sid=' + sid + '&opt=' + opt + '&pgm=prmergesb&action=downloadDoc&PATH=' + data.PATH + '&FILE=' + data.FILE
                                          });
                                      }
                                      else {
                                          Ext.getCmp(data.FLD).markInvalid(data.MSG);
                                          Ext.getCmp(data.FLD).focus();
                                      }
                                  }
                              },
                              failure: function(){
                                  Ext.getBody().unmask();
                                  Ext.Msg.alert('Failure', 'Failed to receive a response from server');
                              }
                          });
                      };
      Here is my RPG code for the merge part.

      Code:
               // If document created successfully
               // Then send the file information to the browser
               // Else send error to the browser
      
               If Type = 'S';
                 vvOut_toJsonPair('SUCCESS:1,FILE:' + %Char(Name) + '.docx,PATH:' +
                   NewDoc);
               Else;
                 vvOut_toJsonPair('SUCCESS:0,MSG:' + %TrimR(Message) +
                   ',FLD:DOCUMENT');
               EndIf;
      Here is my RPG code for the download part.

      Code:
           **--------------------------------------------
           p DownloadDoc     b
           d DownloadDOc     pi
      
           D File            s            100a   varying
           D Path            s           5000a   varying
            /free
      
             Path=vvIn_char('PATH');
             File=vvIn_char('FILE');
             vvOut.download='Y';
             vvOut.file = File;
             vvOut.contentType = 'application/x-download';
             vvout.binary='Y';
             vvOut_file(Path:vvOut);
      
            /end-free
           p                 e
      It works like a charm. Thanks for your help.

      Comment

      Working...
      X