During my recent prototype development I have developed some UI5 application which displays the survey questions in mobile phone, and it's more convenient for end users to fill the survey in mobile phone( instead of using CRM Webclient UI in their laptop) and submit the result to CRM backend system.
In my prototype the API works well - many users have filled the survey and submitted via mobile phone. Now I log on CRM WebClient UI using business role "MarketingPro" to review survey result by pressing button "Evaluate":
Here below is the sample data of my customers' survey feedback:
When I displayed the result via Pie chart, I found the pie chart display is not working as I expect.
What I want is: for each dedicated question, display each answer with its vote number. For example, for question1, 30% of users have filled with answer "one week ago" and 70% "one month ago". My survey form has six questions which means I would like to display six pie charts in the same page.
So I plan to develop my own chart display logic. Here below is detailed step.
Step1: develop CDS view to extract survey result from CRM DB table
CDS view 1: zsurvey_value_guid
This view extracts the dedicated survey result data which belongs to my survey template 'ZDIS_SERVICE_FEEDBACK'.
@AbapCatalog.sqlViewName: 'zsurveyguid'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Value guid for a given Survey version'
@ClientHandling.algorithm: #SESSION_VARIABLE
define view zsurvey_value_guid
as select from crm_svy_db_svs as tguid {
key tguid.valueguid as guid,
tguid.surveyversion as version
} where surveyid = 'ZDIS_SERVICE_FEEDBACK'and surveyversion = '0000000011';
CDS view 2: zsurvey_value_raw
This view is responsible to expose only those fields related to survey question and survey answer from CRM survey DB table which I really would like to display in my own chart:
@AbapCatalog.sqlViewName: 'zsurveyraw'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Raw survey value'
@ClientHandling.algorithm: #SESSION_VARIABLE
define view zsurvey_value_raw as select from zsurvey_value_guid as tguid inner join
crm_svy_db_sv as detail on tguid.guid = detail.valueguid {
key tguid.guid,
tguid.version,
detail.name as question,
detail.value as answer
}
CDS view 3: zsurvey_value_agg
@AbapCatalog.sqlViewName: 'zsurveyagg'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Survey value aggregated'
define view zsurvey_value_agg as select from zsurvey_value_raw as raw {
key raw.question,
substring( raw.question, 2,1) as question_index,
raw.answer,
count(*) as answer_count
} group by question, answer
This view is responsible to calculate the occurance of each answer belonging to each question.
The output of it:
Just compare this output with the table display in the survey result view of CRM WebClient UI to ensure the data are exactly the same:
Step2: develop an API to consume the CDS view
I plan to display the data from my CDS view in a BSP application, so I have to convert the data from my CDS view to a JSON string.
The conversion could be found from my API ZCL_CRM_SURVEY_TOOL~GET_SURVEY_ANSWER( source code in my
github ).
The JSON string has the following format when opened in JSON Editor:
Step3: display the JSON data in BSP application
Create a new BSP application with a new index.html page, call API to get the JSON string from CDS view in step one.
Use JSON.parse to deserialize this JSON string to JSON object and render it as chart:
The complete source code of index.html could be found from my
github.
This is the final result of survey result displayed in my own chart: