cancel
Showing results for 
Search instead for 
Did you mean: 

BAPI_LEAD_CREATEMULTI - with surveys

Former Member
0 Kudos

somebody knows like enclosing a survey to lead?

use ' BAPI_LEAD_CREATEMULTI ' but does not create the document of surveys.

thanks

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hello. I have this same problem. We need a RFC function module where user can enter a lead description and survey answers. Then lead with filled in description and survey with filled in answers get created in CRM and linked together. I debugged crmd_bus2000108. Here is my solution( it is a little test program for now but it works ). You can determine input values for your case for FMs using debugging. Procedure:

-create lead using CRM_ORDER_MAINTAIN_MULTI_OW

-create survey and populate the data( like on evaluation tab of lead ) using object cl_crm_svy_runtime.

-link survey to existing lead using CRM_ORDER_MAINTAIN_MULTI_OW

-save lead with CRM_ORDER_SAVE

-commit changes with BAPI_TRANSACTION_COMMIT

Code:


*&---------------------------------------------------------------------*
*& Report  Z_TEST_LEAD_SURVEY
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  z_test_lead_survey.
DATA: o_survey_runtime TYPE REF TO cl_crm_svy_runtime,
      o_surveyvalues TYPE REF TO cl_crm_svy_values,
      t_application_params TYPE crm_svy_api_parameter_t,
      t_all_values TYPE survy_t_all_values.

DATA: survey_data TYPE string,
      valuexml TYPE string,
      valuexml_hex TYPE xstring.

DATA: lead_guid TYPE guid_32,
      lead_id TYPE crmt_object_id,
      valueguid TYPE crm_svy_db_sv_guid,
      valueversion TYPE crm_svy_db_sv_vers.

DATA: s_lead_h TYPE crmt_lead_h_com,
      t_lead_h TYPE crmt_lead_h_comt,
      s_orderadm_h TYPE crmt_orderadm_h_com,
      t_orderadm_h TYPE crmt_orderadm_h_comt,
      s_field_names TYPE crmt_input_field_names,
      t_field_names TYPE crmt_input_field_names_tab,
      s_input_fields TYPE crmt_input_field,
      t_input_fields TYPE  crmt_input_field_tab,
      s_objects_to_save TYPE crmt_object_guid,
      t_objects_to_save TYPE crmt_object_guid_tab,
      s_saved_objects TYPE crmt_return_objects_struc,
      t_saved_objects TYPE crmt_return_objects,
      s_survey TYPE crmt_survey_com,
      t_survey TYPE crmt_survey_comt.

**********************************************************************
*                     CREATE LEAD
**********************************************************************
* Fill required structures
s_orderadm_h-object_id = 'BUS2000108'.
s_orderadm_h-process_type = 'ZLEA'.
s_orderadm_h-description = 'TEST LEAD - DENEB'.
APPEND s_orderadm_h TO t_orderadm_h.

s_input_fields-ref_kind = 'A'.
s_input_fields-objectname = 'LEAD_H'.
APPEND s_input_fields TO t_input_fields.

s_input_fields-ref_kind = 'A'.
s_input_fields-objectname = 'ORDERADM_H'.
*Subtable FIELD_NAMES
s_field_names-fieldname = 'DESCRIPTION'.
APPEND s_field_names TO t_field_names.
*/Subtable FIELD_NAMES
s_input_fields-field_names = t_field_names.
APPEND s_input_fields TO t_input_fields.

s_lead_h-lead_type = '0007'.
APPEND s_lead_h TO t_lead_h.

* Create lead
CALL FUNCTION 'CRM_ORDER_MAINTAIN_MULTI_OW'
  EXPORTING
    it_lead_h             = t_lead_h
    iv_collect_exceptions = ''
  CHANGING
    ct_orderadm_h         = t_orderadm_h
    ct_input_fields       = t_input_fields
  EXCEPTIONS
    error_occurred        = 1
    document_locked       = 2
    no_change_allowed     = 3
    no_authority          = 4
    OTHERS                = 5.
IF sy-subrc <> 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

