Sequential number for entries

Sequential number for entries

by JF Dragon -
Number of replies: 8

Hi all,

I'm on Moodle 2.7 and I would like to know if it could be possible to automaticaly add a sequential number to all entry. As I see in the documentation, it's seem to be impossible from the default database parameters to add such sequential number.

I look at the past forums posts and found that one, but it seem to be impossible with this solution to get a unique sequential number for all the entries.

BTW, I know nothing in JavaScript, but I imagine it will be a tool that could solve my problem.

Thanks!

JF


Average of ratings: -
In reply to JF Dragon

Re: Sequential number for entries

by Marie Waterhouse -

Hello JF

I have the exact same question and also know nothing about coding however a friend showed me the following example as a guide.

I am attempting to see how this could fit in with my database template. Will let you know if I have any luck. I wanted to have a unique ref number for each entry so that people could report any problems with specific database entries.

The only other way I could think of getting around the problem was to make use of the template action ##timeadded## as a unique ref.

Best wishes

Marie

Average of ratings: Useful (1)
In reply to Marie Waterhouse

Re: Sequential number for entries

by JF Dragon -

Thanks Marie for your answer...

The problem I see with the JS you found is that this code will work OK for the entries on one page, but the sequential number will not be link to the entry itself and on the next page the numbers will restart at «1».

But your idea to take the ##timeadded## field as unique ref could be the solution. If it could be possible to convert the entry date in sequential number with JS, then we should have our solution. But after saying that, I don't know how to do that. smile

Have a nice day...

JF

In reply to JF Dragon

Re: Sequential number for entries

by Steve Ambro v3.8 -

I don't know enough about Moodle database yet and I do not see this mentioned here but on every database system that I have programmed, it had an "autonum" attribute that was selected for a field.  Is this not found in Moodle Database?

In business, autonum is used for employee#, customer#, Invoice#.

Just a thought....

In reply to JF Dragon

Re: Sequential number for entries

by Iain Moore -

Hi,

I'm looking for this to use in a client list style database. When I imported my entries the results screen gives:

Added 1. Entry (ID 5081)
 Added 2. Entry (ID 5082)
 Added 3. Entry (ID 5083)
 Added 4. Entry (ID 5084)....

How do I get to this entry ID...

I also notice that that number appears in the url when I open a particular record.

.... mod/data/edit.php?d=21&rid=5081 ....

I take it this is Database 21 and record id 5081.

How can I get to this number to put is into the record?

I think it would have to be calculated from the record ID before because the record your then creating wont exist yet.

Iain

In reply to Iain Moore

Re: Sequential number for entries

by Steve Ambro v3.8 -

Let me see if I understand this because I do spy a kind of hope.

You are importing records. 
The system is assigning and showing IDs
and later you can see the ID in the URL.

At what point do you need to know the ID? Before, During or After?  For another process, I am looking into how to read the URL and to use code to pull out the ID.  I will post the code when I solve for it.


In reply to Steve Ambro v3.8

Re: Sequential number for entries

by Iain Moore -

OK...

The process was

After importing records from a .csv, Moodle gives confirmation of the import in the format:

Added 1. Entry (ID 5422)

...

Added 341. Entry (ID 5762)


I noted that the (ID ****) number is in the URL when I opened the now imported record:

moodle."college name".ac.uk/mod/data/view.php?d=24&rid=5422


This tells me that Moodle gives the records a unique id and uses it to find and open the record.


When creating a new record I would like the look up the previous entry and add 1 to give an auto number to the new record. I'm not especially trying to make them match. It just might be a convenient unique number generator.

In reply to Iain Moore

Re: Sequential number for entries

by AL Rachels -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

I would NOT recommend trying to manually manipulate any ID numbers in Moodle. The various parts of core code and the program for each plugin along with the Moodle database takes care of those numbers automatically for you so it can "find" what is needed, when it's needed. In the database activity, there are four different tables, and it is the various ID numbers that tie the different tables together. In the mdl_data_records table alone, there are four of these id fields, id, userid, groupid, and dataid. If you start trying to manipulate the value of those numbers, you run the risk of seriously breaking your Moodle.

If you would like to have a record number shown as part of each entry on the list view, single view, etc. you might be able to create a Genrico filter that could automatically show you the correct record number once you add an entry.

In reply to AL Rachels

Re: Sequential number for entries

by Steve Ambro v3.8 -


I don't think the intent was to manipulate ID numbers from Moodle per se and I believe that one could not write to that column at all.  In major systems, it would be impossible because it is a read-only column.

It looked that the intent was to a create a column, call it MyID,  in a database as reference numbers stemming from the ID number.  This would be totally isolated from Moodle ID numbers. 

Granted, even if you could, adding an actual Moodle ID number manually would be dangerous if not destructive.  I remember when I broke my Moodle on a totally different situation.  It was painful but at least I was the only using it in the first place   (:

I am still trying to see what the original intent was supposed to be.
Maybe a Generico filter would work.