Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
Showing results for 
Search instead for 
Did you mean: 
Active Participant

Hello everyone! In this post, I hope to add some clarity and demystify how to create custom mail forms for ChaRM. There are a few posts on the topic, however I was not able to find all of the information that I needed in one place. With this post, I hope to make it easier for you to use Mail Forms.

In this scenario, we are generating mails forms in ChaRM for transaction types, ZMCR and in the Change Documents.

This post contains the following sections:

1. Creating custom fields to appear in the mail form

2. Maintain Attribute Contents for Mail Forms

3. Create a BADI to populate the fields

4. Create a Mail Forms containing standard and custom fields.

5. To maintain the HTML in the Mail Form directly

6. Add special fields to the form like….

     a) Insert a Company Logo

     b) Insert a hyperlink the the ChaRM

     c) Text Element Conditions

7. Test your changes

8. Update the Action and Conditions.

So here we go.  All screen shots are from 7.1 SP13.

Step 1) Creating custom fields to appear in the mail form

Create a custom structure containing the fields needed in your mail form. For example, this one contains business partners, textbox contents, and other fields.

Step 2) Maintain Attribute Contents for Mail Forms*

SPRO -> Customer Relationship Management -> Marketing -> Marketing Planning and Champaign Management -> Personalized
Mail -> Maintain Attribute Contexts for Mail Forms,

Create an attribute that will reference the new structure with “With no Marketing Attributes” and type = Not Relevant.

Select the new Attribute and assign the new structure selecting All Fields…

When you view the fields assigned, all of the fields in the structure should be displayed.

Note: I did encounter an issue when I was adding additional fields to the structure after it was in use. They did not always appear immediately in this list. This was because table CRMC_IM_FIELDS maintained via the view was not being updated on save. This took some trial and error. I needed to delete the attribute and re-add it and reactivate the table. It finally worked, but you may need patience. Another time when I updated the structure, the changes were immediately shown. Weird.

Step 3) Create a BADI to populate the fields

SPRO -> Customer Relationship Management -> Marketing -> Marketing Planning and Champaign Management -> Campaign Execution -> Badi: Maintain Additional Attributes for Mail Form Attribute Contents

This will create a BADI for definition CRM_IM_ADD_DATA_BADI. Assign the filter value to the name of the Attribute created in Step 2. Assign no type to the filter.

Here were the Attributes needed in the Class..

Here are the Types needed….

In method IF_EX_CRM_IM_ADD_DATA_BADI~CRM_IM_BPSELE, add the logic to populate the fields in the structure.

Being general, here is some high level logic. I trimmed out a lot of the logic for brevity, just so you would get the idea. But, if you have specific questions about how I populated by specific fields on my form, let me know and I’ll share more.

DATA:     lv_tabname           TYPE tabname,

lv_fieldname         tYPE fieldname,
ls_index             type SYTABIX,
ls_TJ30T             type tj30t,
ls_ct_att_value_temp type line of CRMT_IM_NAME_VALUE_TAB,
ls_ext_reference     type CRMT_PO_NUMBER_UC,

data: lt_tsocm_cr_context type table of tsocm_cr_context,
ls_tsocm_cr_context type tsocm_cr_context.

FIELD SYMBOLS:<fs_table_buffer>   TYPE ty_tables,               
<fs_att_value>      TYPE crmt_im_name_value,
<fs_table>          TYPE table,           
<fs_field>          TYPE any,
<fs_value>          TYPE any.

                 lc_CR_number        type string value 'CRMS_SRQM_GEN_FIELDS-CRM_SRQM_NUMBER',
                 lc_textid_longdesc  type TDID value 'CR01',

* 1) filter check
  If flt_val-SCENARIO ne lc_filtername.

* 2) ChaRM header data
  clear: ls_CRMD_ORDERADM_H.
  read table ct_att_values into ls_ct_att_value_temp with key name = lc_CR_number.
  if sy-subrc = 0.
    ls_cr = ls_ct_att_value_temp-value.

* 2b) Read CR/CD record
  select single * from CRMD_ORDERADM_H into ls_CRMD_ORDERADM_H where object_id = ls_cr.

* 2c) Read context
    when lc_CR. "RfC
