Why am I getting "record not on file (138)" on progress4GL - progress-4gl

I'm trying to check if a record exists, otherwise I want to create it.
For example,
I've got a <table> that doesn't have a tab-code equals to 2, so it is not available, then I do another find just to "call" the table to create a new item, but for some reason it doesn't "call" the table and I get a beautiful standard error: record <table> is not on file (138).
I'm still new to progress4GL, so if it's stupid I apologize profusely.
find <table> where tab-code = 2.
if not avail <table>
then do:
find last <table> no-lock no-error.
create <table>.
assign <table>.tab-code = 2.
end.

find <table> where tab-code = 2 NO-ERROR.

Always use NO-LOCK NO-ERROR when you find the record. If not using NO-ERROR then it will give an error after the compilation(means if the record is not available).
FIND FIRST <table> NO-LOCK WHERE <table.id> = 2 NO-ERROR.
IF NOT AVAILABLE <table> THEN DO:
CREATE <table>.
ASSIGN <table>.<table_id> = 2 NO-ERROR.
END.
/*always use FIND FIRST to get record from the particular table. FIND case will fail some time */

Related

Adding Fields/ Columns to oc_product_description Table, Opencart 2.3.0.2

Background: Added some new columns in oc_product_description (I added some key product features and alternative name for ebay listing, so I can generate the product data into a template to use on ebay listings, whilst keeping and using the code on the opencart website..)
Problem: that when I save the product in opencart it deletes the data I just entered into the table, because it uses a Delete and then Insert function (by the looks of it?) in admin/model/catalog/product.php approx line 140. Which uses the $data['product_descriptions'] array which comes about in admin/controller/catalog/product.php approx line 765.. but here there are 3 possibilities.. either from the post or from a get function, or a new array..
I added hidden fields to the admin/view/catalog/product_form.php but what's going on here doesn't make it through to the table in the end..
I also added the new fields to the getProductDescriptions() function and directly to the $data array just as the other fields were already..
Please don't send me off to look up MVC models..Please help!!!
The problem was: that I had used the wrong name and value in the hidden fields..I obviously wasn't giving it much thought when I merely wrote:
<input type="hidden" name="name_ebay" value="<?php echo $entry_name_ebay; ?>">
In actual fact what was required was:
<input type="hidden" name="product_description[<?php echo $language['language_id']; ?>][name_ebay]" value="<?php echo isset($product_description[$language['language_id']]) ? $product_description[$language['language_id']]['name_ebay'] : ''; ?>">
I hope this post has offered some reminders or hints concerning Adding Your Own Fields to Opencart's Product Description Table, and using them in the admin
Take note mostly of:
i) use of language id in the view
ii) the delete, insert (instead of update) in model
iii) the change from post to $data array in controller
Furthermore, I did notice that the delete line,
$this->db->query("DELETE FROM " . DB_PREFIX . "product_description WHERE product_id = '" . (int)$product_id . "'");
Seems to delete the record with this product id?? but without regard to language id?.. I'll have to look into whether this deletes the translated versions on a multi-lingual site of the products in the product_description table..?

How to do a regexp in a waitForPopUp Command in Selenium IDE?

I have popups with this name structure:
static_dynamic_static
The dynamic part changes each time I log in so my test cases fail each time. I thought about solving the problem with a regular expression like this:
Command: waitForPopUp
Target: regexp:static_.+_static
But this doesn't work. What do I do wrong? Is this even working. If not, is there another way to solve this problem?
From my experience you don't need to declare it as a regex within the target field, you should just be able to have the target as:
static_*_static
and that should do it
If you've got only one popup window you can use null as a target and test will take the first popup:
waitForPopup | null
The other option is to get dynamic part before popup opening. It is very likely that the dynamic part could be retrieved from the page. If so you can get it using storeEval, and than use like:
waitForPopup | javascript{'static'+storedVars['dynamic']+'static'}
If you can't store the dynamic part please provide an html of your page or only the part where the dynamic part mentioned.
I see that theoretically it could be possible to get all the names of your windows and than to use pattern in a loop to get the one.
Also (theoretically) it is possible to expand default waitForPopup function.
But the second way and especially the first are much cheaper.
The best way to handle this might be to run a snippet of javascript to handle this:
<tr>
<td>storeEval</td>
<td>var myRe = new RegExp("^prefix.+", "g"); var mywin; windows=selenium.getAllWindowNames();for (i = 0; i < windows.length; i++) { if(myRe.test(windows[i])) { mywin=windows[i]} }; mywin;</td>
<td>x</td>
</tr>
<tr>
<td>selectWindow</td>
<td>name=${myWindow}</td>
<td></td>
</tr>
That javascript isn't fully function (no null checking) but should help get you on the right track.

