No announcement yet.

Ajax processing

  • Filter
  • Time
  • Show
Clear All
new posts

  • Ajax processing

    i have applied this example from SC channel in order to change the value of a field when another is selected.

    in my case the master table is drug_category while the child table is drug.

    of course they are in to separate tables and there is a foreign key in the drug table referring drug_category table.

    the ajax processing works and in the application the user correctly sees the name of the drugs or the category whan one or the other is selected, the problem is that in the DB for the dug_category is written the id of the drug_category. i want that in the db is written the actual name of the drug_category, not its id.

    in my form in the field category i have:

    SELECT iddrug_category , drug_category
    FROM drug_category
    ORDER BY drug_category

    in this field i have enabled ajax processing

    in the other (drug) i have:

    SELECT drug, drug
    FROM drug
    WHERE iddrug_category = '{category}'
    ORDER BY farmaco

    is that possible?
    Thank you

  • #2
    Do you really need the name of the drug_category in the drug table or you need to want to run some query (grid app) on the drug table and need the name also? If so the easiest thing would be to define a view at the database level and make your grid based on that view and not the drug table.

    ​If you must have the drug_category name in the drug table, you can alter the drug table to have a drug name field (same size as category table) and then in the onBeforeInsert/ onBeforeUpdate event of the form, sc_lookup(rs, "SELECT drug_name FROM drug_category WHERE iddrug_category = {iddrug_category}"); {drug_name} = {rs[0][0]};


    • #3
      i know i have not been clear at first.

      The form where the Ajax processing is going on is called therapy and is based on table therapy. I want drug_category to be written with its name in table therapy. Then eventually I will set a grid of the therapy table.

      i use drug_category and drug tables only for ajax processing in the therapy form where there is a drug_category field and a drug field.

      Now, in the DB (therapy table) it writes the actual name of the drug for the drug field, but in the drug category (always therapy table) it writes the drug_category id instead of the drug_category name.

      Last edited by mhanu70; 05-19-2016, 06:02 AM.