Create custom metric type for surveys

Colin Chalmers
Tera Contributor

We are trying to create a custom metric type to add to a survey but the data is not being persisted.

 

We feel we are missing the step or config to map the metric type to a DB, the only information we can find on this is not very helpful so maybe someone else has better / clearer steps?

 

https://docs.servicenow.com/bundle/vancouver-servicenow-platform/page/administer/survey-administrati...

 

Can someone point me to a blog/tutorial for this?

 

Thanks in advance!

3 REPLIES 3

Lorenzo3
Tera Contributor

Hi @Colin Chalmers. I'm facing the same issue here, Did you find any solution for this?

MattCoscos
Tera Contributor

did you find any solution on this?

Paul58
Tera Contributor

I found the answer in this thread:
https://www.servicenow.com/community/developer-forum/create-custom-metric-type-in-surveys/m-p/306795...

In your client controller script make sure $scope is a parameter to your top level function and set the page field value somewhere in your client controller code.  

HTML:
<input type="text" class="form-control" placeholder="Enter employee name.." ng-model="c.data.employee" ng-change="c.update()">

 

Server script:

(function() {
  if (input) {
            var responseJson = new ScriptInclude().callApi(input.employee);
            data.answer = responseJson.data[0].email;
    }
})();
 

Client Controller:

api.controller=function($scope, spUtil) {
   var c = this;
   c.update = function() {
        c.server.update().then(function() {
            $scope.page.field.value = c.data.answer;
        });
    };
};