Selenium IDE, selecting muliple text using same class

I have a page with lots of text using the same class. I am wanting to select and store all the text with that same class. Is this possible? All advice & comments appreciated!
I have HTML code like this:
<p class="foo">Some sample text</p>
<p class="foo">Some more sample text</p>
I have tried this:
<tr>
<td>storeText</td>
<td>//p[#class=foo']</td>
<td>var1</td>
</tr>
I expected var1 to be:
Some sample text
Some more sample text
Alternatively do I need to set up a while statement and gather each individually?
This page talks about a similar exercise, but uses Selenium for Python: Get the text from multiple elements with the same class in Selenium for Python?
//gather all p[class=foo]
List<WebElement> ele = driver.findElements(By.cssSelector("p.foo"));
Iterator<WebElement> iter = ele.iterator();
// initialize array, map, whatever
While(iter.hasNext()) {
// insert text into map
// print to log
// store in array
//whatever you need
var.add( iter.next().text() );
}
I didn't get to try out the answer from #bcar because I am not a javascript expert nor am I sure I could put the answer into IDE. I found another way however. I discovered that the text is stored in tables, so I am using the following code to extract the entire table (which includes the text I need).
<tr>
<td>storeText</td>
<td>//div/h2[text()="Elements and Performance Criteria"]/following::table</td>
<td>Content</td>
</tr>
Now I have to work out how to replace the new lines with as this is plain text. Another question for stackoverflow! Thanks.
Quite easy:
Just loop through the stored elements.
Whenever you use find_elements_by_class_name, it returns the list of selenium web elements. Hence you just need to iterate with a loop, like this.
names = driver.find_elements_by_class_name("_xEcR")
for i in names:
print(i.text)

How can I pull data in a controller and form for one model that is in a different model with out a foreign key relationship?

