URL Resource - adding a URL Variable

URL Resource - adding a URL Variable

by John Provasnik -
Number of replies: 4
Picture of Particularly helpful Moodlers Picture of Testers

I want to make a URL that helps a student get to their course Outline report (found in their User Profile). 

I was going to add this URL to the top of the course. The URL is as such: 

https://moodlesite.com/report/outline/user.php?id=userid&course=course&mode=outline

My understanding is to place the start of the URL in the External URL box: 

Then, add in the URL variables. 

I used the Moodle docs and can only seem to get one of the two variables to append: 




However,  when I click save, it's only adds on the Course ID, even though User ID is first. When I re-edit the URL activity, the parameter becomes blank. 

Also, i dont know if it's possible to append the url (it needs &mode=outline at the end of the URL). 

Anyone have luck using this feature of the URL resource? 


Thanks,

Average of ratings: -
In reply to John Provasnik

Re: URL Resource - adding a URL Variable

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers
John, I am probably a bit off base with my reply, but I did take note of your URL that was having a problem.

A while ago, I posted this bug on Moodle Tracker. MDL-48726. It might be a little related to what you are trying to do since you are using the query string method of including a "?" in your URL.
Average of ratings: Useful (1)
In reply to John Provasnik

Re: URL Resource - adding a URL Variable

by Jon Bolton -
Picture of Particularly helpful Moodlers Picture of Testers
Ah, two issues here.

The main one is the parameters. What’s in your screenshot won’t work because both parameters are “id”.
The first needs to be “userid” and the parameter is user-id
The second needs to be “course” and the parameter is course-id
The url is correct, so that will definitely work (I’ve tested it).

The second problem is that the variables are appended to the end of the url so you can’t add the mode=outline bit 😕 but one workaround that I’ve used previously is to add a custom user profile field (hidden and locked) for report mode and then your third parameter can be mode 😀 You can update all users very quickly using
the bulk user upload spreadsheet and “fill in missing from file”.
Average of ratings: Useful (1)
In reply to Jon Bolton

[Solved] Re: URL Resource - adding a URL Variable

by John Provasnik -
Picture of Particularly helpful Moodlers Picture of Testers
Fantastic!
I'm on Moodle 3.5. I did a little trial an error with your instructions above (and maybe I was just still doing it wrong), but in the end:  
I used "id" as the parameter for the user id
I used "course" as the parameter for the course id.
I didn't end up needing to append the last bit on (&mode=outline), though making it a profile item was a great idea. Using just the other two bits of info, the link went right to the user outline report anyway, maybe due to the front end of the URL being .../report/outline...
Thank you so much. The docs weren't so clear so I'm going to add this thread into the URL Variables section. 

So, to summarize, this is the link that I wanted to be dynamic in the URL module:

https://moodlesite.com/report/outline/user.php?id=000000&course=0000&mode=outline

1. I set the External URL to: https://moodlesite.com/report/outline/user.php

2. Under URL variables, I set the following parameters to the following variables: 

  
and I ignored the final bit (jut to test out the passing of the two different IDs)

3. Then, I saved and this was the result (which brought me to the needed report):

   https://moodlesite.com/report/outline/user.php?id=00000&course=0000

What a great feature to have!
In reply to Jon Bolton

Re: URL Resource - adding a URL Variable

by John Provasnik -
Picture of Particularly helpful Moodlers Picture of Testers
To follow up, I did have to use "userid" when I tried to create another URL with a Variable, but in this case, the link actually did show "userid" and not just "id"

I added the example into the docs:
https:// moodlesite.com/grade/report/user/index.php?id=00000&userid=0000 is the path to a user's course user report
https:// moodlesite.com/grade/report/user/index.php is the base URL
?id=00000 is the first added parameter, so type id in the parameter box and in the dropdown select id under course
&userid=0000 is the second added parameter, so type userid in the parameter box and in the dropdown select id under user