ProductCode auto generator

Hi, i have a question about the forms and loading data for multiple Tables
I need to create a ProductCode in my form, in this form there are 3 fields of 3 diferent tables, the Category, Client and Brand, you can set the value through a combo box, linked to their respective tables.

The ProductCode would be something like this:
###-CatCode-#-ClientCode-BrandCode-xxxx

where:
CatCode is the code for the selected Category
ClientCode is the code for the selected Client
BrandCode is the code for the selected Brand
The # is introduced in a text field
The xxxx are the consecutive for each client

A preview

I tried with the option to reload With AjaxI but I can not make this work properly

Thanks for help :wink:

Hi all, I solved my problem after lot trying, put an Ajax event ONChange on each field than i need to monitored, something like this:

sc_lookup(dataset, "SELECT catcode FROM tabla1 WHERE catid = '{category}'");
[catcode] = {dataset[0][0]};
{productcode} = [code1].[catcodet].[code2]...;

with the consecutive, i put this code on clien onChange event:

sc_lookup(conset, 
		  "SELECT COUNT(cliente) FROM tabla2
		  WHERE client = '{client}'");

$aux = {conset[0][0]} + 1;

{C_CodOrden} = [C_CodOrden]."-"."$aux";

i hope this help someone, bye

question.png

Not sure why it doesnt work. As I understand it, you set the first field then this will trigger the list in the second drop down and if that changes it triggers the last field? I think you should start by using the title option and add ‘select…’ to the list. The problem is that if you start up your form there’s no onchange event triggered on the first item. After that you need to use the correct sql (use the pre-selected value of the above dropdown) and select the ajax refresh on the above dropdown. That should do it.

I think you can create a new function php with the script for generate the code of ProductCode.
And this function you must call it from ONLOAD EVENT, and Events Ajax onchange for each field.

Well… thanks for the suggestions, i used the onChange event on each field and it started to work, but i have a problem with the consecutive, I’m trying something like this:

while(!EOF){
sc_exec_sql("select count(*) from table where field=’{some_column}’
}

But don’t works