new web service giving "Can not find data record in database table external_functions"

new web service giving "Can not find data record in database table external_functions"

by Pradeep Kandoth -
Number of replies: 10

Hi I created a web service doing the following :

1. Externallib in mod/questionnaire

   has :

<?php
require_once("$CFG->libdir/externallib.php");
class moodle_questionnaire_external extends external_api {


public static function get_questinnaires_parameters() {
return new external_function_parameters (
array(
'courseid'=> new external_value(PARAM_INT, 'id of the course')
)
);
}


public static function get_questionnaires_returns () {
return new external_multiple_structure (
new external_single_structure ( //This is used to represent a single activity.
array(
'id'=> new external_value(PARAM_INT,'The id of the activity'),
'name' => new external_value(PARAM_TEXT,'The name of the activity')
)
)
);
}

public static function get_questionnaires($courseid)
{
global $CFG, $DB;
$params = self::validate_parameters(self::get_questionnaire_parameters(),
array('courseid' => $courseid)
);
$sql = 'select id,name from '. $CFG->prefix.'questionnaire where course='.$courseid;
$rets = array();
$qs= $DB->get_records_sql($sql);
foreach($qs as $q)
{
$ret= array();
$ret["id"]= $q->id;
$ret["name"]=$q->name;
$rets[] = ret;
}
return $rets;
}
}

?>

 

added 

to lib/db/services.php in 

'moodle_course_get_questionnaires' => array(
'classname' => 'moodle_questionnaire_external',
'methodname' => 'get_questionnaires',
'classpath' => 'mod/questionnaire/externallib.php',
'description' => 'Return questionnaire details',
'type' => 'read',
'enabled'=>1,
),

but when i try accessing the service 

 

$function='moodle_course_get_questionnaires';
//$params= array('courseid'=>$courseid);;
$params= $courseid;
$response =$testclient->simpletest($serverurl, $function, $params);

 

i get the error "Can not find data record in database table external_functions" 

 

What steps am i missing out. any help will be greatly appreciated

 

 

Average of ratings: -
In reply to Pradeep Kandoth

Re: new web service giving "Can not find data record in database table external_functions"

by Netram Dhakar -

Hi Pradeep,

You might have to manually make an entry in database table "external_functions" with your newly created function. Then you can get ride from this error. There are following fields in the above mentioned table:

id
name
classname
methodname
classpath
component
capabilities

 

Cheers

Netram Dhakar

Average of ratings: Useful (1)
In reply to Netram Dhakar

Re: new web service giving "Can not find data record in database table external_functions"

by Patrick Pollet -

@Pradeep,

      I also noticed that your function public static function get_questinnaires_parameters() { is mispelled

it should be public static function get_questionnaires_parameters() {

Cheers

Average of ratings: Useful (1)
In reply to Patrick Pollet

Re: new web service giving "Can not find data record in database table external_functions"

by Pradeep Kandoth -

@ Patrick Pollet,@netram Dhakar  thanxs changed the spelling and added to database.  but when i go the add function in plugin external services  the whole page goes blank. What is wrong now ?

In reply to Pradeep Kandoth

Re: new web service giving "Can not find data record in database table external_functions"

by Netram Dhakar -

Hi Pradeep,

Please enable moodle debugging then you can figur out What is the the error.

Cheers

Netram Dhakar

Average of ratings: Useful (1)
In reply to Netram Dhakar

Re: new web service giving "Can not find data record in database table external_functions"

by Pradeep Kandoth -

Now i am getting the following error 

cURL request for "http://localhost:81/moodle/webservice/rest/server.php?wstoken=0792a48fa0c388fcd8c835e5ba25ecd9&wsfunction=moodle_course_get_questionnaires" failed, HTTP response code: HTTP/1.0 500 Internal Server Error

  • line 1141 of \lib\filelib.php: call to debugging()
  • line 185 of \webservice\rest\locallib.php: call to download_file_content()
  • line 104 of \webservice\rest\nt.php: call to webservice_rest_test_client->simpletest()

warm regards

pradeep

In reply to Patrick Pollet

Re: new web service giving "Can not find data record in database table external_functions"

by Pradeep Kandoth -

i've inserted  

moodle_course_get_questionnaires,moodle_questionnaire_external,get_questionnaires,mod/questionnaire,moodle,''    into the table 

In reply to Pradeep Kandoth

Re: new web service giving "Can not find data record in database table external_functions"

by Pradeep Kandoth -

For those of you who are struggling these are the mistakes i've made so far

 

1. Spelling wrong  between param,implementation and result.

2. Record not inserted into 'external_functions' table.

3. Record  inserted wrongly 'classpath' column has to contain the complete file name.

I am still stuck on the last problem will get back as soon as the solution is found

In reply to Pradeep Kandoth

Re: new web service giving "Can not find data record in database table external_functions"

by Jérôme Mouneyrac -

Hi,

to add a web service function in Moodle, you need to increment the version.php. In your case you put the services.php in the lib folder, so you would need to increment the root version.php. However you should put your services.php into mod/questionnaire/db/services.php. And then increment mod/questionnaire/version.php.

PS: when Moodle detects a version.php change, Moodle automatically triggers an upgrade. The upgrade system will check if db/services.php exists, and will automatically update the service information into the database. You don't need to edit anything in your database.

Average of ratings: Useful (1)
In reply to Jérôme Mouneyrac

Re: new web service giving "Can not find data record in database table external_functions"

by Jocelyn Ireson-Paine -

Hi Jerome,

In Creating a web service and a web service function, there's an example that shows how to add a new Web-service function for creating a group. This example declares the function by updating the $functions array in /lib/db/services.php . However, you suggest that Pradeep should update mod/questionnaire/db/services.php , presumably because his function does things with questionnaires. Which is best?

I ask because I want to do two things with Web services, and having read your reply, I now don't know which services.php to change. First, I want to implement the Hello World function mentioned in Creating a web service and a web service function. That's as an experiment, to get me started. Second, I want to implement a function that copies course-backup files into new courses, by calling call import_backup_file_silently from /backup/lib.php . Should I update $functions in /lib/db/services.php , or elsewhere? If the latter, where? Are there any conventions about this?

It would be simplest, I suppose, if we could just update a services.php somewhere under /local/ . That would avoid tampering with any existing Moodle code, and so make installing new Moodle versions safer.

By the way, Creating a web service and a web service function  doesn't tell us to increment the version.php . Must we always do this when adding a Web-service function?

Jocelyn

In reply to Jocelyn Ireson-Paine

Re: new web service giving "Can not find data record in database table external_functions"

by Jérôme Mouneyrac -

Hi Jocelyn,
thanks for your question. We are currently working on explaing plugins (MDLSITE-1661). 

Plugins are:

- module ( => /mod/xyz/)
- enrolment plugin (=> /enrol/xyz/)
- authentication plugin (=> /auth/xyz/)
- ... http://docs.moodle.org/dev/Frankenstyle#Plugin_types
- local plugin ( => /local/xyz/) 

Always put /db/services.php into the /xyz/ folder. For your example I suggest to create a local plugin. Local plugins are for things that are not module/enrolement/authentication/... So you guessed right smile

About web services, two new docs are available for web services: http://docs.moodle.org/dev/Web_services_API and http://docs.moodle.org/dev/External_functions_API

Average of ratings: Useful (1)