Hello all,
I'm working on a little project that requires addition of one extra filed to a few tables. Additionally, the new field needs a simple lookup definition. I would like to accomplish that in a XBasic to simplify the deployment.
The only information I have found on this topic is here:
http://msgboard.alphasoftware.com/al...-Rule-W-xbasic
Thanks to Stan Mathew's reply I was able to come up with this code:
Unfortunately it doesn't work. I'm getting an error that the 'rul.column_name.lookup' property does not exist. However when I try this code in the interactive window I'm able to add the lookup rule successfully:
Can anybody explain why does it work in the interactive window, but doesn't inside the function? What is missing in that function to make it work?
Any help is greatly appreciated!
Thanks,
Jarek
I'm working on a little project that requires addition of one extra filed to a few tables. Additionally, the new field needs a simple lookup definition. I would like to accomplish that in a XBasic to simplify the deployment.
The only information I have found on this topic is here:
http://msgboard.alphasoftware.com/al...-Rule-W-xbasic
Thanks to Stan Mathew's reply I was able to come up with this code:
Code:
FUNCTION update_table AS C (tn as C, prefix as C ) on error goto error_handler 'create new columns dim fields as C ='' fields = prefix +"_tax_type,c,4"+crlf() fields = fields+ prefix +"_tax_value,n,15,2" table.Add_Fields(tn,fields) 'set the lookup rule to tax_type dim rul as P dim t as P dim fType as P dim fGST as p dim fValue as p dim frul as P t = table.open(tn) rul = t.rules_get() rul.change_begin() eval( "rul." + prefix+"_tax_type.lookup.Type = "+s_quote("Table")) rul.change_end(.t.) rul.change_begin() eval( "rul." + prefix+"_tax_type.lookup.table_list.insert()") eval( "rul." + prefix+"_tax_type.lookup.Table = "+s_quote("lookup_tax.dbf")) eval( "rul." + prefix+"_tax_type.lookup.link = "+s_quote("Id")) rul.change_end(.t.) frul.table_list.insert() temp = frul.table_list.[1] temp.Condition = "" temp.Display = "No" temp.Fill = prefix +"_tax_type" temp.Source = "Id" temp.Width = 4 frul.table_list.insert() temp = frul.table_list.[2] temp.Condition = "" temp.Display = "Yes" temp.Fill = "" temp.Source = "Name" temp.Width = 10 t.close() error_handler: err = error_code_get() msg = error_text_get(err) ui_msg_box("Error", msg) t.close() end END FUNCTION
Code:
t = table.open('table_name') rul = t.rules_get() rul.change_begin() rul.col_name.lookup.Type = "Table" rul.col_name.lookup.Table ="My_Lookup_table" rul.col_name.lookup.Link "ID"; rul.change_end(.t.) rul.col_name.lookup.table_list.insert() rul.col_name.lookup.table_list.[1].Source = "Name" rul.col_name.lookup.table_list.[1].Display = "Yes"
Any help is greatly appreciated!
Thanks,
Jarek
Comment