prepopulate.conf: How to config/debug rules and expressions?

I've created a working prepopulate.conf ruleset that's happily copying over data from some fields to auto-fill the preferred labels.

Now I'd like to add a "skipIfExpression" condition so that only one of repeated MD-elements is used as data source.

For testing, I've copied the documentation example and replaced it with the entity identifier of my test entry:

"skipIfExpression = ^ca_entities.idno =~ /VHH-A-0031247/,"

That line seems to have no effect. The rule is still executed and always adds all the names, separated by a ";" into the preferred labels forename field:

 agent_person_forename = {
       #skipIfExpression = ^ca_entities.vhh_PersonName.PN_DisplayName =~ /skip/,
       skipIfExpression = ^ca_entities.idno =~ /VHH-A-0031247/,
       table = ca_entities,
       restrictToTypes = [person],
       mode = overwrite,
       target = ^ca_entities.preferred_labels.forename,
       template = ^ca_entities.vhh_PersonName.PN_Forename,
       useFor = [edit, save],
   }


How can I debug this?


Thanks in advance! :)

Comments

  • edited April 29

    ...and would it actually be possible to have a checkbox in an md-element container and then do something like this?

    skipIfExpression = ^ca_entities.my_stuff.useme != /eng/
    

    With "eng" being the idno of an item in a list (in this case a language code).

    Would be cool.

  • I've found the logs, and in another attempt to brute force my way through this, i failed to do a simple "if($field == 'string value')", because it rejects my "not equal" (neq) operator:

    ERROR --> Hoa\Compiler\Exception\UnexpectedToken: Unexpected token "!=" (neq) at line 1 and column 35:
    ^ca_places.vhh_TitlePlace.PT_Type != /official_name/
    
    2021-04-29 23:17:15 - ERROR --> Hoa\Compiler\Exception\UnexpectedToken: Unexpected token "<>" (neq) at line 1 and column 35:
    ^ca_places.vhh_TitlePlace.PT_Type <> /official_name/
    

    What am I doing wrong here?


    Thanks again!

  • edited April 29

    You're using a regular expression there, so try using the regex operators =~ and !~ rather than the string comparison operators. Eg.

    ^ca_places.vhh_TitlePlace.PT_Type !~ /official_name/
    


  • edited April 29

    Hi,

    As this seems to a regexp syntax, what if you try to escape the dash symbol by adding backslash before, such as:

    skipIfExpression = ^ca_entities.idno =~ /VHH\-A\-0031247/,
    


  • Thanks for the regexp tip, but I've also got the "unexpected token" error if I tried:

    skipIfExpression = ^ca_places.vhh_TitlePlace.PT_Type != "official_name",
    skipIfExpression = ^ca_places.vhh_TitlePlace.PT_Type != official_name,
    

    (Same with "<>").

    For testing, I've now replaced it with:

    skipIfExpression = ^ca_places.vhh_TitlePlace.PT_Type !~ /official_name/,
    

    Now there's no more error, but the line still has no effect:

    Even if "PT_Type" is not "official_name" (=idno, not label, not value) - the string is still copied (but should be skipped). I've also tried /official/, not knowing if the label or the idno or the value is evaluated. Same behavior.

  • edited April 30

    In the end, my actual question is:

    How can I prepopulate preferred_labels from values of repeating container MD-elements, without having all the parallel values concatenated there, but cherry-pick by "skipIfExpression"?


    Found this in the docs:

    The <if> tag provides maximum control by using expressions to determine when content is displayed. For example, to output the display only if "current" is selected from the type drop-down in a repeating credit line container:

            <unit relativeTo="ca_objects.credit_line"><if rule="^ca_objects.credit_type =~ /current/">^ca_objects.credit_line.credit_text 
            (^ca_objects.credit_line.credit_type)</if></unit>
    


    Which sounds like what I want to do, but I'd read the example code as inconsistently syntaxed:

    The "if-rule" tests says "^ca_objects.credit_type" (container "credit_line" missing?), but the template text lists it inside a container: ^ca_objects.credit_line.credit_type

    Plus, there's no caret (^) for "ca_objects" in "relativeTo": Is this a typo or different syntax?

    Is that rule certain to work as-is?

  • The caret ^ is not needed in "relativeTo". Not a typo.

Sign In or Register to comment.