Convert @for -> list

Hi Everyone

I have some code that works perfectly but I assume that it go do with some “list love” i.e. I think that this would be better solved with lists.

I have a config document that admins can use to set values for a checkbox field (actually it can be used for any type of field). I allow the use of alias’s for the field values in the config document. I then load the values from the config document and display them in my checkbox field. The users then select what they want and the alias is saved in the field. No problem. I then have a computed for display field that displays the values selected when the document is in read mode. This displays the alias’s and not the values!

Here is an example:

config document field name: verteiler

Values:

value1 | 1

value2 | 2

value2 | 3

I then have a field on some form called testVerteiler that then loads the value of verteiler from the config doc (value1 | 1; value2 | 2; value3 | 3). I have a further field called _dispTestVerteiler that needs to display the selected values. if 1 and 3 was selected then the field currently displays 1 : 3 and I want it to display value1 : value3. I have code that does this but it uses 2 for loops that I think would be better suited to list processing - unfortunatly I cannot seem to figure out what I need :o(

Maybe some kind person would take a look at it?

Thank you in advance

Ursus Schneider

----------- here is the code -------

REM {get the current value};

REM ;

currValue := testVerteiler;

@If (currValue = “”; @Return (“”); “”);

REM ;

REM { now get the list of possible values from the config document };

REM ;

fieldName := “testVerteiler”;

key := “#” + formName + “#” + fieldName + “#”;

list := @DbLookup (“” : “NoCache”; “”; “vwKeywords”; key; 2; [FailSilent]);

REM ;

REM { check if you even need to search for aliases - if not then just return what was selected };

REM ;

@If (@Contains (list; “|”); “”; @Return (currValue));

REM ;

REM { split the values into 2 lists };

REM ;

abbrName := @Trim (@Right (@Explode (list; “;”); “|”));

longName := @Trim (@Left (@Explode (list; “;”); “|”));

REM ;

REM { now try and find your value in the list };

REM ;

retValue := “”;

@For (i := 1; i <= @Elements (currValue); i := i + 1;

@Do (

@For (j := 1; j <= @Elements (abbrName); j := j + 1; 	

	@Do (

	@If (@UpperCase (currValue [i]) = @UpperCase (abbrName [j]); retValue := retValue : longName [j]; "")

	)

)

)

);

retValue

---------- end of code --------

Subject: convert @for → list

Hi Ursus,

The way I do it is as follows:

@If(testVerteiler=“”;@return(“”);“”);

list := @DbLookup (“” : “NoCache”; “”; “vwKeywords”; key; 2; [FailSilent]);

values:= "| "+ testVerteiler;

templist:=@ReplaceSubstring(list;values;“”);

newlist:=@trim(@Replace(list;templist;“”));

@Left(newlist;“|”)

templist:=@ReplaceSubstring(list;values;“”);

  • templist contains all values from list, but the values that are in testVerteiler do not have an alias now;

newlist:=@trim(@Replace(list;templist;“”));

  • all values that are in both list and templist will be removed. Since the values of testVerteiler in templist don’t have an alias they will not be removed. So newlist will now contain all values and aliases of tempVerteiler

@Left(newlist;“|”)

  • since you want to show the values, take away the aliases.

Another, much easier, way is to make the computed for display field a dailoglist.

Fill the choices with the same values as the testVerteiler field (@DbLookup (“” : “NoCache”; “”; “vwKeywords”; key; 2; [FailSilent]);). In that case the values will show in a decent way.

Because you do the lookup several times, it is best to put this in a computed for display field (multiple values). In the checkbox field and one of the ways mentioned above you can use that fieldName instead of the dblookup.

Regards,

René