* Get GUID of created LEAD for later saving
READ TABLE t_orderadm_h INTO s_orderadm_h INDEX 1.
s_objects_to_save = lead_guid = s_orderadm_h-guid.
APPEND s_objects_to_save TO t_objects_to_save.

* Potrdi spremembe
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

**********************************************************************
*                     CREATE SURVEY SURVEY
**********************************************************************
* Create survey answers input string
CONCATENATE 'svyApplicationId=CRM_SURVEY_LEAD'
            '&SurveyId=ZNEW_LEAD_FORM_SISVSAP'
            '&svySurveyId=ZNEW_LEAD_FORM_SISVSAP'
            '&svyVersion=0000000003'
            '&SchemaVersion=1'
            '&svySchemaVersion=1'
            '&svyLanguage=EN'
            '&conid='
            '&survey/result/address/name1=Deneb Debelak'
            '&survey/result/address/street=Tekstilna 17a'
            '&survey/resultaddress/postalcode=4000'
            '&survey/result/address/city=Kranj'
            '&survey/result/address/region=Gorenjska'
            '&survey/result/address/phone=041966493'
            '&survey/result/address/fax=Nimam'
            '&survey/result/address/email=d.debelakhotmail.com'
            '&survey/result/address/uri=http://www.nimam.com'
            '&survey/result/bankdetails/bankcountry=Slovenija'
            '&survey/result/bankdetails/bankkey=1234'
            '&survey/result/bankdetails/bankaccount=78238348238328'
            '&survey/result/id_ddb164f9ec715ef1acf9001b7840a5e4/id_ddbc6515052e00f1acf9001b7840a5e4=Kr neki 1'
            '&survey/result/id_ddb164f9ec715ef1acf9001b7840a5e4/id_ddbc65a01ff500f1acf9001b7840a5e4=Kr neki 2'
            '&survey/result/id_ddb16f9ec715ef1acf9001b7840a5e4/id_ddbc66812b7273f1acf9001b7840a5e4=id_ddbc66872638c2f1acf9001b7840a5e4'
            '&survey/result/id_ddb164f9ec715ef1acf9001b7840a5e4/id_ddb165018f99b4f1acf9001b7840a5e4=Kr neki 3'
            '&survey/result/id_ddb164f9ec715ef1acf9001b7840a5e4/id_ddb1682cf66426facf9001b7840a5e4=Kr neki 4'
            '&survey/result/id_ddb16650885482f1acf9001b7840a5e4/id_ddb1666f95b6daf1acf9001b7840a5e4=Kr neki 5'
            '&survey/result/id_ddb16650885482f1acf9001b7840a5e4/id_ddb1671399e9c2f1acf9001b7840a5e4=Kr neki 6'
            '&survey/result/id_ddb16650885482f1acf9001b7840a5e4/id_ddb166a505462f1acf9001b7840a5e4=Kr neki 7'
            '&survey/result/id_ddb16650885482f1acf9001b7840a5e4/id_ddb166bcdef443f1acf9001b7840a5e4=Kr neki 8'
            '&survey/result/id_ddb16650885482f1acf9001b7840a5e4/id_ddb166d6b77e3ff1acf9001b7840a5e4=Kr neki 9'
            '&survey/result/id_ddb16650885482f1acf9001b7840a5e4/id_ddbd38c6829df9f1acf9001b7840a5e4=THE END'
            '&onInputProcessing(SUBMIT)=Save'
       INTO survey_data.

* Create survey runtime object
CREATE OBJECT o_survey_runtime
  EXPORTING
    i_runtime_mode   = 'INBOUND'
    i_application_id = 'CRM_SURVEY_LEAD'
    i_survey_id      = 'ZNEW_LEAD_FORM_SISVSAP'
    i_survey_version = '0000000000'
    i_language       = 'E'
    i_media_type     = '01'
    i_valueversion   = '0000000000'
    i_no_value_save  = ''.

* Save survey answers
o_survey_runtime->set_values( EXPORTING i_survey_data = survey_data
                              IMPORTING e_valueguid = valueguid
                                        e_valueversion = valueversion
                                        et_application_params = t_application_params ).

* Get survey values object
o_survey_runtime->get_values( IMPORTING er_survey_values = o_surveyvalues ).

