Lawtex - how to use logic based on the field of a struct vector?

Asked

Viewed 232 times

1

I have a vector that uses a struct with several variables and one of them is a boolean. What can I do to execute something if at least one element of this vector has this variable as true?

struct[STR_Dados_dos_Inadimplentes] {
     fields {
          +[pagouMulta]: Boolean{
              name = "Pagou multa"
              request = "A multa foi paga?"
          }
     }
},

+|inadimplentes|: Vector[STR_Dados_dos_Inadimplentes]{
     name = "Dados dos inadimplentes"
     request = "Insira dados dos inadimplentes"
}

1 answer

1


You can perform several logics, in different positions and syntax of the code, according to your wishes, using the value of this Boolean. I will explain 3 possibilities of operation:

(1) To create another variable, within the struct

Within fields, just use a if simple to create the logic. Important to understand that as the variable [pagouMulta] is already a Boolean, you can write the condition of the if as much as if([pagouMulta] == true) or simply as if([pagouMulta]), and the creation of the new field would be:

struct[STR_Dados_dos_Inadimplentes] {
    fields {
        +[pagouMulta]: Boolean {
            name = "Pagou multa"
            request = "A multa foi paga?"
        },
        if([pagouMulta]) {
            +[valorMulta]: Integer {
                name = "Valor da Multa"
                request = "Qual foi o valor da multa paga?"
            }
        }
    }
},

Then the field [valorMulta]will only exist, and be asked, if the user’s answer is true for [pagouMulta].

(2) For some logic operation within the struct

By placing an operating logic within the struct, it is executed with priority, so a value of this struct changes, and applies to all instantiated objects for this struct, and for this, just create this logic within the loaders, as below:

struct[STR_Dados_dos_Inadimplentes] {
    fields {
        +[pagouMulta]: Boolean {
            name = "Pagou multa"
            request = "A multa foi paga?"
        }
    }
    loaders {
        if([pagouMulta]) {
            //Operação específica que queira realizar, como por exemplo:
            print "A multa foi paga"
        }
    }
},

(3) For some logic operation within the operations of head, body or extra

To use this variable inside the operations, can only be done by using an instantiated variable such as STR_Dados_dos_Inadimplentes. So say we create a variable
+<inadimplente>: STR_Dados_dos_Inadimplentes, and we want to do an operation inside the operations of head, then we can do:

head { 
    operations {
        if(<inadimplente.pagouMulta>){
            // Operação que queira executar, como por exemplo, usar uma branch específica para multa paga
            use branch[BRC_Multa_Paga]
        }
    }
}

In your example, specifically, you created the vector |inadimplentes|, so to make the operation, we have two ways:

1. select a vector-specific element, using the Vector index to select a specific object, such as |inadimplentes{0}| for the first element, |inadimplentes{1}| for the second and etc, and only replace the if(<inadimplente.pagouMulta>) by a if(|inadimplentes{0}.pagouMulta|)

2. use a foreach to perform the operation on all elements of Vector, such as:

head { 
    operations {
        foreach(<inadimplente> IN |inadimplentes|) {
            if (<inadimplente.pagouMulta>) where (separator = "%f1, %s2, %p2 e %l2.") {
                // Operação que queira executar, como por exemplo, imprimir os dados do inadimplente
                print <inadimplente>
            }
        }
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.