I am new to rails and haven't really done to much with data outside of the model.
I have a form that references a table controller for files. I want to add an dropdown that will display a list of projects from a project table for the user to assign a the file to a project if they want too. Assigning a project is not a requirement. The file can be unassigned to a project. I do have a project_id column in the file table for those projects assigned but it is allowed to be null and I did not build a relationship because I need to have cases where there are none.
Can someone please tell me how to do this?
When they evaluate the file, the screen posts back with a save or update button depending if it has already been saved in the database.
At the same time as the save and update pop up on the right I want to display a list box of the projects with an assign project button. If new just a list, if update either just a list because not assigned or display the selected value in the list if already assigned, while allowing them to change it from the list if desired.
In the file controller method that posts back to the UI I have this code:
#file_alias_filedata = FileAliasFiledata.all
#projects = Project.all
for update
#projects = Project.find(params[:id])
In the form I have this code:
<p> <label> Select Project to Assign:</label> <br />
<%= select_tag 'projects', (#projects.present? ? options_for_select(#projects, #selected_project) : []) %> </p>
The form runs but I get this in the dropdown box:
#<Project:0x))7ff531ab4518>
Can someone please help me figure out how to accomplish my task and why I see the strange box value?
What am I doing wrong?
Thank you for your help!
Assigning a project is not a requirement. The file can be unassigned
to a project. I do have a project_id column in the file table for
those projects assigned but it is allowed to be null
From the docs:
belongs_to(name, scope = nil, options = {}) public
Specifies a
one-to-one association with another class. This method should only be
used if this class contains the foreign key. If the other class
contains the foreign key, then you should use has_one instead. See
also ActiveRecord::Associations::ClassMethods’s overview on when to
use has_one and when to use belongs_to.
Methods will be added for retrieval and query for a single associated
object, for which this object holds an id:
association(force_reload = false)
Returns the associated object. nil is returned if none is found.
Likewise,
has_many(name, scope = nil, options = {}, &extension) public
Specifies
a one-to-many association. The following methods for retrieval and
query of collections of associated objects will be added:
collection(force_reload = false) Returns an array of all the
associated objects. An empty array is returned if none are found.
But belongs_to() and has_many() are supposed to make things more convenient for you. You certainly do not have to use them.
Next,
and why I see the strange box value? What am I doing wrong?
You see the strange value for the same reason the following two loops display different things:
class Dog
attr_reader :name
def initialize(name)
#name = name
end
end
#dogs = [
Dog.new("Sam"),
Dog.new("Betty"),
Dog.new("Pete"),
]
#dogs.each {|dog| puts dog}
#dog_names = #dogs.map {|dog| dog.name }
#dog_names.each {|dog_name| puts dog_name}
--output:--
#<Dog:0x0000010099a308>
#<Dog:0x0000010099a2b8>
#<Dog:0x0000010099a268>
Sam
Betty
Pete
You will see the same result if you do something like the following in a view:
<div>
<%= select_tag "dog", options_for_select(#dogs) %>
</div>
<div>
<%= select_tag "dog_name", options_for_select(#dog_names) %>
</div>
If you read the docs here:
http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/options_for_select
...you will see several examples, which should make it clear that options_for_select() takes an argument that is:
An array of Strings.
A Hash where both the keys and values are Strings.
An enumerable that iterates over some Strings.
etc.
Do you see a pattern? It's Strings! options_for_select() needs an argument that consists of Strings. If the argument is not a collection of Strings, e.g. an array of project objects, then options_for_select() tries to convert the objects to strings by calling to_s() on the objects. And the default to_s() method is Object#to_s() which is inherited by all objects and produces a string containing the class name and the object_id.
I am also new to rails, but I think you can try using the options_from_collection_for_select method.
<%= select_tag :search_state, options_from_collection_for_select(State.find(:all, :select => :name), :name, :name) %>
Hope this help. Cause it certainly helped me.

How to add Count of child table in EntityDataSource

I have an EntityDataSource that works to get row data from tblOrderFile as follows:
<asp:EntityDataSource ID="entityDataSourcePreorder" runat="server"
ConnectionString="name=iDBEntities"
DefaultContainerName="iDBEntities" EnableFlattening="False"
EntitySetName="tblOrderFiles"
Select="it.[pkOrderFileID], it.[fkOrderFileStatusID], it.[Filename], it.[CreateDate], it.[UserId]"
AutoGenerateWhereClause="True" EntityTypeFilter="" Where="">
I would now like to modify it to also return back the number of rows in child table tblOrderFileItem (with Entity Set Name tblOrderFileItems).
I found a way to get the Count to work by adding an Include directive as follows:
<asp:EntityDataSource ID="entityDataSourcePreorder" runat="server"
ConnectionString="name=iDBEntities"
DefaultContainerName="iDBEntities" EnableFlattening="False"
EntitySetName="tblOrderFiles" Include="tblOrderFileItems"
AutoGenerateWhereClause="True" EntityTypeFilter="" Where="" >
</asp:EntityDataSource>
but I believe this is returning the all the columns of all the rows for each Order Item. I only really want the Count and do not want to deliver the rest of the data to the web page.
I also tried simply adding it.tblOrderFileItems.Count to the Select statement but get an error saying
'Count' is not a member of 'Transient.collection[MyDBModel.tblOrderFileItem(Nullable=True,DefaultValue=)]'. To extract a property of a collection element, use a subquery to iterate over the collection.
Select="ANYELEMENT(SELECT VALUE Count(c.ItemId) FROM it.tblOrderFileItems AS c) as ChildCount"