Skip to Content
Author's profile photo Bharat Bajaj

Program to create URL in Attachment Block of Opportunity in CRM WEB UI

Hello Guys,

In this document, I’ll explain the way to create a URL directly in the Attachment Block of any Opportunity using a Custom Program, without going to the Web UI.

This can be really helpful in case there is a requirement to automatically attach a unique URL for each opportunity after Create/Change operation.

For illustration, here I have created a Program to create the URL, but you can also put the code in a FM & call the same during/after the save or as per the business requirement.

Below is the small piece of code which will solve our purpose.

 

Sample Code

REPORT  ztest1.

PARAMETERS : p_opp_id TYPE crmt_object_id,      ” Opportunity ID
p_url    TYPE char100 LOWER CASE.             ” External URL

DATA : lv_opp_guid        TYPE crmt_object_guid,
wa_bus_obj     TYPE sibflporb,
lt_url         TYPE sdokcntascs,
wa_url         TYPE sdokcntasc,
lt_prop        TYPE sdokproptys,
wa_prop        TYPE sdokpropty,
wa_loio        TYPE skwf_io,
wa_phio        TYPE skwf_io,
wa_error       TYPE skwf_error.

CHECK p_url IS NOT INITIAL AND p_opp_id IS NOT INITIAL.

***
CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT’
EXPORTING
input  = p_opp_id
IMPORTING
output = p_opp_id.

***
SELECT SINGLE guid
FROM crmd_orderadm_h
INTO lv_opp_guid
WHERE object_id = p_opp_id.

***
wa_url-line = p_url.
APPEND wa_url TO lt_url.

***
wa_bus_obj-instid = lv_opp_guid.  “(Opportunity GUID)
wa_bus_obj-typeid = ‘BUS2000111’. “(For Opportunity)
wa_bus_obj-catid  = ‘BO’.         “(Business Object)

***
wa_prop-name = ‘KW_RELATIVE_URL’. “The name of URL
wa_prop-value = p_opp_id.
APPEND wa_prop TO lt_prop.

wa_prop-name = ‘CONTENT_URL’.
wa_prop-value = p_url.
APPEND wa_prop TO lt_prop.

wa_prop-name = ‘LANGUAGE’.
wa_prop-value = sy-langu.
APPEND wa_prop TO lt_prop.

wa_prop-name = ‘DESCRIPTION’.
wa_prop-value = ‘Opportunity External URL’.
APPEND wa_prop TO lt_prop.

***
CALL METHOD cl_crm_documents=>create_url
EXPORTING
url             = lt_url
properties      = lt_prop
business_object = wa_bus_obj
IMPORTING
loio            = wa_loio
phio            = wa_phio
error           = wa_error.

***
IF wa_error IS INITIAL.
WRITE : ‘URl added to Oppty : ‘, p_opp_id .
ELSE.
MESSAGE ID wa_error-id TYPE wa_error-type NUMBER wa_error-no
WITH wa_error-v1 wa_error-v1 wa_error-v1 wa_error-v1.
ENDIF.

 

The above program calls the Static Method CREATE_URL of Global Class CL_CRM_DOCUMENTS and the logic is pretty straight forward & simple.

If I execute the above program with below inputs :

/wp-content/uploads/2015/08/2_765398.png

 

The URL will be directly added in the Attachment block of opportunity like below:

 

/wp-content/uploads/2015/08/4_765399.png

 

You can use the same program for Activities/ Business Partners or any other CRM object, you just need to pass the corresponding Business Object (BO) Type & the respective GUID in the method parameter “BUSINESS_OBJECT”. (for Eg. BUS1006 for Business Partner / BUS2000126 for Activity)

 

I hope this will be helpful for you. Please add comments if you need any further help or inputs.

 

Regards,

Bharat Bajaj

Assigned tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Really helpful post Bharat...

      BR,

      Riya