BAPI_ACTIVITYCRM_CREATEMULTI in CRM
Hi Experts,
I have one query regarding the bapi - BAPI_ACTIVITYCRM_CREATEMULTI.
i want to add some more fields in TABLES of this BAPI.
In TABLES of this BAPI there is a table named as : EXTENSIONIN. I have tried to add some data in this field which should be reflected in the table CRMD_ACTIVITY_I.
Do anybody have any idea regarding BAPI Extension ??
Hi Naresh,
Yes. We can extend standard Function Modules available in SAP. For that in ECC 6.0 We have FM Extensions.
Display FM - > Function Module -> Enhance interface.
But I am not able to see the FM in SE37 which you have given.BAPI_ACTIVITYCRM_CREATEMULTI.
All the very best to you.
- MOHAN
Similar Messages
-
Using BAPI_ACTIVITYCRM_CREATEMULTI for creating sales order in CRM
Hello Experts,
I am creating a sales order using BAPI_ACTIVITYCRM_CREATEMULTI, But I am getting the following errors:
1. Reference Object Type (ORGMAN) not allowed
2. Reference Object Type (PARTNER) not allowed
3. Incomplete interface data - No reference specified
4. Item was not found
Can you please help me with the mandatory fields, that has to be filled in the BAPI, and do I need to use Commit BAPI after this BAPI.
Please I am in critical postion,
Now I am able to create a sales order there is no data it like the partner number and Item.May be I am missing some important fileds.
Please help.
Thanks,
Suma
Edited by: Suma B on Aug 8, 2008 1:05 PMHi,
I am passing data using SE37 T-Code.
I was told by the fucntioal guys that GUID will be generated by CRM, so we dont need to send that as an input.
Still facing the same error...
These are my input fields:
REF_HANDLE
REF_GUID
R
OBJECTNAME
LOGICAL_KEY
FIELDNAME
C
|
0000000000
ORDERADM_H
PROCESS_TYPE
0000000000
ORDERADM_H
POSTING_DATE
0000000000
ACTIVITY_H
CATEGORY
0000000000
ACTIVITY_H
PRIORITY
0000000000
ACTIVITY_H
DIRECTION
0000000000
PARTNER
000000000022XXXXXXX
REF_PARTNER_FCT
0000000000
PARTNER
000000000022XXXXXXX
REF_PARTNER_NO
0000000000
PARTNER
000000000022XXXXXXX
PARTNER_FCT
0000000000
PARTNER
000000000022XXXXXXX
PARTNER_NO
0000000000
ORGMAN
DIS_CHANNEL
0000000000
ORGMAN
DIVISION
0000000000
ORGMAN
SALES_ORG
0000000000
ORDERADM_I
PRODUCT
0000000001
B
SCHEDLIN
00000000000000000000000000000000
QUANTITY
|
This is error log:
T
ID
NUM
MESSAGE
LOG_NO
LOG_MS
MESSAGE_V1
MESSAGE_V2
MESSAGE_V3
MESSAGE_V4
PARAMETER
ROW
FIELD
SYSTEM
|
W
CRM_ORDER
004
Referenced object type (ORGMAN) not allowed
$000001
000001
ORGMAN
ORDER
0
CR5CLNT100
W
CRM_ORDER
004
Referenced object type (PARTNER) not allowed
$000001
000002
PARTNER
ORDER
0
CR5CLNT100
W
CRM_ORDER
005
Incomplete interface data - No reference specified
$000001
000003
ORDER
0
CR5CLNT100
E
CRM_ORDERADM_I
006
Item was not found.
$000001
000004
ORDER
0
CR5CLNT100
E
CRM_ORDER
005
Incomplete interface data - No reference specified
$000001
000005
ORDER
0
CR5CLNT100
S
CRM_MESSAGES
005
A log has been generated for single document
$000001
000006
MESSAGES
0
CR5CLNT100
E
COM_PARTNER
119
Enter Sold-To Party
$000002
000001
Sold-To Party
PARTNER
0
PARTNER_NO
CR5CLNT100
E
COM_PARTNER
119
Enter Ship-To Party
$000002
000002
Ship-To Party
PARTNER
0
PARTNER_NO
CR5CLNT100
E
COM_PARTNER
119
Enter Bill-To Party
$000002
000003
Bill-To Party
PARTNER
0
PARTNER_NO
CR5CLNT100
E
COM_PARTNER
119
Enter Payer
$000002
000004
Payer
PARTNER
0
PARTNER_NO
CR5CLNT100
E
COM_PARTNER
119
Enter Sold-To Party
00000000000000047612
000001
Sold-To Party
PARTNER
0
PARTNER_NO
CR5CLNT100
E
COM_PARTNER
119
Enter Ship-To Party
00000000000000047612
000002
Ship-To Party
PARTNER
0
PARTNER_NO
CR5CLNT100
E
COM_PARTNER
119
Enter Bill-To Party
00000000000000047612
000003
Bill-To Party
PARTNER
0
PARTNER_NO
CR5CLNT100
E
COM_PARTNER
119
Enter Payer
00000000000000047612
000004
Payer
PARTNER
0
PARTNER_NO
CR5CLNT100
|
Thanks,
Suma -
Problem in BAPI_ACTIVITYCRM_CREATEMULTI
Hi Experts!
I am uploading activity in crm throu BAPI_ACTIVITYCRM_CREATEMULTI. When I am inserting data in structures
BAPIBUS2000110_HEADER_INS
BAPIBUS20001_HEADER_INS
BAPIBUS2000110_HEADER_INSX
than it is not updating the ACTIVITY . Msg r shown ie
AN AUTHORIZATIOIN CHECK COULD NOT BE EXECUTED
A LOG HAS BEEN GENERATED FOR SINGLE DOCUMENT
AN AUTHORIZATIOIN CHECK COULD NOT BE EXECUTED
Pls send me the solution.
Regds
NavneetHi Navneet,
That message is due to the error in input data.You have to give all the required mandatory fields in header . Eg:
BAPIBUS2000110_HEADER_INS-GUID
BAPIBUS2000110_HEADER_INS-DESCRIPTION
BAPIBUS2000110_HEADER_INS-DIRECTION
BAPIBUS2000110_HEADER_INS-PRIORITY
BAPIBUS2000110_HEADER_INS-PROCESS_TYPE
BAPIBUS2000110_HEADER_INS-MODE as A.
Set those fields which had data in BAPIBUS2000110_HEADER_INS as X against same field in structure BAPIBUS2000110_HEADER_INSX
Try giving partner and organisation details .
BAPIBUS20001_PARTNER_INS-REF_GUID
BAPIBUS20001_PARTNER_INS-REF_KIND = A
BAPIBUS20001_PARTNER_INS-REF_PARTNER_HANDLE
BAPIBUS20001_PARTNER_INS-PARTNER_FCT
BAPIBUS20001_PARTNER_INS-PARTNER_NO
BAPIBUS20001_PARTNER_INS-NO_TYPE
BAPIBUS20001_PARTNER_INS-DISPLY_TYPE
BAPIBUS20001_ORGMAN_INS -REF_GUID
BAPIBUS20001_ORGMAN_INS -REF_KIND = A
BAPIBUS20001_ORGMAN_INS -REF_PARTNER_HANDLE
BAPIBUS20001_ORGMAN_INS-DIS_CHANNEL
BAPIBUS20001_ORGMAN_INS -SALES_ORG
BAPIBUS20001_ORGMAN_INS -SALES_ORG_RESP
BAPIBUS20001_ORGMAN_INS -MODE = A
Thanks ,
Rajeswari -
CRM IC (Interactive Center) Service Order Create
Guys,
We are creating a Service order in CRM_IC using 'BAPI_ACTIVITYCRM_CREATEMULTI' . the order creates fine ,But I need to assign person responsible to the line item and am not sure how to do it.
Anybody tried this out ? or is there a better way to create a service order for CRM IC environment.
Thanks,
ManojHi
Please send the sample code for create service order using function module
Regards
P.Prabhakaran -
Which function creates an activity in CRM?
Hi,
We would like to create activities in CRM through a BAPI-like function but we can't seem to find a suitable one. Do you know which function / class method is used to create new activities in CRM ?
Thanks in advance,
GeorgeHi,
Please have Look into the below LInk
Using BAPI_ACTIVITYCRM_CREATEMULTI.
[Link|Re: Creating Activities Programmatically in CRM]
Hope it will be HelpFul
Thanks
kalyan -
Activity through BAPI_ACTIVITYCRM_CREATEMULTI or CRM_ORDER_MAINTAIN
Hi All,
I have to create activity from Legacy file, so which one would be convenient as FM CRM_ORDER_MAINTAIN is a generic FM and it can create Opprtunity,Activity etc.and there is a BAPI FM ( which creates Activity )BAPI_ACTIVITYCRM_CREATEMULTI .What Should one use in a conversion program in which input is in a fixed length file format.
Thanks & Regards.
Paul Dibs.Hi Koushik,
Thanks for the reply,
But still I need to know what are the specific difference between the two function module.Even in CRM_ORDER MAINTAIN I am able to get all those Structure with which I am working in BAPIACTIVITYCRM_CREATEMULTI. I know all the other CRM Business transaction can be created through CRM_ORDER_MAINTAIN. If you could explain a bit detail in what context one should use CRM_ORDER MAINTAIN and BAPIACTIVITYCRM_CREATEMULTI. -
How to make processing of BAPI_ACTIVITYCRM_CREATEMULTI time efficient
hello
We want to upload the CRM Business activity (Interaction Record) using 'BAPI_ACTIVITYCRM_CREATEMULTI ' .It is taking 30 min to upload 5000 records, but the actual file will contain more than 1 million records.Is there any way to upload it efficiently.HI,
Use the "Parallel Processing" to reduce the time taken to execute more records..
Just search "Parallel processing in SAP" in GOOGLE for teh methods... -
Creating Activities Programmatically in CRM
Hi,
I am trying to use BAPI_ACTIVITYCRM_CREATEMULTI.
This is called within a BAdI when a contact responds to a survey.
I am evaluating the survey results and them trying to set the appropriate status.
I am successfully screating the activity document. However I am failing to set the status.
This is my code where I set the values of the Status tables to be passed in. I am only setting the status e.g. E0002 (Accepted) or E0004 (Declined) and the Activate flag.
Am I missing something?
CALL METHOD ir_survey_values->values_get
EXPORTING
i_question_id = 'q1'
i_answer_id = 'id_answer'
IMPORTING
et_values = et_result.
READ TABLE et_result INTO es_result INDEX 1.
IF es_result EQ 'id_yes'.
MOVE 'E0002' TO es_status-status.
MOVE 'X' TO es_statusx-activate.
APPEND es_status TO et_status.
MOVE 'X' TO es_statusx-status.
MOVE 'X' TO es_statusx-activate.
APPEND es_statusx TO et_statusx.
ELSE.
MOVE 'E0004' TO es_status-status.
MOVE 'X' TO es_statusx-activate.
APPEND es_status TO et_status.
MOVE 'X' TO es_statusx-status.
MOVE 'X' TO es_statusx-activate.
APPEND es_statusx TO et_statusx.
ENDIF.
* call function module BAPI_ACTIVITYCRM_CREATEMULTI
REFRESH lt_return.
CALL FUNCTION 'BAPI_ACTIVITYCRM_CREATEMULTI'
TABLES
header = lt_header
headerx = lt_headerx
partner = lt_partner
partnerx = lt_partnerx
date = lt_date
datex = lt_datex
status = et_status
statusx = et_statusx
created_process = lt_created_process.
Thanks
DavidThanks. It appears my problem was that I was using coding relevant to CRM 4 rather than CRM 5.
It seems all I needed was:
CALL METHOD ir_survey_values->values_get
EXPORTING
i_question_id = 'q1'
i_answer_id = 'id_answer'
IMPORTING
et_values = et_result.
READ TABLE et_result INTO es_result INDEX 1.
IF es_result EQ 'id_yes'.
lv_act_status = 'E0002'. " In process
ELSEif es_result eq 'id_no'.
lv_act_status = 'E0004'. " Declined
else.
lv_act_status = 'E0001'. " Response
ENDIF. -
Any case study on using ERP sales order vs CRM Sales order in IC WEB UI
Hi All,
Currently we have a requirement where in agent uses ERP Sales order functionality in IC WEB UI for creating sales order. Incase of any incompleteness in order or any pricing error an activity should get created and should get assinged to Back office guy(CRM User).
My approach is as follows, we will call a custom FM in CRM from the user exit associated with Sales order transaction, This logic gets executed on save of ERP sales order.This custom FM will create an activity in CRM and assing it to back office guy. Other approach is to use the IDOC linked to the VAO1 transaction which inturns calls the custom fm.
Can you please suggest if you have any better approach to this.
Recently we came to know that ERP Sales order has got limited functionalities. If some one has a case study doc on ERP Sales order vs CRM sales order pls give me the ref link.
Thanks,
udayaHi Udaya,
Calling a Customer Specific R/3 Transaciton was quite easy in CRM 4.0 / 5.0 in the PC-UI Framework using Object Links. You can do that all by customizing and creating a custom method for a BOR Object in Transaction SWO1.
I think I've used CRM_ORDER_MAINTAIN to update the Document Flow. The subsequent activities where created by BAPI_ACTIVITYCRM_CREATEMULTI. I've wrapped all that standard functions in a RFC enabled function module.
It would be possible to provide also a link in the E-Mail to the Manager but the client is using a Citrix environment to provide access to the Portal. But Outlook runs locally. So we decided to use the standard Portal iView to display the Alerts. When you fill the Alert Container with the elements OBJKEY_GUID, OBJKEY_BOR_OBJECT_TYPE, OBJKEY_CRM_OBJECT_TYPE, OBJKEY_METHOD and OBJKEY_LOGICAL_SYSTEM using the Function Module SWC_ELEMENT_SET that provides a direct link to the specific document too.
Best regards
Gregor -
Im creating activity by using BAPI_ACTIVITYCRM_CREATEMULTI, but its creating a TEMPLATE. when i tried not passing value for TEMPLATE TYPE field im finding error as incomplete data even though passing complete data.
Hi Nisha,
im trying to create sales meeting. im passing header, partner, organisation, date, status data. its creating successfully with GUID and object ID but as a TEMPLATE. im sending my code for ur reference.
*& Report /IGTE0/DM_CRM_ACTIVITIES
Report .....Creating CRM Activities
Author: .....MARUTHI PRASAD J (714997)
REPORT /IGTE0/DM_CRM_ACTIVITIES.
******************source structure declaration
types: begin of ty_source_data,
ref_id(5) type N,
DESCRIPTION(40),
STATUS(5),
DATE_FROM(8),
DATE_TO(8),
TIME_FROM(6),
TIME_TO(6),
PRIVATE_FLAG(1),
PROCESS_TYPE(4),
PRIORITY(1) type N,
TIMEZONE_FROM(6),
ACT_LOCATION(100),
PARTNER_FCT(8),
RELATION_PARTNER(32),
CREATED_AT(15), "type DEC,
CREATED_BY(12),
CHANGED_AT(15), "type DEC,
CHANGED_BY(12),
SALES_OFFICE(14),
SALES_GROUP(14),
SALES_ORG(14),
DIS_CHANNEL(2),
DIVISION(2),
EXTERN_ACT_ID(20),
CATEGORY(3),
end of ty_source_data.
types: begin of ty_source_data_updt,
rel_typ(8),
ref_id1(5) type N,
BUS_PRTNR(32),
VALID_TO(8),
end of ty_source_data_updt.
*****Declaration of BAPI : bapi_activitycrm_createmulti
data: lt_source_data type table of ty_source_data,
ls_source_data type ty_source_data.
data: lt_source_data_updt type table of ty_source_data_updt,
ls_source_data_updt type ty_source_data_updt.
data: lt_header type table of BAPIBUS2000110_HEADER_INS,
ls_header type BAPIBUS2000110_HEADER_INS,
lt_headerx type table of BAPIBUS2000110_HEADER_INSX,
ls_headerx type BAPIBUS2000110_HEADER_INSX,
lt_created_process type TABLE OF BAPIBUS20001_HEADER_INS,
ls_created_process type BAPIBUS20001_HEADER_INS,
lt_PARTNER type table of BAPIBUS20001_PARTNER_INS,
ls_PARTNER type BAPIBUS20001_PARTNER_INS,
lt_PARTNERX type table of BAPIBUS20001_PARTNER_INSX,
ls_PARTNERX type BAPIBUS20001_PARTNER_INSX,
lt_ORGANISATION type table of BAPIBUS20001_ORGMAN_INS,
ls_ORGANISATION type BAPIBUS20001_ORGMAN_INS,
lt_ORGANISATIONX type table of BAPIBUS20001_ORGMAN_INSX,
ls_ORGANISATIONX type BAPIBUS20001_ORGMAN_INSX,
lt_DATE TYPE TABLE OF BAPIBUS20001_APPOINTMENT_INS,
ls_DATE TYPE BAPIBUS20001_APPOINTMENT_INS,
lt_DATEX TYPE TABLE OF BAPIBUS20001_APPOINTMENT_INSX,
ls_DATEX TYPE BAPIBUS20001_APPOINTMENT_INSX,
lt_STATUS TYPE TABLE OF BAPIBUS20001_STATUS_INS,
ls_STATUS TYPE BAPIBUS20001_STATUS_INS,
lt_STATUSX TYPE TABLE OF BAPIBUS20001_STATUS_INSX,
ls_STATUSX TYPE BAPIBUS20001_STATUS_INSX,
lt_return1 type table of bapiret2 with header line
*****Declaration of BAPI : bapi_activitycrm_save
data: lt_OBJECTS_TO_SAVE TYPE TABLE OF BAPIBUS20001_GUID_DIS,
ls_OBJECTS_TO_SAVE TYPE BAPIBUS20001_GUID_DIS,
lt_SAVED_OBJECTS type table of BAPIBUS20001_OBJECT_ID,
ls_SAVED_OBJECTS type BAPIBUS20001_OBJECT_ID,
lt_return2 type table of bapiret2 with header line,
lt_return3 type table of bapiret2 with header line,
lt_return4 type table of bapiret2 with header line
*****Declaration for return logs
********************Uploading text file
parameters: lv_file type localfile.
data: lv_file1 type string.
parameters: lv_updt type localfile.
data: lv_updt1 type string.
start-of-selection.
lv_file = 'C:\Documents and Settings\714997\Desktop\Book1_he.txt'.
lv_file1 = lv_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = lv_file1
FILETYPE = 'DAT'
HAS_FIELD_SEPARATOR = '#'
TABLES
DATA_TAB = lt_source_data.
IF SY-SUBRC <> 0.
ENDIF.
lv_updt = 'C:\Documents and Settings\714997\Desktop\crm_task_Partner_10Dec2010sort.txt'.
lv_updt1 = lv_updt.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = lv_updt1
FILETYPE = 'DAT'
HAS_FIELD_SEPARATOR = '#'
TABLES
DATA_TAB = lt_source_data_updt.
IF SY-SUBRC <> 0.
ENDIF.
loop at lt_source_data into ls_source_data.
*************header data
refresh: lt_header,lt_partner,lt_organisation,lt_date,lt_status.
clear: ls_partner,ls_header,ls_organisation,ls_status,ls_date.
ls_header-PROCESS_TYPE = ls_source_data-PROCESS_TYPE.
ls_header-HANDLE = '0000000001'.
ls_header-DESCR_LANGUAGE = 'EN'.
ls_header-LANGU_ISO = 'EN'.
ls_header-DESCRIPTION = ls_source_data-DESCRIPTION.
ls_header-CATEGORY = ls_source_data-CATEGORY.
ls_header-PRIORITY = ls_source_data-PRIORITY.
ls_header-OBJECTIVE = '003'.
ls_header-EXTERN_ACT_ID = ls_source_data-EXTERN_ACT_ID.
ls_header-PRIVATE_FLAG = ls_source_data-PRIVATE_FLAG.
ls_header-POSTING_DATE = ls_source_data-DATE_FROM .
ls_header-MODE = 'A'.
ls_header-CREATED_AT = ls_source_data-CREATED_AT .
ls_header-CREATED_BY = ls_source_data-CREATED_BY .
ls_header-CHANGED_AT = ls_source_data-CHANGED_AT .
ls_header-CHANGED_BY = ls_source_data-CHANGED_BY .
ls_header-ACT_LOCATION = ls_source_data-ACT_LOCATION .
ls_header-TEMPLATE_TYPE = 'C'.
ls_headerx-PROCESS_TYPE = 'X'.
ls_headerx-HANDLE = 'X'.
ls_headerx-DESCR_LANGUAGE = 'X'.
ls_headerx-LANGU_ISO = 'X'.
ls_headerx-DESCRIPTION = 'X'.
ls_headerx-CATEGORY = 'X'.
ls_headerx-PRIORITY = 'X'.
ls_headerx-OBJECTIVE = 'X'.
ls_headerx-EXTERN_ACT_ID = 'X'.
ls_headerx-PRIVATE_FLAG = 'X'.
ls_headerx-POSTING_DATE = 'X'.
ls_headerx-MODE = 'X'.
ls_headerx-CREATED_AT = 'X'.
ls_headerx-CREATED_BY = 'X'.
ls_headerx-CHANGED_AT = 'X'.
ls_headerx-CHANGED_BY = 'X'.
ls_headerx-ACT_LOCATION = 'X'.
ls_headerx-TEMPLATE_TYPE = 'X'.
IF ls_source_data-PRIVATE_FLAG = 'N'.
ls_header-PRIVATE_FLAG = ' '.
else.
ls_header-PRIVATE_FLAG = 'X'.
ENDIF.
append ls_header to lt_header.
append ls_headerx to lt_headerx.
*******************partner data
refresh lt_partner.
refresh lt_partnerx.
ls_PARTNER-REF_GUID = .
ls_PARTNER-REF_HANDLE = '0000000001'.
ls_PARTNER-REF_KIND = 'A'.
ls_PARTNER-PARTNER_FCT = ls_source_data-PARTNER_FCT.
ls_PARTNER-PARTNER_NO = ls_source_data-RELATION_PARTNER.
ls_PARTNER-NO_TYPE = 'BP'.
ls_PARTNER-DISPLAY_TYPE = 'BP'.
ls_PARTNER-KIND_OF_ENTRY = 'A'.
ls_PARTNER-MAINPARTNER = 'X'.
ls_PARTNER-RELATION_PARTNER = ls_source_data-RELATION_PARTNER.
ls_PARTNERX-REF_HANDLE = 'X'.
ls_PARTNERX-REF_KIND = 'X'.
ls_PARTNERX-PARTNER_FCT = 'X'.
ls_PARTNERX-PARTNER_NO = 'X'.
ls_PARTNERX-NO_TYPE = 'X'.
ls_PARTNERX-DISPLAY_TYPE = 'X'.
ls_PARTNERX-KIND_OF_ENTRY = 'X'.
ls_PARTNERX-MAINPARTNER = 'X'.
ls_PARTNERX-RELATION_PARTNER = 'X'.
append ls_partner to lt_partner.
append ls_partnerx to lt_partnerx.
*******************organisation data
refresh lt_organisation.
refresh lt_organisationx.
ls_organisation-REF_HANDLE = '0000000001'.
ls_organisation-REF_KIND = 'A'.
ls_organisation-DIS_CHANNEL = ls_source_data-DIS_CHANNEL.
ls_organisation-DIVISION = ls_source_data-DIVISION.
ls_organisation-SALES_ORG = ls_source_data-SALES_ORG.
ls_organisation-SALES_OFFICE = ls_source_data-SALES_OFFICE.
ls_organisation-SALES_GROUP = ls_source_data-SALES_GROUP.
ls_organisation-SALES_ORG_RESP = 'O 03000015'.
ls_organisation-MODE = 'A'.
ls_ORGANISATIONX-REF_HANDLE = 'X'.
ls_ORGANISATIONX-REF_KIND = 'X'.
ls_ORGANISATIONX-DIS_CHANNEL = 'X'.
ls_ORGANISATIONX-DIVISION = 'X'.
ls_ORGANISATIONX-SALES_ORG = 'X'.
ls_ORGANISATIONX-SALES_OFFICE = 'X'.
ls_ORGANISATIONX-SALES_GROUP = 'X'.
ls_ORGANISATIONX-MODE = 'X'.
append ls_organisation to lt_organisation.
append ls_organisationx to lt_organisationx.
********************date
refresh lt_date.
refresh lt_datex.
ls_DATE-REF_HANDLE = '0000000001'.
ls_DATE-REF_KIND = 'A'.
ls_DATE-APPT_TYPE = 'ORDERPLANNED'.
ls_DATE-TIMEZONE_FROM = ls_source_data-TIMEZONE_FROM.
ls_DATE-TIMEZONE_TO = ls_source_data-TIMEZONE_FROM.
ls_DATE-DATE_FROM = ls_source_data-DATE_FROM.
ls_DATE-DATE_TO = ls_source_data-DATE_TO.
ls_DATE-TIME_FROM = ls_source_data-TIME_FROM.
ls_DATE-TIME_TO = ls_source_data-TIME_TO.
ls_DATE-MODE = 'A'.
ls_DATEX-REF_HANDLE = 'X'.
ls_DATEX-REF_KIND = 'X'.
ls_DATEX-APPT_TYPE = 'X'.
ls_DATEX-TIMEZONE_FROM = 'X'.
ls_DATEX-TIMEZONE_TO = 'X'.
ls_DATEX-DATE_FROM = 'X'.
ls_DATEX-DATE_TO = 'X'.
ls_DATEX-TIME_FROM = 'X'.
ls_DATEX-TIME_TO = 'X'.
ls_DATEX-MODE = 'X'.
IF ls_source_data-DATE_TO = 'NULL'.
ls_date-DATE_TO = ls_source_data-DATE_FROM.
ENDIF.
IF ls_source_data-TIME_FROM = 'NULL'.
ls_DATE-TIME_FROM = '000000'.
ENDIF.
IF ls_source_data-TIME_TO = 'NULL'.
ls_DATE-TIME_TO = '000000'.
ENDIF.
append ls_date to lt_date.
append ls_datex to lt_datex.
********************status
refresh lt_STATUS.
refresh lt_STATUSX.
ls_STATUS-REF_HANDLE = '0000000001'.
ls_STATUS-REF_KIND = 'A'.
ls_STATUS-STATUS = ls_source_data-STATUS.
ls_STATUS-ACTIVATE = 'X'.
ls_STATUSX-REF_HANDLE = 'X'.
ls_STATUSX-REF_KIND = 'X'.
ls_STATUSX-STATUS = 'X'.
ls_STATUSX-ACTIVATE = 'X'.
append ls_status to lt_status.
append ls_statusx to lt_statusx.
*******************Creating the activity
CALL FUNCTION 'BAPI_ACTIVITYCRM_CREATEMULTI'
TABLES
HEADER = lt_header
HEADERX = lt_headerX
PARTNER = lt_partner
PARTNERX = lt_partnerx
ORGANISATION = lt_organisation
ORGANISATIONX = lt_organisationx
DATE = lt_date
DATEX = lt_datex
TEXT =
TEXTX =
REASON =
REASONX =
OUTCOME =
OUTCOMEX =
STATUS = lt_status
STATUSX = lt_statusx
LOCATION =
LOCATIONX =
INPUT_FIELDS =
CREATED_PROCESS = lt_created_process
RETURN = lt_return1
DOCUMENT_FLOW =
JOURNAL =
JOURNALX =
MATERIAL =
MATERIALX =
EXTENSIONIN =
LOOP AT lt_created_process into ls_created_process.
ls_OBJECTS_TO_SAVE-GUID = ls_created_process-GUID.
ENDLOOP.
refresh lt_created_process.
ls_OBJECTS_TO_SAVE-OBJECT_TYPE = 'BUS2000126'.
append ls_OBJECTS_TO_SAVE to lt_OBJECTS_TO_SAVE.
*****************Saving the activity
CALL FUNCTION 'BAPI_ACTIVITYCRM_SAVE'
EXPORTING
UPDATE_TASK_LOCAL = 'X'
SAVE_FRAME_LOG = FALSE
IMPORTING
LOG_HANDLE =
TABLES
OBJECTS_TO_SAVE = lt_OBJECTS_TO_SAVE
SAVED_OBJECTS = lt_SAVED_OBJECTS
RETURN = lt_return2
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = '1'
IMPORTING
RETURN =
LOOP AT lt_SAVED_OBJECTS into ls_SAVED_OBJECTS.
write: / ls_SAVED_OBJECTS-GUID, / ls_SAVED_OBJECTS-OBJECT_ID.
ENDLOOP.
refresh lt_SAVED_OBJECTS.
clear ls_SAVED_OBJECTS.
endloop. -
BADI for changing fields during Creation of BP in CRM
Hello to everyone,
I need to find a BADI (or other way) to default several fields during BP creation in CRM (4.0 SR1 SP9). The fields I will like to set are TAX TYPE, TAX NUMBER, TAX CATEGORY, etc.. I have found the BADI BUPA_TAX_UPDATE but i dont see any suitable parameters (structures) to changes these fields. Please advice and thanks in advance.Hi
If you use function BUPA_NUMBERS_GET then your BP number will already be buffered and you can avoid a DB read. It may also be that the BP is not in the DB yet anyway.
You can only pass one GUID in at a time - loop through IT_CHANGED_INSTANCES into a variable of type BU_PARTNER_GUID and pass that into the function as input parameter IV_PARTNER_GUID.
Cheers
Dom -
Refresh CRM data in R/3 report
Hi All,
I've a report in R/3 where i get the Order Status of CRM through a RFC, but when i'm changing the status in CRM through crmd_order, when the report is open in R/3. When i press the refresh button, the status is not changed, it shows the previous status.
Below is the code, can any1 help me how to go about
CALL FUNCTION 'CRM0_READ_RFC_DEST'
EXPORTING
i_consumer = 'CRM'
i_download_type = '*'
i_objname = '*'
I_BAPICRMDH2 =
I_REM_LOGSYS =
TABLES
t_crmrfcpar = t_crmrfcpar
EXCEPTIONS
NO_ENTRY_FOUND = 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.
IF NOT t_crmrfcpar[] IS INITIAL.
READ TABLE t_crmrfcpar INDEX 1.
l_rfcdst = t_crmrfcpar-rfcdest.
ENDIF.
Call RFC
*loop at z_guid into lguid.
*endloop.
*refresh ZORDER_STATUS.
CALL FUNCTION 'ZCRM_HEADER_STATUS'
DESTINATION l_rfcdst
IMPORTING
ORDER_IDRET = l_guid
tables
ORD_STATUS = ZORDER_STATUS
Regards
Sanjuany body?
-
Installation of IPC AP 7.0 Jar is getting Failed when uploading in CRM
Hello Experts,
we did some changes in the previosly uploded version of IPC AP 7.0 customer user exit Jar file in eclipse.
While uploading the new modified jar through transaction /SAPCND/UE_DEV in CRM we are getting error :" installation of module <Jar file name > has failed ".
when we checked the logs in SM 53 we seen the below mentioned error:
Message: Exception of type com.sap.sql.log.OpenSQLException caught: Exception of type com.sap.sql.sqlparser.CommonSQLParserException: - statement "DELETE FROM "SVMCRT_MOD_TR_T" WHERE "MODULE_NAME" LIKE ? ESCAPE ^ (reason: Modification of ABAP tables is not permit ted)" is not supported
caught: - statement "DELETE FROM "SVMCRT_MOD_TR_T" WHERE "MODULE_NAME" LIKE ? ESCAPE ^ (reason: Modification of ABAP tables is not permitted)" is not supported
--> com.sap.sql.log.OpenSQLException: Exception of type com.sap.sql.sqlparser.CommonSQLParserException: - statement "DELETE FROM "SVMCRT_MOD_TR_T" WHERE "MODULE_NAME" LIKE ? ESCAPE '^' (reason: Modification of ABAP tables is n" is not suppor ted
caught: - statement "DELETE FROM "SVMCRT_MOD_TR_T" WHERE "MODULE_NAME" LIKE ? ESCAPE '^' (reason: Modification of ABAP tables is not permitted)" is not supported
at com.sap.sql.log.Syslog.createAndLogOpenSQLException(Ljava/lang/Class;Ljava/lang/String;[Ljava/lang/Object;)Lcom/sap/sql/log/OpenSQLException;(Syslog.java:85)
at
if required i can post the complete stack trace.
any inputs/suggestions are most welcome.
Thanks & regards,
SiddharthHi Mark,
Yesterday after Posting the thread we found the same Note ,Issue occured because of JAVA write access was not enabled on the table ,After enabling it as mentioned in SAP Note, Jar file get successfully uploaded.
Thanks for your Help also.
Regards,
Siddharth -
Custom message required on log on pop-up in SAP CRM WEB UI
We required custom message to the log- on popup, right now the message is coming after we give the user ID and password "starting SAP CRM" instead of that
user required welcome message.., how can achieve this ?
Please reply as soon as possible.Hi Pankaj,
did you already check the guide in the CRM Wiki:
https://wiki.sdn.sap.com/wiki/display/CRM/WelcomeUserMessageinWeb+UI
Hope this answers your question.
Best Regards,
Michael -
Dynamic CRM 2013 Online how to execute Report, generate PDF and email
Dear All,
I am using Dynamic CRM 2013 online. For quote, I have workflow and Dialogue processes for review process. On approval, I want the system to generate a PDF of quote report, attach the PDF and email it to the Customer.
Better I would like, When approver, clicks on the approve button, the system should auto generate a PDF of quote report, attach the PDF and email it to the Customer, without any further input from the user. If its not possible, I may have to put button on
quote form.
I am using the attached code, but facing various issues.
1. Under prepare the SOAP Message coding part, I am not sure what should be the below URL for CRM 2013 Online?
xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
2. What should be the emailid here? Is it Recepient Contact id(Guid) ?
var emailid = resultXml.selectSingleNode("//CreateResult").nodeTypedValue;
alert("emailid" + emailid.toString());
3. Using this code, not able to create Entity for "ActivityMimeAttachment", I am getting newEntity as undefined.
Below is the code I am using. Please check and help me out, where I am going wrong. Let me know if any better way to implement it. At present, I have put one button on quote form, on click event, below code will get executed.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
var Xrm;
if (window.opener) { Xrm = window.opener.Xrm; }
else if (window.parent) { Xrm = window.parent.Xrm; }
function getReportingSession() {
var reportName = "Quotation_Report"; //set this to the report you are trying to download
var reportId = "7C39D18F-1DC6-E311-8986-D89D6765B238"; //set this to the guid of the report you are trying to download
var recordid = Xrm.Page.data.entity.getId();
// recordid = recordid.substring(1, 37); //getting rid of curly brackets
alert(recordid);
var pth = Xrm.Page.context.getServerUrl() + "/CRMReports/rsviewer/reportviewer.aspx";
var retrieveEntityReq = new XMLHttpRequest();
retrieveEntityReq.open("POST", pth, false);
retrieveEntityReq.setRequestHeader("Accept", "*/*");
retrieveEntityReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
retrieveEntityReq.send("id=%7B" + reportId + "%7D&uniquename=" + Xrm.Page.context.getOrgUniqueName() + "&iscustomreport=true&reportnameonsrs=&reportName=" + reportName + "&isScheduledReport=false");
var x = retrieveEntityReq.responseText.indexOf("ReportSession=");
var ret = new Array();
ret[0] = retrieveEntityReq.responseText.substr(x + 14, retrieveEntityReq.responseText.indexOf("&", x) - x - 14); //the session id
x = retrieveEntityReq.responseText.indexOf("ControlID=");
ret[1] = retrieveEntityReq.responseText.substr(x + 10, retrieveEntityReq.responseText.indexOf("&", x) - x - 10); //the control id
return ret;
function createEntity(ent, entName, upd) {
var jsonEntity = JSON.stringify(ent);
var createEntityReq = new XMLHttpRequest();
var ODataPath = Xrm.Page.context.getServerUrl() + "XRMServices/2011/OrganizationData.svc";
createEntityReq.open("POST", ODataPath + "/" + entName + "Set" + upd, false);
createEntityReq.setRequestHeader("Accept", "application/json");
createEntityReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
createEntityReq.send(jsonEntity);
var newEntity = JSON.parse(createEntityReq.responseText).d;
alert("new entity" + newEntity);
return newEntity;
function createAttachment() {
var params = getReportingSession();
var recordid = Xrm.Page.data.entity.getId();
alert("recordid " + recordid);
var orgName = Xrm.Page.context.getOrgUniqueName();
var userID = Xrm.Page.context.getUserId();
//create email record
// Prepare the SOAP message.
var xml = "<?xml version='1.0' encoding='utf-8'?>" +"<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'" +
" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
" xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" +
"<soap:Header>" +
"</soap:Header>" +
"<soap:Body>" +
"<Create xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
"<entity xsi:type='email'>" +
"<regardingobjectid type='quote'>" + recordid + "</regardingobjectid>" +
"<subject>" + "Email with Attachment4" + "</subject>" +
"</entity>" +
"</Create>" +
"</soap:Body>" +
"</soap:Envelope>";
// Prepare the xmlHttpObject and send the request.
var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xHReq.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Create");
xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xHReq.setRequestHeader("Content-Length", xml.length);
xHReq.send(xml);
// Capture the result
var resultXml = xHReq.responseXML;
// alert("resultXml " + resultXml);
// Check for errors.
var errorCount = resultXml.selectNodes('//error').length;
if (errorCount != 0) {
alert("ERROR");
var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
alert(msg);
var emailid = resultXml.selectSingleNode("//CreateResult").nodeTypedValue;
alert("emailid" + emailid.toString());
//var emailid = userID;
var post = Object();
post.Body = encodePdf(params);
var email = new Array();
email[0] =new Object();
email[0].id = emailid;
email[0].entityType ='email';
post.Subject ="File Attachment";
post.AttachmentNumber = 1;
post.FileName ="Report.pdf";
post.MimeType ="application/pdf";
post.ObjectId = Object();
post.ObjectId.LogicalName ="email";
post.ObjectId.Id = email[0].id;
post.ObjectTypeCode ="email";
alert(post.ObjectId.Id);
createEntity(post,"ActivityMimeAttachment", "");
alert("created successfully");
email.Subject = "Your Order";
//Set The current order as the Regarding object
email.RegardingObjectId = {
Id: Xrm.Page.data.entity.getId(), //Get the current entity Id , here OrderId
LogicalName: Xrm.Page.data.entity.getEntityName()//Get the current entity name, here it will be “salesOrder”
//Create Email Activity
SDK.JScriptRESTDataOperations.Create(email, "Email", EmailCallBack, function (error) { alert(error.message); });
// Email Call Back function
function EmailCallBack(result) {
email = result; // Set the email to result to use it later in email attachment for retrieving activity Id
var activityPartyFrom = new Object();
// Set the From party of the ActivityParty to relate an entity with Email From field
activityPartyFrom.PartyId = {
Id: customerId, // id of entity you want to associate this activity with.
LogicalName: "contact"
// Set the "activity" of the ActivityParty
activityPartyFrom.ActivityId = {
Id: result.ActivityId,
LogicalName: "email"
// Now set the participation type that describes the role of the party on the activity).
activityPartyFrom.ParticipationTypeMask = { Value: 2 }; // 2 means ToRecipients
// Create the from ActivityParty for the email
SDK.JScriptRESTDataOperations.Create(activityPartyFrom, "ActivityParty", ActivityPartyFromCallBack, function (error) { alert(error.message); });
var activityPartyTo = new Object();
// Set the From party of the ActivityParty to relate an entity with Email From field
activityPartyTo.PartyId = {
Id: ownerId, // id of entity you want to associate this activity with.
LogicalName: "systemuser"
// Set the "activity" of the ActivityParty
activityPartyTo.ActivityId = {
Id: result.ActivityId,
LogicalName: "email"
// Now set the participation type that describes the role of the party on the activity). activityPartyTo.ParticipationTypeMask = { Value: 1 }; // 1 means Sender
// Create the from ActivityParty
SDK.JScriptRESTDataOperations.Create(activityPartyTo, "ActivityParty", ActivityPartyToCallBack, function (error) { alert(error.message); });
//ActivityParty From Callback
function ActivityPartyFromCallBack(result) {
//ActivityParty To Callback
function ActivityPartyToCallBack(result) {
var StringMaker = function () {
this.parts = [];
this.length = 0;
this.append = function (s) {
this.parts.push(s);
this.length += s.length;
this.prepend = function (s) {
this.parts.unshift(s);
this.length += s.length;
this.toString = function () {
return this.parts.join('');
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
function encode64(input) {
var output = new StringMaker();
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
while (i < input.length) {
chr1 = input[i++];
chr2 = input[i++];
chr3 = input[i++];
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
else if (isNaN(chr3)) {
enc4 = 64;
output.append(keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4));
return output.toString();
var bdy = new Array();
var bdyLen = 0;
function concat2Bdy(x) {
bdy[bdyLen] = x;
bdyLen++;
function encodePdf(params) {
bdy = new Array();
bdyLen = 0;
var retrieveEntityReq = new XMLHttpRequest();
var pth = Xrm.Page.context.getServerUrl() + "/Reserved.ReportViewerWebControl.axd?ReportSession=" + params[0] + "&Culture=1033&CultureOverrides=True&UICulture=1033&UICultureOverrides=True&ReportStack=1&ControlID=" + params[1] + "&OpType=Export&FileName=Public&ContentDisposition=OnlyHtmlInline&Format=PDF";
retrieveEntityReq.open("GET", pth, false);
retrieveEntityReq.setRequestHeader("Accept", "*/*");
retrieveEntityReq.send();
BinaryToArray(retrieveEntityReq.responseBody);
return encode64(bdy);
</SCRIPT>
<SCRIPT type=text/vbscript>
Function BinaryToArray(Binary)
Dim i
ReDim byteArray(LenB(Binary))
For i = 1 To LenB(Binary)
byteArray(i-1) = AscB(MidB(Binary, i, 1))
concat2Bdy(AscB(MidB(Binary, i, 1)))
Next
BinaryToArray = byteArray
End Function
</SCRIPT>
</head>
<body>
<input type="button" onclick="createAttachment();" value="Attach Report" />
</body>
</html>
Thanks. and waiting for your valuable comments.
- MittalHello,
Yes, I was able to make my code working as below. Tested on CRM online 2013.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script type="text/javascript">
if (typeof (SDK) == "undefined")
{ SDK = { __namespace: true }; }
SDK.JScriptRESTDataOperations = {
_context: function () {
if (typeof GetGlobalContext != "undefined")
{ return GetGlobalContext(); }
else {
if (typeof Xrm != "undefined") {
return Xrm.Page.context;
else { return new Error("Context is not available."); }
_getServerUrl: function () {
var serverUrl = this._context().getServerUrl()
if (serverUrl.match(/\/$/)) {
serverUrl = serverUrl.substring(0, serverUrl.length - 1);
return serverUrl;
_ODataPath: function () {
return this._getServerUrl() + "/XRMServices/2011/OrganizationData.svc/";
_errorHandler: function (req) {
return new Error("Error : " +
req.status + ": " +
req.statusText + ": " +
JSON.parse(req.responseText).error.message.value);
_dateReviver: function (key, value) {
var a;
if (typeof value === 'string') {
a = /Date\(([-+]?\d+)\)/.exec(value);
if (a) {
return new Date(parseInt(value.replace("/Date(", "").replace(")/", ""), 10));
return value;
Create: function (object, type, successCallback, errorCallback) {
var req = new XMLHttpRequest();
req.open("POST", this._ODataPath() + type + "Set", true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function () {
if (this.readyState == 4 /* complete */) {
if (this.status == 201) {
successCallback(JSON.parse(this.responseText, SDK.JScriptRESTDataOperations._dateReviver).d);
else {
errorCallback(SDK.JScriptRESTDataOperations._errorHandler(this));
req.send(JSON.stringify(object));
Retrieve: function (id, type, successCallback, errorCallback) {
var req = new XMLHttpRequest();
req.open("GET", this._ODataPath() + type + "Set(guid'" + id + "')", true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function () {
if (this.readyState == 4 /* complete */) {
if (this.status == 200) {
successCallback(JSON.parse(this.responseText, SDK.JScriptRESTDataOperations._dateReviver).d);
else {
errorCallback(SDK.JScriptRESTDataOperations._errorHandler(this));
req.send();
Update: function (id, object, type, successCallback, errorCallback) {
var req = new XMLHttpRequest();
req.open("POST", this._ODataPath() + type + "Set(guid'" + id + "')", true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("X-HTTP-Method", "MERGE");
req.onreadystatechange = function () {
if (this.readyState == 4 /* complete */) {
if (this.status == 204 || this.status == 1223) {
successCallback();
else {
errorCallback(SDK.JScriptRESTDataOperations._errorHandler(this));
req.send(JSON.stringify(object));
Delete: function (id, type, successCallback, errorCallback) {
var req = new XMLHttpRequest();
req.open("POST", this._ODataPath() + type + "Set(guid'" + id + "')", true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("X-HTTP-Method", "DELETE");
req.onreadystatechange = function () {
if (this.readyState == 4 /* complete */) {
if (this.status == 204 || this.status == 1223) {
successCallback();
else {
errorCallback(SDK.JScriptRESTDataOperations._errorHandler(this));
req.send();
RetrieveMultiple: function (type, filter, successCallback, errorCallback) {
if (filter != null) {
filter = "?" + filter;
else { filter = ""; }
var req = new XMLHttpRequest();
req.open("GET", this._ODataPath() + type + "Set" + filter, true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function () {
if (this.readyState == 4 /* complete */) {
if (this.status == 200) {
successCallback(JSON.parse(this.responseText, SDK.JScriptRESTDataOperations._dateReviver).d.results);
else {
errorCallback(SDK.JScriptRESTDataOperations._errorHandler(this));
req.send();
__namespace: true
</script>
<script type="text/javascript">
//Create Email and link it with Order as Regarding field
var Xrm;
var email = new Object();
var ownerID = "";
var CustomerId = "";
if (window.opener) { Xrm = window.opener.Xrm; }
else if (window.parent) { Xrm = window.parent.Xrm; }
//Get ownerid who send email of quotation to customer
function GetOwnerID() {
var owner = Xrm.Page.getAttribute("ownerid").getValue();
ownerID = owner[0].id;
var ownerName = owner[0].name;
var entityType = owner[0].entityType;
GetToEmailGUID();
//Get customerid who receive email of quotation from owner
function GetToEmailGUID() {
var Customer = Xrm.Page.getAttribute('customerid').getValue();
CustomerId = Customer[0].id;
var CustomerName = Customer[0].name;
var entityType = Customer[0].entityType;
//if CustomerId is type of "Account" then get Primary Contact id of that account
if (entityType == "account") {
var contact = Xrm.Page.getAttribute("customerid").getValue();
if (contact === null) return;
var serverUrl = Xrm.Page.context.getClientUrl();
var oDataSelect = serverUrl + "/XRMServices/2011/OrganizationData.svc/AccountSet(guid'" + contact[0].id + "')?$select=PrimaryContactId";
var req = new XMLHttpRequest();
req.open("GET", oDataSelect, false);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json;charset=utf-8");
req.onreadystatechange = function () {
if (req.readyState === 4) {
if (req.status === 200) {
var retrieved = JSON.parse(req.responseText).d;
CustomerId = retrieved.PrimaryContactId.Id;
else {
alert(this.statusText);
req.send();
function CreateEmail() {
GetOwnerID();
email.Subject = "Email with Report Attachment";
//Set The current order as the Regarding object
email.RegardingObjectId = {
Id: Xrm.Page.data.entity.getId(), //Get the current entity Id , here OrderId
LogicalName: Xrm.Page.data.entity.getEntityName()//Get the current entity name, here it will be “salesOrder”
//Create Email Activity
SDK.JScriptRESTDataOperations.Create(email, "Email", EmailCallBack, function (error) { alert(error.message); });
// Email Call Back function
function EmailCallBack(result) {
email = result; // Set the email to result to use it later in email attachment for retrieving activity Id
var activityPartyFrom = new Object();
// Set the From party of the ActivityParty to relate an entity with Email From field
activityPartyFrom.PartyId = {
Id: CustomerId, //"79EBDD26-FDBE-E311-8986-D89D6765B238", // id of entity you want to associate this activity with.
LogicalName: "contact"
// Set the "activity" of the ActivityParty
activityPartyFrom.ActivityId = {
Id: result.ActivityId,
LogicalName: "email"
// Now set the participation type that describes the role of the party on the activity).
activityPartyFrom.ParticipationTypeMask = { Value: 2 }; // 2 means ToRecipients
// Create the from ActivityParty for the email
SDK.JScriptRESTDataOperations.Create(activityPartyFrom, "ActivityParty", ActivityPartyFromCallBack, function (error) { alert(error.message); });
var activityPartyTo = new Object();
// Set the From party of the ActivityParty to relate an entity with Email From field
activityPartyTo.PartyId = {
Id: ownerID, //"79EBDD26-FDBE-E311-8986-D89D6765B238", // id of entity you want to associate this activity with.
LogicalName: "systemuser"
// Set the "activity" of the ActivityParty
activityPartyTo.ActivityId = {
Id: result.ActivityId,
LogicalName: "email"
// Now set the participation type that describes the role of the party on the activity).
activityPartyTo.ParticipationTypeMask = { Value: 1 }; // 1 means Sender
// Create the from ActivityParty
SDK.JScriptRESTDataOperations.Create(activityPartyTo, "ActivityParty", ActivityPartyToCallBack, function (error) { alert(error.message); });
//ActivityParty From Callback
function ActivityPartyFromCallBack(result) {
//ActivityParty To Callback
function ActivityPartyToCallBack(result) {
GetReportId('Quotation');
//Create attachment for the created email
function CreateEmailAttachment() {
//get reporting session and use the params to convert a report in PDF
var params = getReportingSession();
//Email attachment parameters
var activitymimeattachment = Object();
activitymimeattachment.ObjectId = Object();
activitymimeattachment.ObjectId.LogicalName = "email";
activitymimeattachment.ObjectId.Id = email.ActivityId;
activitymimeattachment.ObjectTypeCode = "email",
activitymimeattachment.Subject = "File Attachment";
activitymimeattachment.Body = encodePdf(params);
activitymimeattachment.FileName = "Report.pdf";
activitymimeattachment.MimeType = "application/pdf";
//Attachment call
SDK.JScriptRESTDataOperations.Create(activitymimeattachment, "ActivityMimeAttachment", ActivityMimeAttachmentCallBack, function (error) { alert(error.message); });
//ActivityMimeAttachment CallBack function
function ActivityMimeAttachmentCallBack(result) {
var features = "location=no,menubar=no,status=no,toolbar=no,resizable=yes";
var width = "800px";
var height = "600px";
window.open(Xrm.Page.context.getServerUrl() + "main.aspx?etc=" + 4202 + "&pagetype=entityrecord&id=" + email.ActivityId, "_blank", features);
// To open window which works in outlook and IE both
//openStdWin(Xrm.Page.context.getServerUrl() + "main.aspx?etc=" + 4202 + "&pagetype=entityrecord&id=" + email.ActivityId, "_blank", width, height, features);
//This method will get the reportId based on a report name that will be used in getReportingSession() function
function GetReportId(reportName) {
var oDataSetName = "ReportSet";
var columns = "ReportId";
var filter = "Name eq '" + reportName + "'";
retrieveMultiple(oDataSetName, columns, filter, onSuccess);
function retrieveMultiple(odataSetName, select, filter, successCallback) {
var serverUrl = Xrm.Page.context.getServerUrl();
var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
var odataUri = serverUrl + ODATA_ENDPOINT + "/" + odataSetName + "?";
if (select) {
odataUri += "$select=" + select + "&";
if (filter) {
odataUri += "$filter=" + filter;
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: odataUri,
beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("Accept", "application/json");
success: function (data) {
if (successCallback) {
if (data && data.d && data.d.results) {
successCallback(data.d.results);
else if (data && data.d) {
successCallback(data.d);
else {
successCallback(data);
error: function (XmlHttpRequest, errorThrown) {
if (XmlHttpRequest && XmlHttpRequest.responseText) {
alert("Error while retrieval ; Error – " + XmlHttpRequest.responseText);
function onSuccess(data) {
reportId = data[0].ReportId.replace('{', ").replace('}', ");
CreateEmailAttachment(); // Create Email Attachment
//Gets the report contents
function getReportingSession() {
var pth = Xrm.Page.context.getServerUrl() + "/CRMReports/rsviewer/reportviewer.aspx";
var retrieveEntityReq = new XMLHttpRequest();
var Id = Xrm.Page.data.entity.getId();
var quotationGUID = Id.replace('{', ""); //set this to selected quotation GUID
quotationGUID = quotationGUID.replace('}', "");
var reportName = "Quotation"; //set this to the report you are trying to download
var reportID = "7C39D18F-1DC6-E311-8986-D89D6765B238"; //set this to the guid of the report you are trying to download
var rptPathString = ""; //set this to the CRMF_Filtered parameter
var strParameterXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'><entity name='quote'><all-attributes /><filter type='and'><condition attribute='quoteid' operator='eq' uitype='quote' value='" + quotationGUID + "' /> </filter></entity></fetch>";
retrieveEntityReq.open("POST", pth, false);
retrieveEntityReq.setRequestHeader("Accept", "*/*");
retrieveEntityReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
rptPathString = "id=%7B" + reportID + "%7D&uniquename=" + Xrm.Page.context.getOrgUniqueName() + "&iscustomreport=true&reportnameonsrs=&reportName=" +
reportName + "&isScheduledReport=false&p:CRMAF_Filteredquote=" + strParameterXML;
//remove the part starting from &p:salesorderid if your report has no parameters
retrieveEntityReq.send(rptPathString);
var x = retrieveEntityReq.responseText.indexOf("ReportSession=");
var ret = new Array();
ret[0] = retrieveEntityReq.responseText.substr(x + 14, retrieveEntityReq.responseText.indexOf("&", x) - x - 14); //the session id
x = retrieveEntityReq.responseText.indexOf("ControlID=");
ret[1] = retrieveEntityReq.responseText.substr(x + 10, retrieveEntityReq.responseText.indexOf("&", x) - x - 10); //the control id
return ret;
var bdy = new Array();
var bdyLen = 0;
function concat2Bdy(x) {
bdy[bdyLen] = x;
bdyLen++;
function encodePdf(params) {
bdy = new Array();
bdyLen = 0;
var retrieveEntityReq = new XMLHttpRequest();
var pth = Xrm.Page.context.getServerUrl() + "/Reserved.ReportViewerWebControl.axd?ReportSession=" + params[0] +
"&Culture=1033&CultureOverrides=True&UICulture=1033&UICultureOverrides=True&ReportStack=1&ControlID=" + params[1] +
"&OpType=Export&FileName=Public&ContentDisposition=OnlyHtmlInline&Format=PDF";
retrieveEntityReq.open("GET", pth, false);
retrieveEntityReq.setRequestHeader("Accept", "*/*");
retrieveEntityReq.send();
BinaryToArray(retrieveEntityReq.responseBody);
return encode64(bdy);
var StringMaker = function () {
this.parts = [];
this.length = 0;
this.append = function (s) {
this.parts.push(s);
this.length += s.length;
this.prepend = function (s) {
this.parts.unshift(s);
this.length += s.length;
this.toString = function () {
return this.parts.join('');
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
function encode64(input) {
var output = new StringMaker();
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
while (i < input.length) {
chr1 = input[i++];
chr2 = input[i++];
chr3 = input[i++];
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
} else if (isNaN(chr3)) {
enc4 = 64;
output.append(keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4));
return output.toString();
</script>
<script type="text/vbscript">
Function BinaryToArray(Binary)
Dim i
ReDim byteArray(LenB(Binary))
For i = 1 To LenB(Binary)
byteArray(i-1) = AscB(MidB(Binary, i, 1))
concat2Bdy(AscB(MidB(Binary, i, 1)))
Next
BinaryToArray = byteArray
End Function
</script>
</head>
<body>
<input type="button" onclick="CreateEmail();" value="Attach Report" />
</body>
</html>
Thank you,
Mittal.
Maybe you are looking for
-
ISE 1.2 - Wrong Displayed Time
Hi everybody, I have an issue with ISE 1.2.0.899 concerning the sponsor portal. I have set up the ISE in UTC, and synced it to NTP. If I log in as a sponsor and create a guest account in timezone e.g. GMT +02:00 Europe/Zurich ... ...I get a confirmat
-
Photoshop Elements 5.0 PC. Moved. How do I change outgoing mail server? Photoshop trying to connect to old server for emailing pictures. Thanks
-
CONNECTING ORACLE 9I OR 10G DATABASE WITH ORACLE 10G FORMS AND REPORTS
pls tell how to connect oracle 9i or 10g database with oracle developer suite 10g . though the forms are getting connected but not running with error as FRM-10142 the HTTP listner is not running on pls start the listner or check your runtime preferen
-
I updated/installed 8.0.1 a month ago, (had 3.5. 0 or 1 can't remember) and under HELP in the top toolbar, About Firefox, said I have 8.0.1. Today, Sunday 12/18/11 tried updating something (forget what) and it said I have old version and need to upda
-
Mac Pro does not auto-sleep (manual sleeping if fine!)
I have a small annoyance with my 2009 (Nehalem) Mac Pro I am wondering if someone can help with, or suggest something, please: The Mac Pro does not auto-sleep; ever. I have played around with the sleep time settings, and enabled or disabled the 'slee