* 2d) CR scope data
      SELECT * FROM tsocm_cr_context INTO TABLE lt_tsocm_cr_context
               WHERE guid = ls_CRMD_ORDERADM_H-guid.

    when others. "CDs
* 2e) CD scope data
      SELECT * FROM tsocm_cr_context INTO TABLE lt_tsocm_cr_context
               WHERE created_guid = ls_CRMD_ORDERADM_H-guid.  "for CD guid

* 3) For all variables passed
  LOOP AT ct_att_values ASSIGNING <fs_att_value>.
    ls_index = sy-tabix.

* 3a) See if the field name is already passed to badi
    SPLIT <fs_att_value>-name AT '-' INTO lv_tabname lv_fieldname.
    READ TABLE mt_tables WITH KEY table_name = lv_tabname ASSIGNING <fs_table_buffer>.

    IF sy-subrc = 0.
      ASSIGN <fs_table_buffer>-table_content->* TO <fs_table>.

      READ TABLE <fs_table> WITH KEY (lc_product_guid) = is_bp_act-obj_guid ASSIGNING <fs_field>.
      IF sy-subrc <> 0.

      ASSIGN COMPONENT lv_fieldname OF STRUCTURE <fs_field> TO <fs_value>.
      IF sy-subrc = 0.
        <fs_att_value>-value = <fs_value>.

* 4) If field is not already passed, read table to populate
      CASE lv_fieldname.
        when 'EXT_REFERENCE'. "external refencence
          SELECT single po_number_uc FROM crmd_order_index INTO ls_ext_reference
                                     WHERE header = ls_CRMD_ORDERADM_H-guid.
          if ls_ext_reference is not initial.
            <fs_att_value>-value = ls_ext_reference.
            MODIFY ct_att_values FROM <fs_att_value> INDEX ls_index TRANSPORTING value.

        when 'PROJECT_ID'. "Project assigned to CR. There's only one per CR
          LOOP AT lt_tsocm_cr_context INTO ls_tsocm_cr_context where PROJECT_ID is not initial.
            <fs_att_value>-VALUE = ls_tsocm_cr_context-project_id.
          MODIFY ct_att_values FROM <fs_att_value> INDEX ls_index TRANSPORTING value.
        when 'TEXT_LONG_DESC'.           "Text box - long description
          clear ls_text_value.
            EXPORTING P_GUID     = ls_CRMD_ORDERADM_H-guid
      P_TEXTTYPE = lc_textid_longdesc
            IMPORTING PT_TEXTS   = ls_text_value.

          <fs_att_value>-VALUE = ls_text_value.
          MODIFY ct_att_values FROM <fs_att_value> INDEX ls_index TRANSPORTING value.

Step 4)  Create the Mail Forms.
Tcode SM_CRM -> business role ZSOLMANPRO -> Service Operations. Create -> Mail Form (under section Search).

Select to create a new Mail Form and update the header fields…

The field Attribute Context will control the fields that are available for selection.  In my form, fields from standard attributes and from the custom attributes are needed.
To get some of the standard fields, I set the Attribute Context to Service Request Attributes.

Select Add Attributes.

Select the field needed and Insert…

Then, to add the custom fields, update the the Attribute Context to the new custom attibute that was added in Step 2....

Select the Add Attribute button again and change the Attribute Category to Additional Fields to see the custom fields. 

Select the field and insert.

As you add fields, the form will be displayed in WYSIWYG (what you see is what you get) format …

Step 5) To maintain the HTML
You may want to maintain the HTML directly, for example to format the fields into table columns so the labels and values up nicely.  To do that, select DESIGN <->SOURCE to toggle back and forth between the HTML and WYSIWYG screens….

If you are not comfortable with HTML, don’t fear it here! Just start with the one generated automatically by the WYSIWYG setup. 

To keep the sections easier to read, I inserted documentation lines like this… <!-- ROW STATUS -->

If you want to format the fields into table columns, here some logic to get you started. 
1) <table class="Data3"> indicates the name of the table, so you can have several tables in your form, if you want. This small part of my html has three tables.
2) <tr> and </tr> indicate the start and end to a table row. 
3) <td and </td> indicate the start and end to a table column.

This small part of the html will show the ChaRM status, the ChaRM document number, and the Multi Level categorization assigned….


