I am creating a desk reservation application in apex, I have a page to select the date and time for a specific desk and I have an apply button to run the plsql code to insert the data in the reservation table in the db. Now, I want to validate if for the selected desk there is not any other reservation in the same date and in the same time range, then the reservation will be booked.I have created a hidden page item as a flag, and then 2 true actions before the action of inserting data:
first true action : Execute Server Side code
BEGIN
:P6_DUPLICATE_FLAG := 'N';
FOR ITEM in (SELECT TIME_TO FROM WPB_RESERVATIONS WHERE RESERVATION_DATE =
:P6_RESERVATION_DATE
AND LOC_ID = :P6_LOC_ID
AND ROOM_ID = :P6_ROOM_ID
AND WORKPLACE_ID =
:P6_WORKPLACE_ID)
LOOP
IF ITEM.TIME_TO > :P6_TIME_FROM THEN
:P6_DUPLICATE_FLAG := 'Y' ;
END IF;
END LOOP;
END;
and the second true action :Execute java-script code
// First clear the errors
apex.message.clearErrors();
var errorFlag= $v('P6_DUPLICATE_FLAG');
if(errorFlag == 'Y') {
// Now show new errors
apex.message.showErrors([
{
type: "error",
location: [ "page", "inline" ],
message: "There is a reservation for this desk in selected time!",
unsafe: false
}
]);
//To stop the further actions from firing
apex.da.cancelEvent.call(this);
}
the problem is I get different errors when pressing the apply buttun even the date is correct and I am sure it is not duplicated.
before adding this validation everything worked ok.
Am I doing something wrong?
IS there any other way to do this validation?
Related
I am new to Apex Oracle and PL/SQL, trying to validate radio input from the user
Declare
begin
if :R_button = 'NO' then
:Page_comment != NULL;
end if;
end;
There are three options available, YES, NO, and N/A. if the user selects No then it should prompt a comment. how best should i achieve this?
Here's one option.
you already have a radio button (R_BUTTON)
let's suppose that return values are
Y for "Yes"
N for "No"
A for "N/A"
create a dynamic action on the radio button
When:
Event = change
Selection type = item
Item = R_BUTTON
Client-side condition - set it so that DA fires when radio button value is N/A
Type: Item = Value
Item: R_BUTTON
Value = A
True action
Action = execute JavaScript code
Code = apex.message.showPageSuccess("N/A has been chosen");
Affected elements: type = item
item = R_BUTTON
That's all. Run the page and test how it works.
This test has been made on current apex.oracle.com version (19.2):
I have Insert statement that should return Auto Increment column value. Here is example of my insert:
myQuery = new query();
myQuery.name = "insertRec";
myQuery.setDatasource("db");
mySQL = "
INSERT INTO myTable (
First, Last, Email, ActionDate
)VALUES(
:first, :last, :email, :actiondt
)
";
myQuery.setSQL(mySQL);
myQuery.addParam(name="first", cfsqltype="cf_sql_varchar", value="#trim(form.first)#", maxlength="50");
myQuery.addParam(name="last", cfsqltype="cf_sql_varchar", value="#trim(form.last)#", maxlength="50");
myQuery.addParam(name="email", cfsqltype="cf_sql_varchar", value="#trim(form.email)#", maxlength="320");
myQuery.addParam(name="actiondt", cfsqltype="cf_sql_timestamp", value="#now()#");
myQuery.execute().getResult();
//result = myQuery.execute().getResult(); This line is commented because I was getting error message that test variable is not defined. Not sure why since test is declared and equals to myQuery.execute().getResult();
After I run this code record will appear in the table. Result set looks like this:
RecordID First Last Email ActionDt
7 John Woss jwoss#gmail.com 16-NOV-18
As you can see RecordID (auto increments) is there. I would like to get that value once myQuery is completed. How to achieve that?
As outlined in https://stackoverflow.com/a/34894454/432681, you can retrieve the auto-incremented ID via a SELECT on the related sequence.
So, your query should look something like this:
mySQL = "
INSERT INTO myTable (
First, Last, Email, ActionDate
)VALUES(
:first, :last, :email, :actiondt
);
SELECT "sequenceForMyTable".currval from dual;
";
How to get the name of the sequence is also described in the linked answer above.
There's a second way outlined in https://stackoverflow.com/a/25268870/432681 and also mentioned in the CFML documentation, which says that you may use the getPrefix() function to be able to access the generated key. Note that in this case result is the object returned by the execute() method, not the getResult() (because the query doesn't return a result set). So for your example this is how you can get the ID:
result = myQuery.execute();
newID = result.getPrefix().generatedKey;
I am trying to make a page in my website where I want to use this select2 (http://ivaynberg.github.io/select2/) plugin. My requirement is to include same "words" multiple times.
My tags could be:
Monthly_Rent, Monthly_Rent, commission, mortgage, commission
Also when user loads the page, I want to maintain the order how user selected it before saving.
Currently when I add any option, its removed from the list. How can I add it again?
Another issue is, now if I want to remove "commission" which is before "mortgage", it should not delete another "commission" word which is at last.
Please help me understand how to achieve this.
just use a counter and a query function to provide data :
var fruits = ['apple', 'pear', 'orange', 'strawberry']
var counter = 0
$("#yourinput").select2({
query: function(query) {
var data = { results: []};
for (var i = 0; i < fruits.length; i++) {
data.results.push({"id": fruits[i] + "/" + counter, "text": fuits[i]});
}
counter += 1;
query.callback(data);
},
formatSelection: function(item) {
return item.text; // display apple, pear, ...
},
formatResult: function(item) {
return item.id; // display apple/1, pear/2, ... Return item.text to see apple, pear, ...
},
multiple: true,
closeOnSelect: true
}
So, the first time you click on your select box, the data are initialized with apple/1, pear/1, ... The next time, you get apple/2, pear/2, ..., next apple/3, ... and so on.
Each time you select a fruit, you get an different id, even you choose same fruit you have previously chosen. Keeping an unique counter you increment at each select allow you to delete a fruit without side effect : its id disappeared, and will not be reused.
closeOnSelect is set to true, to increment counter at each selection (more precisely, each time you open the select box). If you set it to false, when you select a fruit, it disappears from list, and you cannot select two times same fruit, except if you close the box.
When you validate your form, just remove trailing "/xx" to get the correct id.
I hope it's that you want.
Denis
I'm using jqGrid to maintain a database in MySQL using jSON data. I'm able to display the data in the grid but when I try to add or edit a data row through the modal form I get a message saying "Url is not set". But what is the editurl suppose to contain? mysql insert statements? I'm using the grid's predefined add and edit functions.
Also, if you take a look at the trirand demo page under Manipulating then under Grid Data. They specify their url as url:'server.php?q=2' and their editurl:"someurl.php" They never say what the someurl.php contains. This is where I get lost and I can't find a resource to give me any hints as to what is suppose to be in the editurl php file.
Thanks for any advice.
UPDATE:
Code in my editurl php file: I put the POST values from the col model in variables. I only need insert and update statements in the switch statement. Take a look at my insert statement to see which one I should be using. I also have to make you aware that I'm not listing all the columns in the database but I'm listing all the columns that the user sees in the grid. The first insert statement is commented and it states the columns that the values are suppose to be inserted based on their order. The second insert statement is following the order that is in the database. Where you see ' ' are the columns that I didn't want to display to the data grid for the user to see because that information wasn't relevant.
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "**********";
$dbname = "codes";
// connect to the database
$mysql_connect($dbhost, $dbuser, $dbpass) or die("Connection Error: " . mysql_error());
mysql_select_db($dbname) or die("Error conecting to db.");
$div = $_POST['div_id'];
$l2 = $_POST['l2_id'];
$l1l2 = $_POST['l1l2_id'];
$l1l3 = $_POST['l1l3_id'];
$l2l3 = $_POST['l2l3_id'];
$beg = $_POST['exec_beg'];
$end = $_POST['exec_end'];
$csa = $_POST['csa_id'];
$area = $_POST['area_id'];
$areadesc = $_POST['area_desc'];
$shortdesc = $_POST['short_desc'];
$longdesc = $_POST['long_desc'];
$enabled = $_POST['avail_ind'];
switch($_POST['oper'])
{
case "add":
$query = "INSERT INTO divcodes values ($div,'',$l1l2,$l2,$l1l3,$l2l3,$beg,$end,'',''$csa,$area,$areadesc,$shortdesc,$longdesc,$enabled,'','','','','',''";
$run = mysql_query($query);
break;
case "edit":
//do mysql update statement here
break;
}
When I set the editurl to my php file and I try to add new row of data to the grid it gives me internal server error 500. I don't know how to debug it any further and the error 500 is such a general error.
I thought that since I was using the predefined operations of the grid (add/edit) that the grid would just know to perform an insert or update statement into my database but it looks like that's not the case?
UPDATE TAKE 2: I changed the syntax to use the mysqli extension. Once I restructured my insert statements I stopped getting the 'Internal Server Error Code 500'. When I click add new record then fill in test data then click on submit the modal window disappears like the data has been added to the grid. But no where in the grid can I find the data (maybe the grid is not reloading with the new data). I checked phpmyadmin and the new row is no where to be found. When I edit an existing row and click submit the dialog box stays open but I'm not getting the error 500 which is a relief.
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "**********";
$dbname = "codes";
// connect to the database
$conn = mysqli_connect($dbhost, $dbuser, $dbpass) or die("Connection Error: " . mysql_error());
mysqli_select_db($conn,$dbname) or die("Error conecting to db.");
$div = $_POST['div_id'];
$l2 = $_POST['l2_id'];
$l1l2 = $_POST['l1l2_id'];
$l1l3 = $_POST['l1l3_id'];
$l2l3 = $_POST['l2l3_id'];
$beg = $_POST['exec_beg'];
$end = $_POST['exec_end'];
$csa = $_POST['csa_id'];
$area = $_POST['area_id'];
$areadesc = $_POST['area_desc'];
$shortdesc = $_POST['short_desc'];
$longdesc = $_POST['long_desc'];
$enabled = $_POST['avail_ind'];
switch($_POST['oper'])
{
case "add":
$query = "INSERT INTO divcodes (div_id,l1l2_id,l2_id,l1l3_id,l2l3_id,exec_beg,exec_end,csa_id,area_id,area_desc,short_desc,long_desc,avail_ind) values ($div,$l1l2,$l2,$l1l3,$l2l3,$beg,$end,$csa,$area,$areadesc,$shortdesc,$longdesc,$enabled)";
mysqli_query($conn,$query);
break;
case "edit":
$query = "UPDATE divcodes SET div_id=$div,l1l2_id=$l2,l2_id=$l1l2,l1l3_id=$l2l3,l2l3_id=$l2l3,exec_beg=$beg,exec_end=$end,csa_id=$csa,area_id=$area,area_desc=$areadesc,short_desc=$shortdesc,long_desc=$longdesc,avail_ind=$enabled";
mysqli_query($conn,$query);
break;
}
?>
The editurl is the PHP file that will do your INSERTS, UPDATES and DELETES.
There are several parameters passed to this file including the parameter: oper which will be either add, edit or del depending on which operation you did.
In your PHP file (the editurl file) I would just do a switch:
switch ($_POST["oper"]) {
case "add":
// do mysql insert statement here
break;
case "edit":
// do mysql update statement here
break;
case "del":
// do mysql delete statement here
break;
}
Also passed to that file will be all of your data from that row in name:value pairs, just like the oper parameter. The name will be the index property you defined in your colModel array when you setup your grid.
So if you had a column (from the colModel) that looked like:
{
name: 'name1',
index: 'name1',
width: 95,
align: "center",
hidden: false
}
In your editurl PHP file, you can access that column's value to build your queries above by using:
$_POST["name1"]
Hope this helps and let me know if you have any further questions. I struggled with this part of jQGrid just like you are so I know the pain!! lol
UPDATE
Your MySQL Insert statement is incorrect. You do not need to include every column in that exists in your table, just the ones that are required (the columns that can't be null).
For instance, I have a table (tableName) with three columns:
ID (required, not null)
Name (required, not null)
Phone (not required)
If I want to perform an insert onto this table, but I don't want to insert anything into the Phone column, my Insert statement would look like:
INSERT INTO tableName (ID, Name) VALUES (123, "Frank")
On the left side of VALUES is where you specify which columns you will be inserting into. On the right side of VALUES are the actual values we will be inserting.
Here is a simple, helpful link on MySQL syntax: http://www.w3schools.com/php/php_mysql_insert.asp
As you can see, in that first example on that link, they don't specify which columns, meaning they will be inserting data into ALL columns. In your case, that is not what you want, so I would check out their second example, which does specify the columns you are inserting into.
com and apex triggers
I have two objects namely Customer_c and Order_c
I am trying to write a trigger to delete an order entry belonging to a customer who has been made inactive.
Basically i want to trigger on update for customer_c table
retrieve an entry from customer_c where the Active_c( boolean value) has been made false upon update and take that customers 'Name' and look up in the Order_c table and delete all the 'Name'(Orders) belonging to that customer.
Below is my trigger code. when I am trying to save the trigger in salesforce.
I get the following error:
Error: Compile Error: unexpected token: 'res2' at line 13 column 19
Could anyone please help me on this?
trigger NewCustomerActive on Customer__c(after update) {
List<Customer__c> res2 =
[SELECT Name FROM Customer__c j WHERE j.Active__c = false];
List<Order__c> res =
[SELECT Name FROM Order__c WHERE Customer__c = res2];
}
Change it to
trigger NewCustomerActive on Customer__c(after update) {
List<Customer__c> res2 =
[SELECT Name FROM Customer__c j WHERE j.Active__c = false];
List<Order__c> res =
[SELECT Name FROM Order__c WHERE Customer__c in:res2];
}
Or if you want to save soql statements:
trigger NewCustomerActive on Customer__c(after update) {
List<Order__c> res =
[SELECT Name FROM Order__c WHERE Customer__r.Active__c = false];
}