Setting Line Item Field properties

I have some files that use a lot of line item fields, and I am trying to adapt them to new circumstances. Some of the line items are choice fields, and I want to change the choices of all of them. This was dead simple in Panorama 6. You made the change in the Design Sheet, and you would be asked if you wanted to change the rest of them. But that does not work in Panorama X.

So I tried to change them in a procedure, using:
setfieldproperties “Time1”,initializedictionary(“CHOICES”,"1 2 3 4 ") figuring that I could programmatically change the field in a loop. Two problems arose. The first is that it does not work, even in the field I am on. The second is that I get the error message that I cannot change the choices except in the current field, which itself brings up two more problems, one that then putting the field name in the initializedictionary( function needless, and the other is that I cannot figure out how to get a procedure to work on a different field.

I made a database with six line item fields from 1 to 6. I made the Qty1 field a Choice field with some choices, then I ran this code.

let choices = getdictionaryvalue(getfieldproperties("Qty1"),"CHOICES")
for item,2,6
    field "Qty"+item
    setfieldproperties initializedictionary(
        "CHOICES", choices
        "TYPE","Choice"
        )
endloop

This correctly made the other Qty fields into Choice fields with the same list as Qty1. Then I changed the list in Qty1 and ran the program again, it correctly updated the list for all of the Qty fields. (Note that in that case the line "TYPE","Choice" is not necessary since the fields are already that type, but it’s ok to leave it in also.)

There is no way to change the choice list of a field without making that field the current field (which is what the field statement does). Changing the choice list actually changes the data internally (it still looks the same, but the stored binary data is different), and that can only be done for the current field. Most properties can be changed for any field (this is new in 10.2), but a change that actually changes the data can only be done on the current field. I believe TYPE and CHOICES are the two options that are restricted to the current field.

Here is a revised version of this code that automatically figures out how many line items there are.

let itemfields = dbinfo("lineitemfields","")
let qtyfields = arraystrip(arrayfilter(itemfields,cr(),{?(import() match "Qty*",import(),"")}),cr())
let choices = getdictionaryvalue(getfieldproperties("Qty1"),"CHOICES")
for item,2,linecount(qtyfields)
    field "Qty"+item
    setfieldproperties initializedictionary(
        "CHOICES",choices,
        "TYPE","Choice"
        )
endloop

Of course you would need to change the field name from Qty to whatever your field name (I think for Bruce it was Time. Ok, here’s one more revision, that allows you to specify the target field name once, on the first line.

let itemfield = "Qty"
let itemfields = dbinfo("lineitemfields","")
let qtyfields = arraystrip(arrayfilter(itemfields,cr(),{?(import() match itemfield+"*",import(),"")}),cr())
let choices = getdictionaryvalue(getfieldproperties(itemfield+"1"),"CHOICES")
for item,2,linecount(qtyfields)
    field itemfield+item
    setfieldproperties initializedictionary(
        "CHOICES",choices,
        "TYPE","Choice"
        )
endloop

Since the title of this thread is Setting Line Item Field Properties, I should note a big improvement in how Panorama X handles formulas and code in line item fields. Just put any needed formulas and code in the first line item field, and leave the others blank. If you do that, Panorama will automatically use the formulas and code for all of the corresponding fields. So if you need to make a change to a formula or code, you’ll only have to do it in once place. This is documented on this help page, but I suspect that many of you have not noticed this change.

Thank you. I will try these out. In this case, I have several similar files that I will need to change, and I would like to automate it as much as possible.

Changing Line Item Field properties is also useful for the trick I explained earlier, using line items for the math, and changing the field titles for readability.

Perhaps I should clarify that there is nothing different about changing the properties of a line item field vs. any other field. The setfieldproperties statement doesn’t treat line item fields any differently than other fields, it doesn’t even recognize that a field is a line item field.

For some reason, I had to declare “choices” as a variable before your procedures would work.

It looks like I will have to make this into a custom function or statement.

The code I submitted already declares choices as a variable. That’s what the let statement does.

Also, I actually tried this code. Occassionally I will post code that I haven’t actually tried, but that wasn’t the case here. I tested this code before I uploaded it. So perhaps you retyped it and there was a typo?

It looks like I will have to make this into a custom function or statement.

It wouldn’t make any sense as a function.

It could make sense as a custom statement if you are planning to use it in a bunch of different databases. In that case I would probably modify it to use the current field as the itemfield, instead of hard coding the field name. You could check to make sure it was a line item field.

I copied and pasted. I thought that the let statement would do, but I got the error when I ran it. Maybe there is something hanging on from someplace else that was confusing Panorama. It is probably not a good idea to use common words as variables.