Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

DI API, Block Sending Newsletter

emresuzer
Member

Hi,

I would like to disable block sending newsletter by setting the BlockSendingMarketingContent variable to Yes but code gives -5002 error.

Does anyone know how to do it?

BusinessPartners bp = Common.Parameters.company.GetBusinessObject(BoObjectTypes.oBusinessPartners); if (bp.GetByKey(mi.BusinessPartnerId)) { ContactEmployees employees = bp.ContactEmployees; for (int i = 0; i < employees.Count; i++) { employees.SetCurrentLine(i); if (employees.E_Mail.ToLower().Equals(mailAddress)) { employees.BlockSendingMarketingContent = BoYesNoEnum.tYES; var chk = bp.Update(); if (chk == 0) { XtraMessageBox.Show("Sending e-mail newsletter to the contact is disabled."); } else { string err = Parameters.company.GetLastErrorDescription(); XtraMessageBox.Show(string.Format("Couldn't disable newsletter sending: {0}", err)); } break; } } }

  • SAP Managed Tags:
3 REPLIES 3

josedvm
Participant
0 Kudos

Ok, I guess I achieved it.

Although I tried with BusinessPartners object, not with ContactEmployees (I have to test what occurs when the BP has Contacts).

The code that worked:

BusinessPartners partner = Company.GetBusinessObject(BoObjectTypes.oBusinessPartners);
partner.GetByKey(cardCode);

var bPBlockSendingMarketingContents = partner.BPBlockSendingMarketingContents;

// Block Email
bPBlockSendingMarketingContents.CommunicationMediaId = -1;
bPBlockSendingMarketingContents.Choose = BoYesNoEnum.tYES;

bPBlockSendingMarketingContents.Add();

// Block Fax
bPBlockSendingMarketingContents.CommunicationMediaId = -2;
bPBlockSendingMarketingContents.Choose = BoYesNoEnum.tYES;

partner.BlockSendingMarketingContent = BoYesNoEnum.tYES;

partner.Update();

Previous attempts and explanation

I tried setting directly the value for BlockSendingMarketingContent to Yes and got the same error: 5002. Using both DI API and the Service Layer.

Then, in the Business Partner Master Data form, I noticed you must at least check once the Choose Column in the Communication Media dialog to set Block Sending Marketing Content to True. This dialog appears when you try to check the Block Sending Marketing Content checkbox.

So I tried setting the Choose property to Yes for each row in BPBlockSendingMarketingContents child object, but It did'nt work. Surprisingly, there was only one row with a Media ID equals to 0, when in the GUI I saw Email and Fax, whose IDs are -1 and -2 (check OCMM table).

So I concluded the rows were missing, tried the code above and fortunately it worked (check the table CRDC before and after).

In our SDK Help there is no entry in the DI API Reference for the BPBlockSendingMarketingContents class. It's also surprising that the BPBlockSendingMarketingContents property does not have a Count property!

Using SAP BO 9.20.160 PL 06.

  • SAP Managed Tags:

Hey guys,
if you want to block the Contact Employee, do this:


public void BlockSendingMarketingContentForEmployee(string cardCode, int cntctCode)
{
    var businessPartners =
        (BusinessPartners) this.oCompany.GetBusinessObject(BoObjectTypes.oBusinessPartners);
    if (!businessPartners.GetByKey(cardCode))
    {
        throw new Exception("Coudn't find contact by ContactCode");
    }

    // go through all ContactEmployees and find the one with the right InternalCode
    for (var i = 0;  i < businessPartners.ContactEmployees.Count; i++)
    {
        businessPartners.ContactEmployees.SetCurrentLine(i);
        if (businessPartners.ContactEmployees.InternalCode.Equals(cntctCode))
        {
            var blockRecordset = businessPartners.ContactEmployees.ContactEmployeeBlockSendingMarketingContents;
            blockRecordset.Add();
            blockRecordset.SetCurrentLine(0);
            blockRecordset.CommunicationMediaId = -1;
            blockRecordset.ContactEmployeeAbsEntry = cntctCode;
            blockRecordset.Choose = BoYesNoEnum.tYES;
    
            blockRecordset.SetCurrentLine(1);
            blockRecordset.CommunicationMediaId = -2;
            blockRecordset.ContactEmployeeAbsEntry = cntctCode;
            blockRecordset.Choose = BoYesNoEnum.tYES;
    
            businessPartners.ContactEmployees.BlockSendingMarketingContent = BoYesNoEnum.tYES;
    
            break;
        }
    }
    
    if ( businessPartners.Update() != 0)
    {
        throw new Exception("Couldn't update business partner");
    }
}

We searched a lot, when we finally found out you need to set the field blockRecordset.ContactEmployeeAbsEntry.

  • SAP Managed Tags:

0 Kudos

ContactEmployeeAbsEntry doesn't have a set modifier, did you alter the DI API code?

BTW just a heads up, if you retrieve a Businesspartner object the ContactEmployeeBlockSendingMarketingContents will be empty, and upon trying to update you need to add that object back manually 😕

  • SAP Managed Tags: