Gossamer Forum
Home : Products : DBMan : Customization :

Append to 2nd DB using info from add form

Quote Reply
Append to 2nd DB using info from add form
I have looked at all the posts on appending to a field in a database with information from the add record form, but, none have to do with multiple databases.

I have database A which has records with ID as field 0 and another field called Work. And database B which has a separate ID field as field 0, and a field called Ticket, separate db file, separate pl file, and different field names.

What I want to do is when a a user enters a record via the add form in database B, they enter into the form the Ticket number which corresponds to the ID field in database A. And, when the record in database B is entered with this information I want it to append " $rec{'ID'}" (including the space) to the field Work in database A, append to the end of the field and not overwrite it.

I know this is possible, but I can't figure out how to do it. Can someone help me with this?
Quote Reply
Append to 2nd DB using info from add form [update] In reply to
Ok, so I've gotten this far. This code listed below will allow the updates and pulls the current information from the second database, but, instead of modifying the current information in the database it creates a new record with the same ID. How can change this code to modify the record rather than add a new one?

Code:
@db_cols = @tickets_cols;
$db_file_name = $tickets_db;
$in{'ID2'} = $rec{'Ticket'};
$ticket = $rec{'ID'};

open (DB, "<$db_file_name") or &cgierr("error in modify_records. unable to open db file: $db_file_name.\nReason: $!");
@lines = <DB>; # Slurp the database into @lines..
close DB;

$found = 0; # Make sure the record is in here!
LINE: foreach $line (@lines) {
if ($line =~ /^$/) { next LINE; } # Skip and Remove blank lines
if ($line =~ /^#/) { $output .= $line; next LINE; } # Comment Line
chomp ($line);
@data = &split_decode($line);

if ($data[$db_key_pos] eq $in{'ID2'}) {

%in = &get_record($in{'ID2'});
$in{'Work'} = $rec{'Work'} . "," . $ticket;
$in{'ModifyDate'} = &get_date;
$output .= &join_encode(%in);
$found = 1; } }

open (DB, ">>$db_file_name") or &cgierr("error in add_record. unable to open database: $db_file_name.\nReason: $!");
print DB $output;
close DB; # automatically removes file lock
@db_cols = @work_cols;
$db_file_name = $work_db;
Quote Reply
Re: [Helpdesk] Append to 2nd DB using info from add form [update] In reply to
Are you just basically trying to get the Ticket information from database B to display in A. If so, this could be done without it actually being added to the database.

Is there going to be many tickets for each corresponding record in "A". It's hard to tell exactly what you are doing without seeing how the databases are related other than by the ID.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Append to 2nd DB using info from add form [update] In reply to
Louis,

Yes, there will be many ID's associated with each record in 'tickets.db'. So, the information probably does need to be stored in the field in tickets.db.

What I have is a field in ticket.db in which ID's from work.db can be entered into it. xxxx,xxxx,xxxx Is an example for 3 ID's. Then on the record display from tickets.pl it breaks apart each of the ID's so they are clickable.

So, I need the add_record_success in work.pl to add the ID that was just added to work.db to the field in tickets.db for the associed record with ID (in tickets.db) to the number entered into field 'Ticket' on the add form in work.pl.

Does this make sense?
Quote Reply
Re: [Helpdesk] Append to 2nd DB using info from add form [update] In reply to
I'll give you an example of something I use and perhaps this will provide a solution. This is from a classifieds system which has 7 databases. When I view a User from the user databasewant I use the following to display all the ads within the other 6 databases. This is just an example of one.

print qq|
<table width=450><TR><TD><$font><B>Current Classifieds:</B></font></TD></TR>|;

&switch_to_announce;
undef %in;
$in{'UserID'} = $rec{'UserID'};
$in{'mh'} = 50;

my ($status2,@hits2) = &query("view");
if ($status2 eq "ok") {
my ($numhits2) = ($#hits2+1) / ($#db_cols+1);

for (0 .. $numhits2 - 1) {
%rec2 = &array_to_hash($_, @hits2);
print qq| <TR><TD><$font><A HREF="$db_script_url?db=announce&uid=$db_uid&ItemID=$rec2{'ItemID'}&view_records=1">$rec2{'ItemID'}</A> - $rec2{'Category'} - $rec2{'Title'}</font>&nbsp;</td></tr> |;
}
}

print qq|</table></CENTER><P>|;

Something like this would provide the display you are looking for without having to store the ID numbers and then make links. The above provides links automatically.

Hope this helps

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Append to 2nd DB using info from add form [update] In reply to
This would work for the solution of not having to store the numbers in the database. But, I would actually prefer to store them there so that I can directly reference them if necessary. Although I may still consider just displaying them.

However, I still need to change the modification date on the other record. (sorry I forgot to mention that before even though it was in my code) So, I still need to update that record whether or not the numbers are stored in the database.
Quote Reply
Re: Append to 2nd DB using info from add form [update] In reply to
Does anyone have any ideas on this?
Quote Reply
Append to 2nd DB using info from add form [update] In reply to
Ok, I found a solution for now via a form button, code below. However, can I automate this now so that I don't have to click the form button and the field is automatically updated?

Add_Success
Code:
&switch_cols_to_tickets;
print qq|<form action="$db_script_url" method="POST"><input type=hidden name="db" value="tickets"><input type=hidden name="uid" value="$db_uid">|;
&ticket_record(&get_record($in{Ticket}));
print qq|<INPUT TYPE="SUBMIT" NAME="modify_record" VALUE="Add to Ticket"></form>|;
&switch_cols_to_work;

sub ticket_record
Code:
my (%rec) = @_;
($db_auto_generate and print &build_html_record_form(%rec) and return);

$work .= $rec{'Work'} . ",$in{'ID'}";
print qq|
<INPUT TYPE="hidden" NAME="AddedBy" VALUE="$rec{'AddedBy'}">
<INPUT TYPE="hidden" NAME="CreateDate" VALUE="$rec{'CreateDate'}">
<INPUT TYPE="hidden" NAME="ID" VALUE="$rec{'ID'}">
<INPUT TYPE="hidden" NAME="ModifyDate" VALUE="$in{'Date'}">
<INPUT TYPE="hidden" NAME="RefName" VALUE="$rec{'RefName'}">
<INPUT TYPE="hidden" NAME="ID" VALUE="$rec{'ID'}">
<INPUT TYPE="hidden" NAME="Userid" VALUE="$rec{'Userid'}">
<INPUT TYPE="hidden" NAME="Requestor" VALUE="$rec{'Requestor'}">
<INPUT TYPE="hidden" NAME="Phone" VALUE="$rec{'Phone'}">
<INPUT TYPE="hidden" NAME="Email" VALUE="$rec{'Email'}">
<INPUT TYPE="hidden" NAME="Description" VALUE="$rec{'Description'}">
<INPUT TYPE="hidden" NAME="Work" VALUE="$work">
<INPUT TYPE="hidden" NAME="Resolution" VALUE="$rec{'Resolution'}">
<INPUT TYPE="hidden" NAME="Status" VALUE="$rec{'Status'}">
|;