* Get XML values - filled out in previous call
o_surveyvalues->get_internal_values_xml( IMPORTING e_internal_values_xml = valuexml
                                                   e_internal_values_xml_hex = valuexml_hex ).

**********************************************************************
*                     LINK SURVEY WITH LEAD
**********************************************************************
* Fill required structures
CLEAR t_input_fields.
s_input_fields-ref_guid = lead_guid.
s_input_fields-ref_kind = 'A'.
s_input_fields-objectname = 'SURVEY'.
*Subtable FIELD_NAMES
CLEAR: s_field_names, t_field_names.
s_field_names-fieldname = 'EVALUATION_INFOS'.
APPEND s_field_names TO t_field_names.
s_field_names-fieldname = 'SURVEYID'.
APPEND s_field_names TO t_field_names.
s_field_names-fieldname = 'SURVEYVERSION'.
APPEND s_field_names TO t_field_names.
s_field_names-fieldname = 'VALUEGUID'.
APPEND s_field_names TO t_field_names.
s_field_names-fieldname = 'VALUEVERSION'.
APPEND s_field_names TO t_field_names.
s_field_names-fieldname = 'VALUEXML'.
APPEND s_field_names TO t_field_names.
*/Subtable FIELD_NAMES
s_input_fields-field_names = t_field_names.
APPEND s_input_fields TO t_input_fields.

s_survey-ref_guid = lead_guid.
s_survey-ref_kind = 'A'.
s_survey-surveyid = 'ZNEW_LEAD_FORM_SISVSAP'.
s_survey-surveyversion = '0000000003'.
s_survey-valueguid = valueguid.
s_survey-valueversion = valueversion.
s_survey-valuexml = valuexml_hex.
s_survey-mode = 'A'.
APPEND s_survey TO t_survey.

* Link survey to lead
CALL FUNCTION 'CRM_ORDER_MAINTAIN_MULTI_OW'
  EXPORTING
    it_survey             = t_survey
    iv_collect_exceptions = ''
  CHANGING
    ct_orderadm_h         = t_orderadm_h
    ct_input_fields       = t_input_fields
  EXCEPTIONS
    error_occurred        = 1
    document_locked       = 2
    no_change_allowed     = 3
    no_authority          = 4
    OTHERS                = 5.
IF sy-subrc <> 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

* Save lead
CALL FUNCTION 'CRM_ORDER_SAVE'
  EXPORTING
    it_objects_to_save = t_objects_to_save
  IMPORTING
    et_saved_objects   = t_saved_objects
  EXCEPTIONS
    document_not_saved = 1
    OTHERS             = 2.
IF sy-subrc <> 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
READ TABLE t_saved_objects INTO s_saved_objects INDEX 1.
lead_id = s_saved_objects-object_id.

* Commit work
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

**********************************************************************
*                     WRITE GUIDs
**********************************************************************
WRITE: 'LEAD GUID:', lead_guid, /,
       'LEAD ID:', lead_id, /,
       'VALUE GUID:', valueguid, /.

Revard points if usefull.

Edited by: Deneb Debelak on Dec 11, 2008 3:21 PM

Former Member
0 Kudos

Hi,

We also tested creation of leads with BAPI_LEAD_CREATEMULTI and notice the survey is not there.

we considered then using BAPI_LEAD_ATT_CHANGE that contains the survey after a lead was created but then decided that we will create the lead with the BAPI but

after commit we are navigating to the qualification tab

in the CRMD_BUS2000108 BSP application.

hope this helps,

Eyal.

Former Member
0 Kudos

I do not understand it well. whereupon bapi could be loaded in the end?

he is that no longer that bapi to prove itself

thanks

Former Member
0 Kudos

after you executed BAPI_LEAD_CREATEMULTI you have to

execute BAPI_TRANSACTION_COMMIT then a Lead exists in your system with guid that you know from CREATED_PROCESS

so you can call the url:

http://<yourserver:port>/sap/bc/bsp/sap/crm_bsp_frame/entrypoint.do?appl=CRMD_BUS2000108&blview=<you...;

and if <yourview> has only the qualification tab this should work.

Eyal.

Former Member
0 Kudos

thaks