CRM and CX Blogs by Members
Find insights on SAP customer relationship management and customer experience products in blog posts from community members. Post your own perspective today!
cancel
Showing results for 
Search instead for 
Did you mean: 
This Blog post should give you an idea about how to read CRM survey question/answers value in ABAP code stored against a business transaction and validate the combinations.

 

The Business requirement was to convert the CRM Survey XML and read the Questions & answers on the survey  and validate it, if transaction is saved on a particular status. If validation fails then throw error message and prevent saving of the transaction.

 

  1. Each CRM Survey question/answer has a default technical value attached to it which can be changed as per Business requirement by enabling expert mode via transaction (CRM_SURVEY_SUITE ). This technical value will be used to validate the questions/answer


 



 



 

2. Attach the survey to the respective Business transaction via SPRO configuration.

 

3.Redefine your trigger point where you want to put the validation, In my case the requirement              was to not to allow the transaction to be saved to ‘Qualified’ status from the UI if the answers              combinations are not valid.

 

iv_survey_id             = Survey Name ( used to create survey in CRM_SURVEY_SUITE)

iv_oppotunity_guid  = Transaction guid

DATA: lit_question_ids       TYPE crm_svy_api_xml_t,
wa_question_id         TYPE string,
lit_answer_ids         TYPE crm_svy_api_xml_t,
wa_answer_ids          TYPE string,
wa_questionnaire       TYPE survy_s_all_values,
lt_questionnaire       TYPE survy_t_all_values,
lt_survey_values_table TYPE survy_t_all_values,
lt_no_display          TYPE crm_svy_api_parameter_t,
lv_object_guid         TYPE crmt_object_guid.

DATA: lv_guid          TYPE crmt_object_guid,
lt_survey        TYPE crmt_survey_comt,
ls_survey        TYPE crmt_survey_com,
lr_survey_values TYPE REF TO  cl_crm_svy_values,
ls_xml_string    TYPE string.

CHECK iv_oppotunity_guid IS NOT INITIAL AND iv_survey_id IS NOT INITIAL.
CALL FUNCTION 'CRM_SURVEY_READ_OW'
EXPORTING
iv_guid                       = iv_oppotunity_guid
iv_kind                       = 'A'
IMPORTING
et_survey_com_latest_version  = lt_survey
EXCEPTIONS
parameter_error               = 1
record_not_found              = 2
at_least_one_record_not_found = 3
OTHERS                        = 4.
IF sy-subrc = 0.

DELETE lt_survey WHERE surveyid <> iv_survey_id.
CHECK lt_survey IS NOT INITIAL.

READ TABLE lt_survey INTO ls_survey INDEX 1.
DATA(lv_xml) = ls_survey-valuexml.

IF lv_xml IS INITIAL.
CALL FUNCTION 'CRM_SVY_VALUES_READ'
EXPORTING
valueguid    = ls_survey-valueguid
valueversion = ls_survey-valueversion
status       = 'C'
IMPORTING
x_value_xml  = lv_xml.
ENDIF.

CALL FUNCTION 'CRM_SVY_DB_CONVERT_HEX2STRING'
EXPORTING
x = lv_xml
IMPORTING
s = ls_xml_string.

CREATE OBJECT lr_survey_values
EXPORTING
i_internal_values_xml   = ls_xml_string
EXCEPTIONS
error_in_generation     = 1
error_in_parsing        = 2
error_in_transformation = 3
OTHERS                  = 4.

" get all questions & their answers
CALL METHOD lr_survey_values->values_get_all
IMPORTING
et_all_values = lt_survey_values_table.

IF lt_survey_values_table[] IS NOT INITIAL.
yt_survey_values[] = lt_survey_values_table[].
ENDIF.

ENDIF.

Debugger snapshot of survey values table which shows all questions/answers combinations filled in the Survey( these are the technical value provided at the time of survey creation in Step 1)

 



 

Now validate this table entries against your possible combinations and prevent saving of the transaction, In my case we maintained the possible combination in the BRF+ framework.

 

Also, there are lot of other useful methods in standard class 'CL_CRM_SVY_VALUES' which can be utilised as per business requirement such as hiding questions,updating the answers or adding mandatory questions etc.