GRID COLUMNS atk4 agiletoolkit - grid

Hi I am trying to get some referenced data from another table,
Data structure:
Table PartDetail
-id
-OperationTypeID(foreign key)
-DateAdded
Table OperationType
-id
-Description
I am trying something like this:
$crud = $this->add('MVCGrid', array('allow_edit'=>false));
$crud->setModel('Model_PartDetail',array('DateAdded'));
But then I want to see the "description" from table OperationType, because on my PartDetail model I declare my relationship like this:
$this->hasOne('OperationType','OperationTypeID','Description')
->mandatory(true)
->caption('Operation Type');
for example in this case I want to see the description from the table OperationType
I tried:
$crud->setModel('Model_PartDetail',array('DateAdded','OperationType'));
but is not working, only works with:
$crud->setModel('Model_PartDetail',array('DateAdded','OperationTypeID'));
but I get only the ID number, not the description.
How this works?

I was able to solved it.
on the model you need to redefine it as
$ref = $this->add('Field_Reference', 'OperationTypeID');
$ref->dereferenced_field='OperationTypeDescription';
$m = $this->add('Model_OperationType');
$m->addField('D'); // <-- actually seems that this line is not working
$ref->setModel($m, 'Description');
And then in the page you can actually added as OperationTypeDescription:
$crud->setModel('Model_PartDetail', array('DateAdded', 'OperationTypeDescription'));

Related

Entity Framework reverse poco on table without primary key and null column

I am using Entity Framework Reverse POCO generator v2.37.5.
I need to map an external database. It is not possible for me modify the schema. But the tables don't have primary key and all columns are set to null.
However, the combination of certain columns will always be unique.
For example, the following 3 columns can be combine to form the primary key:
EnrollNumb
CubNumb
SeqVal
Is there any setting in the template that helps me to set combination of columns as primary key?
Any suggestion / direction will be greatly appreciated.
First, find your Entities.ttinclude file.
Protip / entirely optional side-quest and distraction for better T4 editing:
Extract all the C# code (inside the T4 <#+ #> blocks) and move it to a new file named Entities.ttinclude.cs
Add <## Include File = "Entities.ttinclude.cs" #> to the Entities.ttinclude file.
Change the project build-action for Entities.ttinclude.cs to None.
Now you can get (basic) syntax-coloring for the C# code.
Now back to your regularly scheduled stackoverflowing:
Look for this somewhere around lines 250-320:
Settings.UpdateColumn = (Column column, Table table) =>
Inside the function you can tell EF that there totally is a PK defined on this table, I pinky-swear! like so:
Settings.UpdateColumn = (Column column, Table table) =>
{
// ...
if( column.ParentTable.Name == "Memb" )
{
switch( column.Name )
{
case "EnrollNumb":
case "CubNumb":
case "SeqVal":
column.IsNullable = false; // PK columns cannot be NULLable.
column.IsPrimaryKey = true;
column.PrimaryKeyOrdinal = column.Ordinal;
column.ParentTable.HasPrimaryKey = true
break;
}
}
// ...
}
Run Model.tt
Assuming no errors happened, take a look at the folder with the generated .cs files, look for Memb.Configuration.cs. It should look something like this:
[System.CodeDom.Compiler.GeneratedCode("EF.Reverse.POCO.Generator", "2.37.1.0")]
internal class MembConfiguration : System.Data.Entity.ModelConfiguration.EntityTypeConfiguration<Memb>
{
public MembConfiguration( String schema )
{
ToTable( "Memb", schema );
HasKey( x => new { x.EnrollNumb, x.CubNumb, x.SeqVal } );
Property( x => x.EnrollNumb ).HasColumnName( "EnrollNumb" ).HasColumnType( "nvarchar" ).IsRequired().MaxLength(10);
Property( x => x.CubNumb ).HasColumnName( "CubNumb" ).HasColumnType( "nvarchar" ).IsRequired().MaxLength(50);
Property( x => x.SeqVal ).HasColumnName( "SeqVal" ).HasColumnType( "nvarchar" ).IsRequired().MaxLength(5);
// other columns here
}
}
And you should be able to build your project, then run it, and it should just work.
You can also define fake Foreign Key constraints and set-up other kinds of relationships and EF will believe you, which is handy for when you want EF to handle a VIEW as though it were a TABLE, especially as a VIEW in SQL Server cannot be imbued with PK and FK constraints (you can also get DML working provided your VIEW is updatable).

How do I access a calculated field in Rails?

In my first attempt to develop something in Ruby on Rails :) ... I have a list of names stored in fields "first_name" and "last_name". In my Person model, I have defined something like this:
def sort_name
sort_name = last_name + ',' + first_name
end
Now I want to show all persons shown in a list, sorted by sort_name, but (in my controller) something like
#persons = Person.order(:sort_name)
doesn't work (Unknown column 'sort_name' in 'order clause'). How do reference to the calculated field sort_name in my controller?
I am sure this is a "oh my god I am so stupid moment" but happy for any advise!
If the model Person has the fields name, first_lastname and second_lastname, you can do the next:
Person.order(:name, :first_lastname, :second_lastname)
By default is ordering in ascending way. Also you can put if you want ascending or descending way for each field:
Person.order(name: :asc, first_lastname: :desc, second_lastname: :asc)
Additional if you want add a column with the complete name, you can use select, using postgresql the code would be:
people = Person.order(
name: :asc, first_lastname: :desc, second_lastname: :asc
).select(
"*, concat(name,' ', first_lastname, ' ',second_lastname) as sort_name"
)
people[0].sort_name
# the sort_name can be for example "Adán Saucedo Salas"