<table class="Data3">
<td class="Data3"><font color="black" size="2"><strong><font face="Arial">Status</font></strong></font></td>
<td class="Data3"><span style='font-family: "Arial",sans-serif;'><strong><font size="2">                 </font></strong></span> <font color="red" size="2"><span style='font-family: "Arial",sans-serif;'><input dir="ltr" id="%SAP_CRMS_SRQM_GEN_FIELDS-CRM_SRQM_STATUS" value="Status"></span></font></td>
<h2><font size="3"><u>ChaRM Detail</u></font></h2>
<font face="Arial"><!-- ROW3--></font>
<table class="Data">
<tbody><!-- CHARM NO -->
<td class="Data"><font color="black" size="2"><strong><font face="Arial">ChaRM ID</font></strong></font></td>
<td class="Data"><font color="black" size="2"><span style='font-family: "Arial",sans-serif;'><input dir="ltr" id="%SAP_CRMS_SRQM_GEN_FIELDS-CRM_SRQM_NUMBER" value="Service Request ID"></span></font></td>
<table class="DataCat">
<td class="DataCat"><font color="black" size="2"><span style='font-family: "Arial",sans-serif;'><strong>Categorization     </strong></span></font></td>
<td class="DataCat"><span style='font-family: "Arial",sans-serif;'><font color="black" size="2"><input dir="ltr" id="%SAP_CRMS_SRQM_GEN_FIELDS-CRM_SRQM_SUBJ_CAT1" value="Subject Category 1"> /</font></span> <span style='font-family: "Arial",sans-serif;'><font color="red" size="2"><input dir="ltr" id="%SAP_CRMS_SRQM_GEN_FIELDS-CRM_SRQM_SUBJ_CAT2" value="Subject Category 2"> <font color="#000000">/</font></font></span> <span style='font-family: "Arial",sans-serif;'><font color="black" size="2"><input dir="ltr" id="%SAP_CRMS_SRQM_GEN_FIELDS-CRM_SRQM_SUBJ_CAT3" value="Subject Category 3"></font></span></td>

Play around with the html.  It's not as difficult as it looks.   Also, if you miss an end indicator, for example, the tool will try to fix the html automatically. Toggle back and forth between the WYSIWYG and HTML to see your changes and the auto changes.

Step 6) Add special fields to the form….
a) Insert a Company Logo.
Select Insert Picture and browse for the JPG of the logo to insert…

b) Insert a hyperlink the the ChaRM

c) Create a new Text Element to be display in Production
I have a hyperlink to open the ChaRM document in my mail form. Since the hyperlink for the Development and Production systems will differ, you’ll want to control which is displayed. There are a couple of ways to do that.  One way to create the URL hyperlink to work in SolMan production is to update, create a new Text Element and create conditions to check the source SolMan system ID.

Cut and paste the HTML from the original Text Element into the new Text Element.

Return to the WYSIWYG format and remove the original hyperlink that was copied…

Create a new hyperlink for the production system…

Update URL color if needed.

Since two Text Elements now exist, you need to add conditions to determine with each will be used.  Select EDIT STRUCTURE to create the Mail Conditions.

Select the Attribute Context that will be used to determine the condition. In my scenario, I have a custom attribute that was created for the SolMan system id and populated in my BADI.  Select the original Text Element and INSERT….

Select to assign the attribute …


Select the field and INSERT…

Enter the System ID for the SolMan development system.  You can add additional conditions if needed.

Select the other Text Element (e.g for production) and enter those conditions as needed….

When finished, select BACK…

Step 7) Test Changes after updating the HTML

On the WYSIWYG screen, select TEST SEND & PREVIEW (at the top) and select SAVE.

Step 😎 Maintain the Actions / Conditions

Locate the email action for the form. Verify the method assigned is SEND_MAIL_WITH_MAIL_FORMS.

Set the method parameter “Mail template name” to match Mail Form created in the UI (Note that it is case sensitive).

Update the conditions to generate the form when needed.

Here is the resulting email in Outlook. (I did remove the logo and adjusted format a bit manually so it would fit in the screen shot better, but you get the idea. :smile:

Thank you for reading this long post! There was a lot to cover.   I think I covered everything.  If you find that I missed a part or something should have more detail, let me know and I’ll update the post.  

Have a great day!!!

Labels in this area