I have a interactive grid. If no rows selected I want to display a error msg as 'No records selected'. If more than 1 record selected then display 'select 1 record'. If 1 row selected then call a procedure. How can I achieve this using Java Script?
The error message should appear as inline notification.
I have tried this code. But this doesn't give correct error message. If I try clicking one record it is giving correct error msg then if I click one more record the error msg is incorrect. I mean whatever error I'm getting for first time I'm getting the same error always.
var gridView = apex.region("your-IG-static-id").widget().interactiveGrid("getViews").grid;
var records = gridView.getSelectedRecords();
var recs = records.length;
if (recs = 0) {apex.message.alert("No records selected")};
if (recs > 1) {apex.message.alert("Select 1 record")};
if (recs = 1) {
apex.server.process("CALL_YOUR_AJAX_PROCESS", {
x01: $v("PAGE_ITEM_1") ,// Parameters to pass to AJAX process if any
x02: $v("PAGE_ITEM_2") ,// Parameters to pass to AJAX process if any
}, {
//pageItems: ''
//dataType: 'text'
}).done(function (pData) {
console.log(pData);
});
};
Related
Initially I'm loading the ddl data using page_load and next I'm using the AJAX method and fetching the dependency data using Web Method so when I'm selecting the dependency data using `AJAX' the data is coming but the ddl is filling with previous loaded dll data I'm not sure what is the issue.
Here is my code and examples :-
Initially I'm loading the ddl data using page_load event
if (!IsPostBack)
{
firstexpdate = GetExpDates("nifty", "ce");
firststrikeprice = GetStrikePrice("nifty", firstexpdate);
lotsize = GetLotSizeVal("nifty", firstexpdate);
ltpprice = GetGreeksPrice("nifty", firstexpdate, "ce");
}
Like below I'm getting the ddl data.
And here "NIFTY" textbox is autocomplete textbox if I enter minLength: 3 this logic will execute and once enter the acc the autocomplete logic will fire and able to fetching the data from WebMethod and next I'm calling the AJAX method(because once we select the autocomplete textbox data the next ce,date,13500 ... controls data should fill autometically) for auto filling the data.
Here is how I calling the AJAX method logic
$(document).ready(function () {
//Initially I'm calling this function
autocomplete();
//Page load even I written because I used all control under the `updatepanel`
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function EndRequestHandler(sender, args) {
autocomplete();
}
});
function autocomplete() {
$("#search").autocomplete({
source: function (request, response) {
// my source logic is here and able to fetching the data successfully
//once I fetch all the symbols and next I'm calling this method
doSearch(suburbs); //Calling the Symbol Display Method{in this suburbs I'm filling the response data}
},
minLength: 3 //This is the Char length of inputTextBox
});
}
function doSearch(suburbs) {
//And here I written all my required logic and next I'm calling this method for auto fill data
//Like how I explained above query
var smbltext = $(this).text(); //Here will come `ACC` Symbol in autocomplete textbox
AutoFillUsingSymbol(smbltext); // Filling the dependency fields data
}
//This is the full logic of auto filling the controls once we select the`autocomplete`textbox data
function AutoFillUsingSymbol(symbol) {
if (symbol != '') {
var paramsmbl = { entredsmbl: symbol, selectedinstrument: $('#AutoTradeTop_Instrument option:selected').text()};
//alert(paramsmbl.entredsmbl);
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "AutoTrade.aspx/AutoFillData",
data: JSON.stringify(paramsmbl),
dataType: "json",
dataFilter: function (data) {
return data;
},
success: function (data) {
//Clearing before filling the data into ddl
$('#AutoTradeTop_expdate').empty();
$('#AutoTradeTop_strikeprice').empty();
$('#autotrade_lotsizeid').html('');
$('#LTPliveAmount').html('');
var length = data.d.length;
//data.d.each(function (index, element) {
//}
$.each(data.d, function (key, value) {
//alert(value);
if (value.indexOf("-") != -1) {
//alert(value + "date found");
$("#AutoTradeTop_expdate").append($("<option></option>").val(key).html(value));
}
else {
if (!(key == length - 2 || key == length - 1)) {
//alert(value + " value found ");
$("#AutoTradeTop_strikeprice").append($("<option></option>").val(key).html(value));
}
else {
if (key == length - 2) {
//alert(value + "LotSizeVal found");
$('#autotrade_lotsizeid').html(value);
}
else if (key == length - 1) {
//alert(value + "LTP Price found");
$('#LTPliveAmount').html(value);
}
}
}
});
},
error: function ajaxError(data) {
alert(data.status + ' : ' + data.statusText);
}
});
}
}
Once this AJAX logic hit AutoFillUsingSymbol(symbol) It will go to WebMehod logic and able to fetching the required data and filling into ddl list.
before filling into ddl data I'm clearing(emptying the dropdown list data) the ddl data and refilling
$('#AutoTradeTop_expdate').empty();
$('#AutoTradeTop_strikeprice').empty();
$('#autotrade_lotsizeid').html('');
$('#LTPliveAmount').html('');
Here is the example image of auto filling data once we select acc symbol and date is loading what I selected symbol acc
But if I select any one date the dropdown list data is clearing and filling the previous symbol data `nifty' see the above first image for reference.
example image
Note :- I know if we fill or change the dropdownlist client side code, then the list of values does not persist but initially I filled the ddl data in the page_load event and next I wrote the AJAX method but why the values are not loading properly.
Suggest me what is the issue and where I did the mistake
I'm beginner in the client side code development .
I have Oracle APEX 4. I created a tabular form manually (with the apex_item package). It contains three fields.
apex_application.g_f03: LOV (select name display, product_id return from products)
apex_application.g_f04: text field "price"
apex_application.g_f05: text field "quantity".
I would like to see the price of the product in f04 after choosing a product name (...f03). The SQL statement is like this:
select price from products where product_id = {..from f03}.
How to do it with dynamic action or javascript function?
OK, I will give you a hint how to implement your scenario.
Things you need are to make it work:
custom tabular for - you already have it
on demand process that fetchs price of the product from db
dynamic action to listen if value in f03 changed
on demand process
Create on demand process named getPrice with following code
declare
v_price number;
begin
select
price
into
v_price
from
products
where
product_id = apex_application.g_x01;
htp.p( v_price );
exception
when others then
htp.p(SQLERRM);
end;
dynamic action
You have to listen event change on jQuery selector :input[name=f03]. Create dynamic action with true action Execute JavaScript Code.
Within true action you have to do ajax call to on demand process. The example code (working) is below:
var
xhr2,
self = $(this.triggeringElement),
productId = self.val(),
row = self.closest('tr');
xhr = $.ajax({
url:'wwv_flow.show',
type:'post',
dataType: 'text',
traditional: true,
data: {
p_request: "APPLICATION_PROCESS=getPrice",
p_flow_id: $v('pFlowId'),
p_flow_step_id: $v('pFlowStepId'),
p_instance: $v('pInstance'),
//p_arg_names: [ item_id ],
//p_arg_values: [ itemValue ],
x01: productId
},
success: function( resultData, textStatus, ajaxObj ){
//do stuff after fetching product price
row.find( ':input[name=f04]' ).val( resultData )
},
error: function(jqXHR, textStatus, errorThrown){
alert('Error occured while retrieving AJAX data: '+textStatus+"\n"+errorThrown);
}
});
Put the stuff together and you will have answer to your question.
Ps.
Don't forget to mark answer as helpfull if it is answer to your question.
I am using Jtable for booking events. In combination with PHP, MySQL. My question is, is there a way to just reload every 10 second single column. Precisely I have something like this:
Checkbox ID Event Reservations
+ 4 ev1 22
- 5 ev2 19
I would like to have the reservations column reloaded every 10 seconds, so the user that is logged in can see the changes. Now I got it working with reloading the whole table, but this is not what I really need because every user can book only 9 events and I need to have checkboxes at the left side. After reloading the whole table my checkboxes are not working as expected. So is there a way to reload just one column? My code right now is:
window.setInterval(function(){
$('#Events').jtable('reload');
}, 10000);
Any help or suggestion would be appreciated.
I found a way around how to solve it:
First create a new field in JS like this:
test: {
title: 'test',
display: function (data) {
var $div = $('<div id="test"">'+data.record.id+'</div>');
return $div;
}
},
Than create a function that will be run every 10 seconds and make an AJAX request:
function UpdateRes(){
$.ajax({
url: 'Actions.php?action=update',
type: 'post',
data: '&kiu='+$kiu,
}).success(function(data) {
var jsondata = JSON.parse(data);
$.each(jsondata.Records, function(i, item) {
$('.jtable tr.jtable-data-row').each(function(){
if($(this).attr('data-record-key')==item.id){
$(this).find('div').html( item.reservations );
}
})
});
});
}
window.setInterval(function(){
UpdateRes();
}, 10000);
Let your JSON response look like this:
{"Result":"OK",
"Records":
[
{"0":"111","id":"111","1":"20","reservations":"20"},
{"0":"127","id":"127","1":"20","reservations":"20"},
{"0":"133","id":"133","1":"20","reservations":"20"},
{"0":"134","id":"134","1":"20","reservations":"20"},
{"0":"135","id":"135","1":"20","reservations":"20"},
{"0":"326","id":"326","1":"20","reservations":"20"}
]}
And in the end in Actions.php make your query in try catch:
else if($_GET["action"] == "update")
{
//Get records from database
$result8 = mysqli_query($con,
"SELECT l.id,(l.max-l.reserviert) as reservations
FROM td_res l WHERE
l.kiu='" . mysqli_real_escape_string($con,$_POST["kiu"]) . "';");
//Add all records to an array
$rows8 = array();
while($row8 = mysqli_fetch_array($result8))
{
$rows8[] = $row8;
}
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
$jTableResult['Records'] = $rows8;
print json_encode($jTableResult);
}
I have an ajax table that reads data from two mysql tables, the tables are
project_ownerships - id_own, project, code, own_current, own_future
projects - id, project, location, type, type2, area, transport, stage
the data reads into the web page table fine, using a join table sql query.
$query_value = isset($_GET['value']) ? $_GET['value'] : "";
$sql = "SELECT project_ownerships.*, projects.*
FROM project_ownerships, projects
WHERE project_ownerships.project = projects.project
AND project_ownerships.code = $query_value'";
$result = $mysqli->query($sql);
however I can't get the edit update working properly. I am only able to get a data - id value from one db-table.
so any updates that belong to projects table update fine, but any updates to project_ownerships do not have the correct id value and update the wrong db-record
here's the update function. this function returns the error "column not found with index or name id_own"
$.ajax({
url: 'update_multi.php',
type: 'POST',
dataType: "html",
data: {
tablename: editableGrid.getColumnName(columnIndex) == "own_current" ? "project_ownerships" : "projects",
id: editableGrid.getColumnName(columnIndex) == "own_current" ? editableGrid.getValueAt(rowIndex, editableGrid.getColumn("id_own")) : editableGrid.getRowId(rowIndex),
newvalue: editableGrid.getColumnType(columnIndex) == "boolean" ? (newValue ? 1 : 0) : newValue,
colname: editableGrid.getColumnName(columnIndex),
coltype: editableGrid.getColumnType(columnIndex)
},
success: function (...,
error: function(...,
async: true
});
here's the php update
$tablename = $mysqli->real_escape_string(strip_tags($_POST['tablename']));
$id = $mysqli->real_escape_string(strip_tags($_POST['id']));
$value = $mysqli->real_escape_string($_POST['newvalue']);
$colname = $mysqli->real_escape_string(strip_tags($_POST['colname']));
$coltype = $mysqli->real_escape_string(strip_tags($_POST['coltype']));
$id_column = "";
if ($tablename == "projects") {$id_column = "id";} else {$id_column = "id_own";}
if ( $stmt = $mysqli->prepare("UPDATE ".$tablename." SET ".$colname." = ? WHERE ".$id_column." = ?")) {
$stmt->bind_param("si",$value, $id);
$return = $stmt->execute();
$stmt->close();
}
basically what I am trying to do....
if projects.id is removed from the sql the update will not work
if project_ownership.id_own is changed to project_ownership.id and projects.id is removed the update will work, but only with project_ownership.* fields
so... I need a column in the sql query called *.id
separately, when an update is sent, the correct table name can be selected by
tablename: editableGrid.getColumnName(columnIndex) == "own_current" ? "project_ownerships" : "projects",
so using the same logic
id: editableGrid.getColumnName(columnIndex) == "own_current" ? editableGrid.getValueAt(rowIndex, editableGrid.getColumn("id_own")) : editableGrid.getRowId(rowIndex),
firstly, recognises that own_current is there, and passes the argument to editableGrid.getValueAt(rowIndex, editableGrid.getColumn("id_own")) but the error returned is "no column found with the id_own name"... ?
I am really confused..
it cannot not be there (removed from the sql) otherwise the update just freezes
but when it is there it cannot be found...
any help would be great
how is it possible to define the ajax - data - id column or the rowIndex column ?
I am working on the theory that
editableGrid.getRowId(rowIndex)
could be the something like (which it's obviously not otherwise this would work)
editableGrid.getValueAt(rowIndex, editableGrid.getColumn("id_own"))
but I have also tried, amongst others
editableGrid.getValueAt(rowIndex, editableGrid.getColumnIndex("id_own"))
which returns "invalid column index -1"
and
editableGrid.getValueAt(rowIndex, editableGrid.getColumnName("id_own"))
UPDATE
there's a couple private functions in editablegrid that define what row id is. so I guess that makes it an editablegrid question and not really a javascript, ajax, or php question suitable for here
You should rename "id" column of each table in your SQL query with AS operator so they dont conflict.
For example :
SELECT B.*,A.name,A.id as author_id FROM BOOKS B
INNER JOIN AUTHORS A ON A.id=B.authorid
I have created a custom entity called Alert. I have associated this with the out of the box Account entity.
What I want to do now is to customise the Account form so that when a user opens it, it checks if the current account has any active alerts. If it does, it should show a message informing them of this (a javascript alert?) and then navigate to the alerts view for the account.
I've done some basic javascript in CRM but I'm not sure how to query related entities.
Note Active alert is defined by the Display From and Display Until dates in the Alert being active dates (Display From <= Today AND Display Until >= Today).
Update
Thanks for pointing me in the direction of oData. I now have the following function which is looking up the account set but expanding the relationship with the alerts. I'm trying to figure out how to check if there are any alerts, currently my code always triggers the javascript alert.
function CheckForAlerts(accountId)
{
var odataSelect = "http://mscrmdev/Test/xrmservices/2011/OrganizationData.svc/AccountSet?$expand=new_account_new_alert_Account&$filter=AccountNumber eq '" + accountId + "'";
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: odataSelect,
beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
success: function (data, textStatus, XmlHttpRequest)
{
// Use only one of these two methods
// Use for a selection that may return multiple entities
ProcessReturnedEntities(data.d.results);
},
error: function (XmlHttpRequest, textStatus, errorThrown) { alert('OData Select Failed: ' + odataSelect); }
});
}
function ProcessReturnedEntities(ManyEntities)
{
var oneEntity = ManyEntities[0];
if (oneEntity != null)
{
alert('There are active alerts associated with this account.');
}
}
The best way to do this will be via an oData query from the javascript. The CRM 2011 SDK comes with some helper functions for oData calls like this. You will want to use the 'retrieveMultiple' method which will allow you to retrieve all 'alerts' with a lookup to the 'account' in question.
First add the 'RESTJQueryEditor.js' file from the SDK to your form and then you can add your own custom script to perform the retrieve. I then suggest creating the message which you wish to show the user in the callback success function, something like the following:-
retrieveMultiple('nameOfYourAlertEntitySet', '?$filter=myAccountLookupName eq ' + accountId, function(alerts){
if(alerts.length > 0)
{
var message = '';
for(var index = 0; index<alerts.length; index++)
{
message += 'alert: ' + alerts[index].name;
}
alert('Found associated alerts: ' + message);
}
else
{
alert('No associated alerts found for this account');
}
},
function(){
// Log an exception
});
You will want to make the alert message a little nicer of course and adjust your attribute names accordingly, but this is the flavour of what you want to do I believe. Additionally, you can add any further criteria on the alert entity in the filter by use of the 'and' keyword.
Let me know if you have any issues.