In the Oracle APEX 19.1 documentation for JS API, it is mentioned that we can pass column Items in apex.server.process. How do we use that?
Im trying to send column item value to ajax callback function using apex.server.process
I tried the below codes
apex.server.process("ajax_1", { pageItems: ["ENAME"] }, {
target: $("#EMP"), dataType: "text", success: function (pData) {
alert(pData);
}
});
And
apex.server.process("ajax_1", { pageItems: ["ENAME"] }, {
target: "#EMP", dataType: "text", success: function (pData) {
alert(pData);
}
});
The grid has Static ID: EMP and has a column with name : ENAME and Static Id : ENAME
And in the Ajax Callback Process (PLSQL)
BEGIN
htp.prn('ENAME : ' ||:ENAME);
END;
I get the following error
ERR-1002 Unable to find item ID for item "ENAME" in application "XXXXX"
Please help.
In your Ajax Callback Process, you need to access the variables with the Syntax apex_application.g_x01 to apex_application.g_x10.
See https://docs.oracle.com/cd/E59726_01/doc.50/e39149/apex_app.htm#AEAPI214 for details and a small example.
I am late, but since I had the same question, I wanted to submit the answer.
If your Javascript looks like this:
apex.server.process("test_ajax_variable",
{
x01: "Test",
pageItems: "#P13_ITEM"
},
{
dataType: 'text'
});
You can access the variables in an APEX Process like so:
DECLARE
l_test VARCHAR2(100);
BEGIN
l_test := apex_application.g_x01 || ', ' || :P13_ITEM;
htp.p(l_test);
END;
I might be very late at this point, but I believe I understand the solution to your problem. In your JS code you'd first have to define a view and a model. There are multiple ways to do this, I personally went with calling getCurrentView upon the Interactive Grid widget (method call("getCurrentView") is short for widget().interactiveGrid("getCurrentView"):
var view = apex.region("static-id-of-your-IG").call("getCurrentView");
var model = view.model;
From there you can perform a numerous amount of methods (listed here) depending on what your actual needs are: do you want to send all of your records to APEX processing, do you want to send only selected ones etc.
Let's say you only have one record and only one specific column value you'd like to pass. You'd assign a new variable following the view and model definition:
var name = model.getValue( someRecord, "ENAME" );
or as the documentation states, omit the record when the model shape is record itself as it is in your case:
var name = model.getValue( "ENAME" );
Now that you got the value, in your APEX server process you can pass the name variable as an apex_application.g_x01 parameter:
apex.server.process("your-ajax-process-name",
{
x01: name,
},
{
dataType: "text"
}
)
And as mentioned in earlier answers, you would now be able to access the value in your AJAX Callback process like this:
DECLARE
l_test VARCHAR2(100);
BEGIN
l_test := apex_application.g_x01;
htp.p(l_test);
END;
Related
Following the tutorial, there is the query
query selectCommoditiesByOwner {
description: "Select all commodities based on their owner"
statement:
SELECT org.acme.biznet.Commodity
WHERE (owner == _$owner)
}
But nowhere is an example explaining how to request it
For the parameter owner, I tryed with the node variable owner
owner.toUri()
owner.getFullyQualifiedIdentifier()
"resource:" + owner.getFullyQualifiedIdentifier()
But nothing works
Does somebody has a working example?
Example on how to 'request it' is shown in the REST API section of the Queries tutorial https://hyperledger.github.io/composer/tutorials/queries
If you mean: request it from within a Transaction Processor function, using the APIs - there is an example in the same tutorial, of calling a Query function eg.
/**
* Remove all high volume commodities
* #param {org.acme.biznet.RemoveHighQuantityCommodities} remove - the remove to be processed
* #transaction
*/
function removeHighQuantityCommodities(remove) {
return getAssetRegistry('org.acme.biznet.Commodity')
.then(function (assetRegistry) {
return query('selectCommoditiesWithHighQuantity')
.then(function (results) {
// process results objects etc
so using your query - you might do something like:
var tx_owner = tx.owner; // passed into the Transaction Processor for example
return query('selectCommoditiesByOwner', {
"owner": tx_owner // eg "resource:org.acme.trading.Trader#trader1"
})
.then(function (results) {
// do something
hope this helps. See further reference here -> https://hyperledger.github.io/composer//reference/query-language
I am not able to display records on my report.
Report Source: Group Approval(sysapproval_group) table
Condition:Sys Id - is one of - javascript: new GetMyGroupApprovals().getSysIds();
Script Include : MyGroupApproval
Note : Active is checked, Accesible is all application score & Client callable unchecked
var GetMyGroupApprovals = Class.create();
GetMyGroupApprovals.prototype = {
initialize: function() {
},
getSysIds : function getMyGroupMembers(){
var ga = new GlideRecord('sysapproval_group');
ga.addQuery('parent.sys_class_name', '=', 'change_request');
ga.query();
gs.log("TotalRecords1 Before:: " + ga.getRowCount());
var sysIdArray = [];
while(ga.next()){
sysIdArray.push(ga.sys_id);
}
return sysIdArray;
},
type: 'GetMyGroupApprovals'
};
Kindly note that I have to achieve with script approach. I am not able to get records on my report.
This line is probably causing unexpected behavior:
sysIdArray.push(ga.sys_id);
ga.sys_id returns a GlideElement object, which changes for each of the iterations in the GlideRecord, so the contents of sysIdArray will just be an instance of the same object for each row in the result set, but the value will just be the last row in the set.
You need to make sure you push a string to the array by using one of the following methods:
sysIdArray.push(ga.sys_id+''); // implicitly call toString
sysIdArray.push(ga.getValue('sys_id')); // return string value
Quick suggestion, you can use the following to get sys_ids as well:
sysIdArray.push(ga.getUniqueValue());
When I create a new item in the server-side using a Kendo UI data source, how do I update the ID of the client-side data item with the ID of the new record inserted in the database in the server-side?
Doing more research I have found this extremely useful information which, indeed, should be in the docs, but it is "hidden" in a not-so-easy-to-find forum search message:
http://www.kendoui.com/forums/ui/grid/refresh-grid-after-datasource-sync.aspx#2124402
I am not sure if this is the best approach, but it resolved my problem!
This solution simply uses the data source read method to update the model instances with data from server.
The precious info is where it is done: in the "complete" event of the transport.create object!
Here is the code:
transport: {
read: {
url: "http://myurl.json"
},
create: {
url: "http://mycreate.json",
type: "POST",
complete: function(e) {
$("#grid").data("kendoGrid").dataSource.read();
}
},
To avoid the additional server call introduced by the read method, if you have your create method return an object the Data Source will automaticly insert it for you.
Knowing that all you need to do is set the id field from the database and return the model.
e.g. psudo code for ASP MVC action for create.
public JsonResult CreateNewRow(RowModel rowModel)
{
// rowModel.id will be defaulted to 0
// save row to server and get new id back
var newId = SaveRowToServer(rowModel);
// set new id to model
rowModel.id = newId;
return Json(rowModel);
}
I've had the same problem and think I may have found the answer. If in the schema you define the object that holds the results, you must return the result of the created link in that same object. Example:
schema: {
data: "Results",
total: "ResultsCount", ....
}
Example MVC method:
public JsonResult CreateNewRow(RowModel rowModel)
{
// rowModel.id will be defaulted to 0
// save row to server and get new id back
var newId = SaveRowToServer(rowModel);
// set new id to model
rowModel.id = newId;
return Json(new {Results = new[] {rowModel}});
}
Just to add to Jack's answer (I don't have the reputation to comment), if your Create and Update actions return data with the same schema as defined in the kendo DataSource, the DataSource will automatically update the Id field as well as any other fields that may have been modified by the action call. You don't have to do anything other that form your results correctly. I use this feature to calculate a bunch of stuff on the server side and present the client with the results w/o requiring a complete reload of the data.
Here is the method I'm calling:
public Bear GetBear(int bearId)
{
MyEntities be = new MyEntities ();
Location bear = (from b in be.Bears
where b.id == bearId
select b).First();
return bear;
}
Here is how I call it:
$.ajax({ url: "Bear/GetBear", data: { bearId: 2}, success: function (bear) { alert(bear.id) } })
But, the text in the alerted dialog box is undefined. And when I'm moving through GetBear with breakpoint, the returned bear HAS id. What am I doing wrong?
You can change your $.ajax call specifying your contentType to JSON.
Also, take a look in this article, it shows exactly what you're looking for.
http://encosia.com/using-jquery-to-consume-aspnet-json-web-services/
Also, note that in this article he uses msg.d to get the json.
Shouldn't you convert the data into json/xml/text/dataType (http://api.jquery.com/jQuery.ajax) before sending it back?
Suppose in the database there is one table (for example student records) with a number of columns, but my HTML page only displays a few of them. For example: a table having the columns sno, sname, addr, age, dept, and dob and my page having only 3 fields: sno, sname, dept. Here I display the dept field in a combo box control and the rest of the fields are text and empty values.
My requirement is: when I select the dept from combobox the corresponding row vlaues like sno and sname have to display automatically in the text fields. How can I do this?
You make an ajax call to your server when you change the department. Your server returns your object as JSON. Your success handler in your ajax call takes the fields it needs from your JSON object and sets the appropriate html elements to those fields. For example, if you're using jQuery:
var myUrl = "http://some.domain/action/";
var success = function(response) {
$('#textField1').val(response.sno);
$('#textField2').val(response.sname);
}
$('#myDropDown').change(function() {
$.get(myUrl + $(this).val(), success);
});
If you don't want to send back all the properties of your object because you want to minimize bandwidth, you can form your own JSON object, but that's kind of a pain in the neck and if your object is not huge you might as well use whatever JSON serializer is available in the framework you're using and just serialize the object and send it through the wire.
Or here's another option. You could just make one initial AJAX call and then create a map from department to the other fields you want to set. Example:
var map = {};
var success = function(response) {
for (obj in response.objects) {
map[obj.department] = { sno: obj.sno, sname: obj.sname };
}
}
$.get(myUrl, success);
$('#myDropDown').change(function() {
var obj = map[$(this).val()];
$('#textField1').val(obj.sno);
$('#textField2').val(obj.sname);
}
Hope that helps.