• 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.

NAB : help with validation pgm, wanted unexpected behaviour

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

  • NAB : help with validation pgm, wanted unexpected behaviour

    Not sure if i am doing something wrong, or if i need to add something

    i have a edit grid and i tried to use the external validation program..
    when the validation is succesfull i recieve a success:true and all is ok


    however when validation should return an error, the screen remains at 'creating record'
    although i see in the console the success:false;??


    am i missing something?, or is this a bug

    PHP Code:
       //*************************************************************************
         
    DCL-PROC PROCESSPOSTADD;
        
    //*************************************************************************
           
    dcl-s lCtabpr    char(25);

           
    lCtabpr GetValue('OBPRAL''CTABPR');
           if (%
    len(%trim(lCtabPr)) < 16);
              
    SendError('CostCombination must have 16 characters');
           Endif;
           
    Monitor;
             
    Qn016 = %dec(lCtabPr160);
             
    on-error;
                
    SendError('CostCombination may contain only numbers and must a length 16');
           
    Endmon;


         
    END-PROC
    Attached Files

  • #2
    added to that, the record was created to the file ... which should not have happened!!

    Comment


    • #3
      Hi Thierry,

      From your screenshot it appears your validation routine is sending a double response in the error scenario -- a "success:false" followed by a "success:true".

      Can you adjust the logic in your program to suppress the "success:true" response when an error is encountered?

      Comment


      • #4
        Hi Robert,


        thx for your response.. but i need more help.. because i don't know where or what i've put wrong.. i don't see in my program that i'm sending a success !

        Program was fully based on the existing example.. only thing i did was put in in all free.

        in the comment area of this program, it was mentioned that sending the errormessage also send a false..
        unfortunately it seems that after sending this errormessage, the sysyem is doing the update.. !!



        i've put the full program . in copy
        PHP Code:
        **FREE
        //*------------------------------------------------------------------------------------------*
        //* STRPREPRC Compile Options:                                                               *
        //*   >>PRE-COMPILER<<                                                                       *
        //*     >>CMD<< RMVLIBLE VALENCE52;                                                          *
        //*     >>CMD<< ADDLIBLE VALENCE52;                                                          *
        //*     >>CRTCMD<< CRTSQLRPGI OBJ(&LI/&OB) SRCFILE(&SL/&SF) SRCMBR(&SM);                     *
        //*       >>COMPILE<<                                                                        *
        //*         >>PARM<<  OBJTYPE(*PGM);                                                         *
        //*         >>PARM<<  DBGVIEW(*SOURCE);                                                      *
        //*         >>PARM<<  RPGPPOPT(*LVL2);                                                       *
        //*         >>PARM<<  OPTION(*NOXREF);                                                       *
        //*       >>END-COMPILE<<                                                                    *
        //*       >>EXECUTE<<                                                                        *
        //*     >>CMD<< RMVLIBLE VALENCE52;                                                          *
        //*   >>END-PRE-COMPILER<<                                                                   *
        //*------------------------------------------------------------------------------------------*
           
        /copy valence52/qcpylesrc,vvHspec

        //   ** --------------------------------------------------------------
        //   **         Copyright (C) 2008-2018 CNX Corporation
        //   ** --------------------------------------------------------------
        //   **     Object ID: EXNABVAL
        //   **       Version: V5.2
        //   **   Description: NAB Examples - Sample Nitro App Builder Validation/Modify Template
        //   **                For use with Edit Grid Validations within Nitro App Builder.
        //   **                This program template will serve as validation and/or
        //   **                overriding values to the record(s) before the add/update/delete.
        //   **      RPGPPOPT: *LVL2
        //   **
        //   **   Helper Procedures:
        //   **     GetValue(file:field)
        //   **       Get the value for the given file/field.
        //   **     GetFilterValue(file:field)
        //   **       Get the filter value for the given file/field.
        //   **     SetValue(file:field:value)
        //   **       Set the value for the given file/field.
        //   **     SetDoNotProcess(file)
        //   **       Skip the add/update/delete operation for the given file.
        //   **     IsChanged(file:field)
        //   **       Determine if the given file/field has been changed by the user.
        //   **     SendError(message)
        //   **       Stop the update process and send an error to the user.
        //   **
        //   **   Expected response:
        //   **     NOTE: a response should ONLY be sent if you are going to set *on the
        //   **           "outStopProcessing" parameter. This will cause the Nirto App Builder application
        //   **           to abort the add/edit/delete process. SendError procedure will
        //   **           automatically set this parameter *on for you.
        //   **     "success"        - Required: true/false
        //   **     "msg"            - Optional: Output a message to the user via a popup window.
        //   **     "info"           - Optional: Output a message to the user via the "snackbar".
        //   **     "refresh"        - Optional: true/false Refresh the grid's data
        //   **
        //   **   NOTE: this must be compiled with RPGPPOPT = *LVL2
        //   ** --------------------------------------------------------------

              
        dcl-PI OBPRALNAB;
                 
        inMode         char(10);
                 
        inDataPtr      pointer;
                 
        outStopProcess ind;
              
        End-pi;
              
        dcl-s Qn016     zoned(16);
              /
        define nabValidation
              
        /include valence52/qcpylesrc,vvNabTmpl

              Initialize
        ();

              
        // perform validations based on the mode...
              
        if inMode 'ADD';
                 
        ProcessAdd();
              elseif 
        inMode 'EDIT';
                 
        ProcessEdit();
              elseif 
        inMode 'DELETE';
                 
        ProcessDelete();
              elseif 
        inMode 'POSTADD';
                 
        ProcessPostAdd();
              elseif 
        inMode 'POSTDELETE';
                 
        ProcessPostDelete();
              elseif 
        inMode 'POSTEDIT';
                 
        ProcessPostEdit();
              endif;

              
        CleanUp();
              *
        inlr=*on;
              return;

           
        //*************************************************************************
             
        DCL-PROC PROCESSADD;
           
        //*************************************************************************
               // sample code to retrieve the next available customer number
               // and set the last activity date before adding a new record...
               //
               //exec sql select cusno into: lCusno from democmast
               //         order by cusno desc
               //         fetch first row only;
               //lCusno += 1;
               
        SetValue('OBPRAL':'BEDRPR':'001');
               
        SetValue('OBPRAL':'AFDLPR':' ');
               
        SetValue('OBPRAL':'TABIPR':'000346');
               
        SetValue('OBPRAL':'TLCDPR':'H');
               
        SetValue('OBPRAL':'RKWRPR':'0');

             
        End-proc;

           
        //*************************************************************************
             
        DCL-PROC PROCESSDELETE;
           
        //*************************************************************************

             
        End-proc;

           
        //*************************************************************************
             
        DCL-PROC PROCESSEDIT;
           
        //*************************************************************************

               // sample code to ensure that the user enters a 2 character
               // value for CSTATE...
        //       lState = GetValue('DEMOCMAST':'CSTATE');
        //       if (%len(%trim(lState)) < 2);
        //         SendError('State must be a 2 character code.');
        //       Endif;

             
        End-proc;

            
        //*************************************************************************
             
        DCL-PROC PROCESSPOSTADD;
            
        //*************************************************************************
               
        dcl-s lCtabpr    char(25);

               
        lCtabpr GetValue('OBPRAL''CTABPR');
               if (%
        len(%trim(lCtabPr)) < 16);
                  
        SendError('CostCombination must have 16 characters');
                  return;
               Endif;
               
        Monitor;
                 
        Qn016 = %dec(lCtabPr160);
                 
        on-error;
                    
        SendError('CostCombination may contain only numbers and must a length 16');
                    return;
               
        Endmon;


             
        END-PROC;

            
        //*************************************************************************
             
        DCL-PROC PROCESSPOSTDELETE;
            
        //*************************************************************************
             
        End-proc;

            
        //*************************************************************************
             
        DCL-proc ProcessPostEdit;
            
        //*************************************************************************
             
        End-proc;


              /include 
        valence52/qcpylesrc,vvNabTmpl 

        Comment


        • #5
          Hi Thierry,

          Now that I can see the whole program I see what the problem is: Your edit-checking source is located inside the wrong procedure. You should move it into the ProcessAdd procedure. When either the ProcessAdd or ProcessEdit procedures result in a call to SendError then the save attempt is aborted.

          To clarify: ProcessPostAdd and ProcessPostEdit are called AFTER all edit-checks are presumed to have passed. The names of these procedures might be kind of lost in translation -- "post" means "after" in this context, so "ProcessPostAdd" literally means "process after add". Since the save has already occurred by the time the Post procedures are called, a sendError call does not have any effect, other than to cause the double JSON response you're seeing.

          We'll add some more comments to the EXNABVAL sample code to make this more clear in the next build.

          -R

          Comment


          • #6
            Hi Robert,


            i was indeed lost in translation and assumed that the Post routines where launched before the actual update/add
            i've modified and tested and is now ok.


            thx for clarification.


            Thierry

            Comment

            Working...
            X