Controling field from product lines on Create document - Sagex3

SUGGESTED

I'm a relatively new user at sagecity, so my apologies if I violated any rules in my post.

i'm Trying to check if a custom field in the lines of a document has value but i'm not achiving what i want...

here's what i tried:

Case ACTION
  When "VERIF_CRE"

    For I = 0 To [M:SIH4]NBLIG
     If [F:SIH4]ZSERIE = "" or [F:SIH4]ZSERIE = "0"
        [L]SERIE = 1
     Endif
    Next I
  
    if [L]SERIE = 1 Then
       Call ERREUR("teste de validação.") From GESECRAN
       mkstat = 2
    Endif

what am i doing wrong?

MyAccountAccess

  • 0

    Hi Simona,

    Welcome to Sage City!  Tip: It always helps if you include the Sage X3 version and patch level in your Forum posts. 

  • 0
    SUGGESTED

    Hi Simona,

    Welcome to Sage City! I did some corrections to your code:

    Case ACTION
      When "VERIF_CRE" : Gosub VERIF_CRE
      When Default
    Endcase
    
    
    $VERIF_CRE
    
    Local Integer I, SERIE
    
    For I = 0 To [M:SIH4]NBLIG-1
     If [M:SIH4]ZSERIE(I) = "" or [M:SIH4]ZSERIE(I) = "0"
        [L]SERIE = 1
        Break
     Endif
    Next I
    
    If [L]SERIE = 1
      OK = 0
      GERR = 1
      GMESSAGE = "teste de validação. - Some lines are not filled with ZSERIE value"  
    Endif
    Return
    

    First of all, when you are working with a label like “VERIF_CRE” the program stops with GERR and GMESSAGE variables, rather than 'mkstat', wich is used to show errors with field events like “AM_ITMREF()” for example.

    If you want to check the field “ZSERIE” for all the lines in the sales invoice, then you have to iterate the field with “ZSERIE(I)”.

    Last but not least, don’t write code in the ‘case ACTION’, always try to create a label with your code like my example.

    My code could be improved, changing the text for a "mess()" for example, but I hope this will help you for the moment.

    Regards,

    Pedro. 

  • 0 in reply to pedroarias

    Hi Simona,

    When declaring variables within standard object labels, be careful of using simple variables (I, J, K,... ) as these might be declared within other sections, instead implement the normal prefix for customer specific solutions (ZI, ZJ, ZK,...).  

    Currently the expression you have will only be valid if the field is blank and/or 0, not if it contains just spaces or combination of spaces and 0's. By using the vireblc function you can remove all spaces in the field: 

    Local Integer ZI, ZSERIE

    For ZI = 0 To [M:SIH4]NBLIG-1
         If vireblc([M:SIH4]ZSERIE(ZI),4) = "" or vireblc([M:SIH4]ZSERIE(ZI),4) = "0"
              [L]ZSERIE = 1
              Break
          Endif
    Next

    Regards,

    Regard

  • 0

    Hey pedroarias... i was also looking for solutions thanks a lot clear my doubts. MyAccountAccess MyAccountAccess.com