Hello. I would need to dynamically read a value on the add page. When I change the value of a db field (which uses look up table) I should launch a query and insert the result into a custom field. This dynamically every time I change value in the field.
eg:
TableA
FieldA-> changevalue-> runQuery → $myResult = (select ifnull (sum (myTableB.FieldB), 0) from myTableB where myTableB.id = myothertable.id)
put $myResult in to TableA CutomFieldCShould I use client side event for this?{// keys = event types, values = handler functions
“change”: function (e) {
// Your code
}
}
In your onchange event, you can do Ajax to query the database and get the value, see the topic Lookup Table > Ajax by API and Client Scripts in the help file.
i tried this and it works because this table is in lookup in the search field.
x_CutomFieldValue->lookup table-> “TableA
$(”#x_CutomFieldValue").change(function() {
var object = “TableA”, data = { “action”: “view”, “object”: object, “idTableA”:
encodeURIComponent($(“#x_OtherCutomFieldValue”).val()) };//search value match obyect
var res = ew.ajax(data);
if (res && res.success) {
var row = res[object];
$(“#x_Field”).val(row[“Value”]);
}
});But if I use a different table it doesn’t work. The table where I get the value is not in the lookup table of the x_CutomFieldValue field$(“#x_CutomFieldValue”).change(function() {
var object = “TableB”, data = { “action”: “view”, “object”: object, “idTableB”:
encodeURIComponent($(“#x_OtherCutomFieldValue”).val()) };//search value match obyect
var res = ew.ajax(data);
if (res && res.success) {
var row = res[object];
$(“#x_Field”).val(row[“Value”]);
}
});
the problem is not in the different table but it seems to be a view table
var object = “viewtable”,… (does not get data)
why?
View is same as table, make sure the view is selected to generate or there is no class is generated for the view.
the classes exist and are generate. I’ve same problem with all view, but only whit views. The name of field are same. I’ve cheked it from
function Row_Rendered() {
// To view properties of field class, use:
var_dump($this->field);
}object is correct but don’t works. When I change field (onchange) I see the icon run, but not get value from view table.
if I change the name of the object with that of the table (not the view) it works
So works fine
// saldoclienti → is an a view table
//global userfn.php
// Get values form saldo clienti API Ayax
$API_ACTIONS[“getSaldo”] = function(Request $request, Response $response) {
$idCl = Param(“idCl”); // Get the input value from $GET or $POST
$idCl = AdjustSql($idCl);
if ($idCl !== NULL)
Write(ExecuteScalar(“SELECT Saldo FROM saldoclienti WHERE idCliente = $idCl”)); // Output field value as string
};// Startup script
$(“#x_idCampagna”).change(function() {
var url = ew.API_URL, action = “getSaldo”, id = encodeURIComponent(“2”);//$(this).val()
$.get(url + “?action=” + action + “&idCl=” + id, function(res) {
if (res)
$(“#x_Importo”).val(res);
});
});So it doesn’t work why?//start up script
$(“#x_idCampagna”).change(function() {
var object = " saldoclienti", data = { “action”: “view”, “object”: object, “idCliente”:
encodeURIComponent(“2”) };//match to object //$(this).val()
var res = ew.ajax(data);
//ew.ajax(data, function(res) {
if (res && res.success) {
var row = res[object];
$(“#x_Importo”).val(row[“Saldo”]); // Set the result
}
//});//
});
and how can I send multiple parameters for the query in Ajax?
Eg:
Write(ExecuteScalar("SELECT Saldo FROM saldoclienti WHERE idCliente = $idCl && idCampapagna = $idCa ")); // Output field value as string
In the first case, you execute the SQL yourself.In the second case, you use the REST API, then you need to make sure the user has “View” permission to the table/view “saldoclienti”. (There is also an extra space before “saldoclienti”.)
Sorry but the view table don’t have (all view by default) a class of view…only a _list.php. How can I use it with REST API object “view”?
ok now I understand that you have to select the view in table settings to generate it. Thanks