Gossamer Forum
Home : Products : DBMan : Customization :

Three way Relationship

(Page 2 of 3)
> > > >
Quote Reply
Re: Three way Relationship In reply to
So far, so good. Smile

I found your problem!!

In looking at your files again, I found the following:

In po.cfg you have

'PO_Number' => [ 1, 'alpha', 20, 255, 1, '', ''],

and

$db_key = 'PO_Number';

But in db.cgi, sub switch_to_po, you have

$db_key_pos = 0;

Change the above line to

$db_key_pos = 1;

and you should get your data.

In Reply To:
PS: Out of Curiousity, I tried to remove those Comments(#) in the last three lines. I get the listing of the fileds but I also get those many blank lines.
That's why I added the # to the beginning of the lines. I didn't want you to get the blank lines.

Once you make the change in sub switch_to_po, change the code in sub html_record_form to

Code:
my (%rec) = @_;
$rec{$db_key} = $in{$db_key};
&switch_to_po;
%rec2 = &get_record($rec{$db_key});
foreach $col (@db_cols) {
print "--$rec2{$col}--<BR>";
}
You should get the entire record from your po file. Once that's working, we'll get the dealer info.


JPD
Quote Reply
Re: Three way Relationship In reply to
Right There !

It prints the all the fields in the record correctly. I will try and populate my OPF form and Display correctly.

Yes Now, the next task is to getin the Dealer Info.

Your advice again.......Smile





Regards

Vijay
Quote Reply
Re: Three way Relationship In reply to
Cool!

The dealer info key field is Userid, right? And that is the field that relates the PO db with the dealer db.

After

%rec2 = &get_record($rec{$db_key});

(you can delete those debugging lines now)

add


&switch_to_dealer;
%rec3 = &get_record($rec2{'User_Id'});


Now all of your dealer info should be in the %rec3 hash.

To get back to the code I wrote a couple of weeks ago, to put the values from the %rec2 and %rec3 hashes into the %rec hash so you can use them in your form, add the following:

Code:

&switch_to_opf;
foreach $col (@db_cols) {
if (exists $rec2{$col}) { $rec{$col} = $rec2{$col}; }
elsif (exists $rec3{$col}) { $rec{$col} = $rec3{$col}; }
}
So, when you put it all together, you should have

Code:

my (%rec) = @_;
$rec{$db_key} = $in{$db_key};
&switch_to_po;
%rec2 = &get_record($rec{$db_key});
&switch_to_dealer;
%rec3 = &get_record($rec2{'User_Id'});
&switch_to_opf;
foreach $col (@db_cols) {
if (exists $rec2{$col}) { $rec{$col} = $rec2{$col}; }
elsif (exists $rec3{$col}) { $rec{$col} = $rec3{$col}; }
}


Then use the regular $rec{'FieldName'} for the values of your form fields. This should populate your fields with the data.


JPD
Quote Reply
Re: Three way Relationship In reply to
Hi J P Deni,

This is just to inform you that things seem to be working the way you have suggested. Now I am working on the HTMLs and Overall look and feel. I am a bit slow learner. I will get back soon with my next set of queries.

I really admire the way you work with us on these individual projects. Hats Off !!!


Regards

Vijay
Quote Reply
Re: Three way Relationship In reply to
I get such a sense of satisfaction when a problem, especially a long problem like this one, is finally resolved.

I'm glad I could help.


JPD
Quote Reply
Post deleted by miheer In reply to
Quote Reply
Post deleted by miheer In reply to
Quote Reply
Re: Three way Relationship In reply to
I am back again (Very fast) with some more cribbing....

I have a problem with Modify Record in my OPF. When I try to modify the record, Most of the fields go blank ( i.e. the fields from "PO" and "dealer" records perticularly) I need a clue to get going

Regards

Vijay
Quote Reply
Re: Three way Relationship In reply to
The addition of the values to the form fields takes place in sub html_record_form. That's the subroutine I need to see.

Can you get rid of the other stuff? It makes the page take a long time to load. Smile


JPD
Quote Reply
Re: Three way Relationship In reply to
Hi JP Deni,

Here is my Code

sub html_record_form {
# --------------------------------------------------------

my (%rec) = @_;
$rec{$db_key} = $in{$db_key};
&switch_to_po;
%rec2 = &get_record($rec{$db_key});
&switch_to_dealer;
%rec3 = &get_record($rec2{'User_Id'});
&switch_to_opf;
foreach $col (@db_cols) {
if (exists $rec2{$col}) { $rec{$col} = $rec2{$col};
}
elsif (exists $rec3{$col}) { $rec{$col} = $rec3{$col};
}
}

($db_auto_generate and print &build_html_record_form(%rec) and return);

my $font_color = 'Font face="Verdana" Size=2 Color=#003399';

...
|;
}
========================================
I know It is a mess here, I will clear it after your reply

Thanks



Regards

Vijay
Quote Reply
Re: Three way Relationship In reply to
I went ahead and deleted it. I had a hard time finding the code I needed.

If the values are being entered correctly when a record is added, then the thing to do is only pull the code from the other databases at the time the record is added and not when it is modified.

Code:
my (%rec) = @_;
if ($in{'add_form'}) {
$rec{$db_key} = $in{$db_key};
&switch_to_po;
%rec2 = &get_record($rec{$db_key});
&switch_to_dealer;
%rec3 = &get_record($rec2{'User_Id'});
&switch_to_opf;
foreach $col (@db_cols) {
if (exists $rec2{$col}) { $rec{$col} = $rec2{$col}; }
elsif (exists $rec3{$col}) { $rec{$col} = $rec3{$col}; }
}
}
To make sure the correct flag is set, add

$in{'add_form'} = 1;

to the beginning of sub html_add_form.


JPD
Quote Reply
Re: Three way Relationship In reply to
Hi JPD,

I tried above mod but still resuly is same

Here is my code
sub html_add_form {
# --------------------------------------------------------
# The add form page where the user fills out all the details
# on the new record he would like to add. You should use
# &html_record_form to print out the form as it makes
# updating much easier. Feel free to edit &get_defaults
# to change the default values.

$in{'add_form'} = 1;
&html_print_headers;
print qq|
<html>
<head>
<title>$html_title: Create an Order Processing Form.</title>
</head>

<body bgcolor="#DDDDDD">
<form action="$db_script_url" method="POST">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
<center>
<table border=1 bgcolor="#FFFFFF" cellpadding=5 cellspacing=3 width=100% align=center valign=top>
<tr><td colspan=2 bgcolor="navy">
<FONT FACE="MS Sans Serif, arial,helvetica" size=1 COLOR="#FFFFFF">
<b>$html_title: Create an Order Processing Form</b>
</td></tr>
<tr><td>
<p><$font_title>
</font>
<$font>
|; &html_record_form (&get_defaults); print qq|
</font></p>
<p><center> <INPUT TYPE="SUBMIT" NAME="add_record" VALUE="Add Record"> <INPUT TYPE="RESET" VALUE="Reset Form"></center></p>
|; &html_footer; print qq|
</td></tr>
</table>
</center>
</form>
</body>
</html>
|;
}

Of Course My sub html_record_form is same as indicated above by you.

The Problem is, It is not able to pull the values from PO and Dealer Databases.

Thanks



Regards

Vijay
Quote Reply
Re: Three way Relationship In reply to
When is it not pulling the values from the other databases? When you add or when you modify? I thought we had the add thing worked out.


JPD
Quote Reply
Re: Three way Relationship In reply to
Hi JP Deni,

It Does not pull the values from other databases only during MODIFY. Add record of course works very well.

Thanks



Regards

Vijay
Quote Reply
Re: Three way Relationship In reply to
So the values are being added to the fields when the record is added.

Then the values should be in the fields when the record is modified. You don't have to pull any data from other databases when you are modifying the record. That's why I had you add if ($in{'add_form'}) to sub html_record_form.


JPD
Quote Reply
Re: Three way Relationship In reply to
Logically speaking yes ! It does not have to pull the values because the record is already there.

I also checked the opf.db file It shows correct record but while modification It does not show me some of the fields pre-filled while some fields are shown pre fielled.

I need your advice

Thanks



Regards

Vijay
Quote Reply
Re: Three way Relationship In reply to
Okay. Now we're getting somewhere.

In sub html_record_form, after the code you added to pull in the data from the other databases, add (for debugging purposes)

Code:

elsif ($in{'modify_form'} {
foreach $col (@db_cols) {
print "$col -- $rec{$col}<BR>"
}
}
(That should look familiar to you. Smile)

This will tell us what is actually in the record when you try to modify it.


JPD
Quote Reply
Re: Three way Relationship In reply to
Hi JPD,

Please once again excuse me for my Perl knowledge. I am getting a syntax error. ( somewhere in elseif statement)

Here is my code

my (%rec) = @_;
if ($in{'add_form'}) {
$rec{$db_key} = $in{$db_key};
&switch_to_po;
%rec2 = &get_record($rec{$db_key});
&switch_to_dealer;
%rec3 = &get_record($rec2{'User_Id'});
&switch_to_opf;
foreach $col (@db_cols) {
if (exists $rec2{$col}) { $rec{$col} = $rec2{$col}; }
elsif (exists $rec3{$col}) { $rec{$col} = $rec3{$col}; }
}
}
elsif ($in{'modify_form'} {
foreach $col (@db_cols) {
print "$col -- $rec{$col}<BR>"
}
}


Where am I making mistake ?

Thanks

Regards

Vijay
Quote Reply
Re: Three way Relationship In reply to
My mistake.

Code:
elsif ($in{'modify_form'}) {
foreach $col (@db_cols) {
print "$col -- $rec{$col}<BR>"
}
}
JPD
Quote Reply
Re: Three way Relationship In reply to
I tried the above modification.

Now, don't get any error but It does not print anything not even blank lines above the normal form.

Thanks




Regards

Vijay
Quote Reply
Re: Three way Relationship In reply to
I guess I'll need to look at your html.pl file.

JPD
Quote Reply
Re: Three way Relationship In reply to
Hi JPD,

You can see the file at following URL

http://www.thakralindia.com/dbman/opf_html.txt

Thanks


Regards

Vijay
Quote Reply
Re: Three way Relationship In reply to
That's what I get for working from memory.

In your debugging lines, change

elsif ($in{'modify_form'} {

to

elsif ($in{'modify'} {


JPD
Quote Reply
Re: Three way Relationship In reply to
Yes !!!

Now it Prints all the values correctly. (Only in the debugging area i.e. before the form) but it still does not pre-fill the valuse in form fields

What Next ? Smile

Thanks

Regards

Vijay
Quote Reply
Re: Three way Relationship In reply to
Your sub html_record_form is incorrect. You have

Code:

<input type="text" name="PO_Number" value="$rec2{'PO_Number'}">

<input type="text" value="$rec2{'Date'}" name="Date">

<input type="text" value="$rec3{'Dealer_Code'}" name="Dealer_Code">

<input type="text" name="Company" value="$rec3{'Company'}" size="50">

<input type="text" name="Address" value="$rec3{'Address'}" size="50">

<input type="text" name="City" value="$rec3{'City'}">

<input type="text" name="State" value="$rec3{'State'}">

<input type="text" name="Shipping_Address" value="$rec2{'Shipping_Address'}" size="50">
and others, but you get the picture.

The point of the code I gave you:

Code:

foreach $col (@db_cols) {
if (exists $rec2{$col}) { $rec{$col} = $rec2{$col}; }
elsif (exists $rec3{$col}) { $rec{$col} = $rec3{$col}; }
}
was to put all of the values into the % rec hash so you wouldn't need to use $rec2{'FieldName'} and $rec3{'FieldName'}. I'm sure I mentioned that earlier in the thread. I guess you missed what I wrote on 18 May:

At that point, all of the data for the order and the dealer should be in the % rec hash and you can use your form fields normally.

Change all of the $rec2{'FieldName'} and $rec3{'FieldName'} variables to $rec{'FieldName'} variables.



JPD
> > > >