ConvertFrom-StringData values stored in variable

I'm new to Powershell and I'm putting together a script that will populate all variables from data stored in a Excel file. Basically to create numerous VMs.
This works fine apart from where i have a variable with multiple name/value pairs which powershell needs to be a hashtable.
As each VM will need multiple tags applying, i have a column in excel called Tags.
The data in the field would look something like: "Top = Red `n Bottom = Blue".
I'm struggling to use ConvertFrom-StringData to create the hashtable however for these tags.
If i run:
ConvertFrom-StringData $exceldata.Tags
I end up with something like:
Name Value
---- -----
Top Red `n bottom = blue
I need help please with formatting the excel field correctly so ConvertFrom-StringData properly creates the hashtable. Or a better way of achieving this.
Thanks.
Sorted it, formatted the excel field as: Dept=it;env=prod;owner=Me
Then ran the following commands. No ConvertFrom-StringData required.
$artifacts = Import-Excel -Path "C:\temp\Artifacts.xlsx" -WorkSheetname "VM"
foreach ($artifact in $artifacts) {
$inputkeyvalues = $artifact.Tags
# Create hashtable
$tags = #{}
# Split input string into pairs
$inputkeyvalues.Split(';') |ForEach-Object {
# Split each pair into key and value
$key,$value = $_.Split('=')
# Populate $tags
$tags[$key] = $value
}
}

Building a query in appmaker with "or"

So say I am using a form to build a query against my datasource (i've come so far in two weeks! I can do this!), how do I make it more complex?
What if I want books by austen that include the word "pride" AND books by gabaldon that contain the word "Snow"
the individual queries would be
widget.datasource.query.filters['author']._contains = "austen";
widget.datasource.query.filters['title']._contains = "pride";
and
widget.datasource.query.filters['author']._contains = "gabaldon";
widget.datasource.query.filters['title']._contains = "snow";
in pseudosql it would be
select * from table
where
((author like 'austen') and (title like 'snow'))
or
((author like 'gabaldon') and (title like 'pride'))
Is there a way to filter a data source on a complex query like this and cut out the whole widget.datasource aspect? I'd be fine with using a calculated table.
Edit: Ok i'm making some progress towards the kind of functionality I need, can anyone tell me why this works:
widget.datasource.query.filters.document_name._contains = 'x';
but this does not?
widget.datasource.query.parameters.v1 = "x";
widget.datasource.query.where = 'document_name contains :v1';
this also doesn't work:
widget.datasource.query.where = 'document_name contains "x"';

Show table by button click

TABLES: mara, marc.
"marc is N
"mara is 1
SELECTION-SCREEN PUSHBUTTON 15(10) text-001 USER-COMMAND press.
DATA: lt_mara TYPE TABLE OF mara WITH HEADER LINE,
ls_mara TYPE mara.
DATA: lt_marc TYPE TABLE OF marc WITH HEADER LINE,
ls_marc TYPE marc,
Sum type P length 8 DECIMALS 2.
PARAMETERS: p_mtart TYPE mara-mtart.
SELECT-OPTIONS: so_werks FOR marc-werks.
SELECT * FROM mara INTO TABLE lt_mara
WHERE mtart = p_mtart.
IF sy-subrc = 0.
SELECT * FROM marc INTO TABLE lt_marc
FOR ALL ENTRIES IN lt_mara
WHERE matnr = lt_mara-matnr
AND werks IN so_werks.
LOOP AT lt_marc INTO ls_marc.
READ TABLE lt_mara INTO ls_mara
WITH KEY matnr = ls_marc-matnr.
sum = ls_mara-brgew + ls_mara-ntgew .
WRITE:/ ls_mara-mtart, ls_marc-matnr , ls_marc-werks , ls_mara-brgew, ls_mara-ntgew,sum.
ENDLOOP.
ELSE.
MESSAGE TEXT-e02 TYPE 'E' .
ENDIF.
How Can make this happen:I want that on click of the button to show the table.Please the code to be as simple as possible and as easy to understand as possible.if you can't make it with a button make it with a radiobutton or smth else.
Thanks in advance!
If you want to keep it simple, you can use "sy-ucomm" which stores your last triggered action. With your button, it'd look like this:
AT SELECTION-SCREEN.
CASE sy-ucomm.
WHEN 'PRESS'.
*code for displaying your table via ALV or WRITE goes here*
ENDCASE.
The most common way to display internal tables like this is with an ALV, a simple example of how to build up an ALV can be found here:
https://archive.sap.com/discussions/thread/873601
If you'd like it to do the WRITE: to screen under one circumstance, and display the ALV Grid in another, you should use Select Options and parameters.
Your code needs the addition of EVENTS, please take a look here on what they are and how to use them:
http://www.erpworkbench.com/abap/abap-events.htm

Resources