Create a record from one database to another

Create a record from one database to another

by Tobias Cock -
Number of replies: 4

Hi,

I am trying to create a link between two databases as I need a one to many relationship.

As an example, "database 1" will consist of student names, contact info etc. Whereas "database 2" will consist of teachers interactions with students, i.e. meetings, telephone calls, email etc.

What I am trying to achieve is to allow teachers to add a new “interaction activity” in database 2 from the single view page of the database 1 record by clicking on a link on the single view page.

When clicking on the link the teacher should be taken to the “Add entry” page in database 2. Additionally, the student name from the database 1 record should automatically be pre-populated into the new record. The purpose of this is to establish a link between the two records in database 1 and 2.

What I have done so far is to create one link in the html template for the single view in in database 1 that will take them to the “add entry” page in database 2. However I am not able to pass the student name over, thus the teacher has to manually enter it every time, and if they make a spelling mistake the “link” between the two databases are broken. I have tried to pass the student name to the database 2 using url parameters. i.e. (http://ims.jsc.no/moodle/mod/data/edit.php?d=99&FirstName=Thomas&LastName=Brown)

But this does not workL

Any advice on how to pass field data from one database to another (using url parameters or by other means) would be very much appreciated.  

PS! I am using Moodle 1.9.5+,

Thanks
Tobias

Average of ratings: -
In reply to Tobias Cock

Re: Create a record from one database to another

by Itamar Tzadok -

You can try adding javascript in database 2 that is called in edit entry view and extracts the student's name from the url and enters it to the designated input field of the entry.

When you upgrade to Moodle 2 try the Dataform.

hth smile

In reply to Itamar Tzadok

Svar: Re: Create a record from one database to another

by Tobias Cock -

Thank you very much for the info Itamar!

As I am not very familiar with how to write javascripts, do you know if there is any pre-exisiting scripts avaialble that I can use.

Thanks,
Tobias 

In reply to Tobias Cock

Re: Svar: Re: Create a record from one database to another

by Itamar Tzadok -

There is always someone who's done something similar or asked about it. You probably won't find find a script which would plug&play for your purpose, but you can get fairly close.

Just google

javascript extract arguments from url

or something similar.

In principle you use location.search to get the query part of the url  (see http://www.w3schools.com/jsref/prop_loc_search.asp) then split by '&' to get an array of the arguments, then iterate the array and split each item by '=', and if the left side (first item of the split) is the desired argument (e.g. uname) you take the right side (second item of the split) and assign it to the value property of the designated field which you should be able to get by something like document.getElementById(##fieldname:id##).

But if you don't do javascript you will need someone to write it for you. smile

In reply to Itamar Tzadok

Svar: Re: Svar: Re: Create a record from one database to another

by Tobias Cock -

Thanks for the clarificationsmile

I will contact a freelance developer and see if he/her can help me out on this.