Totara Learn Open Discussions

Include Custom Attributes in core_course_get_courses Response

 
Paul Widenka
Include Custom Attributes in core_course_get_courses Response
by Paul Widenka - Wednesday, 10 August 2022, 1:22 PM
 

Hello!

Can someone please point me to or advise on how we include our custom attributes into a web service response payload?

I have added custom attributes to Course and can see them on the Course pages.

When I call wsfunction=core_course_get_courses i still only see the default attributes in my json response.

Many thanks,

Paul

Olumuyiwa Taiwo
Re: Include Custom Attributes in core_course_get_courses Response
by Olumuyiwa Taiwo - Monday, 22 August 2022, 12:03 AM
Group Partners

Hi Paul

The function behind that WS function is the function get_courses() in server/course/externallib.php. You'll see that the function returns a specific set of fields (which I believe are the core fields). Custom fields are not included.

What you are after seems like it should be expected behaviour, so you might consider submitting a feature request.

In case someone from Totara is reading this, there is a bug the file I referred to above (in TXP15, I haven't checked other versions).

The file is littered with SQL statements like 'SELECT <blah> FROM "ttr_course" ...'

Hard-coding the table prefix in SQL queries will make affected functions have unexpected results on sites that don't use 'ttr_' as the prefix.

Tom Wood
Re: Include Custom Attributes in core_course_get_courses Response
by Tom Wood - Monday, 22 August 2022, 2:18 AM
Group Totara

Hi Olumuyiwa,

The ttr_ prefix is a special one and will be replaced with the one configured in the config.php as normal. It was introduced to provide an easier way for developers to copy SQL and run it directly on the databases without having to manually replace the prefix. It's purely for developers and should all work well for sites using a different prefix.

Hope this helps :).

Thanks

Tom