Esther
Esther

Reputation: 11

error in Add BP Campaign Using C# :Invalid activity type [OCLG.CntctType] [Message 3533-2]

I am trying to add a campaign in SAP using DI API in C# and I get this error:

Invalid Activity Type [OCLG.CntctType] [Message 3533-2] Error Code -5002

Can anyone help me with this?

My code is:

public bool CreateCampaign()
{
    try
    {
        System.Data.DataTable dtdiz;
        SapSDK.SAP_DI.Queries.GetSQLRes("exec [dbo].[Getcards] ".ToString(), out dtdiz);
        if (dtdiz.Rows.Count == 0)
        {
            CustomLog.MyLogger.error("exec [dbo].[Getcards]  : dtdiz not found");
            return false;
        }
        SAPbobsCOM.CampaignsService oCampaignService = SapSDK.SapCon.getInstance.oCompany.GetCompanyService().GetBusinessService(SAPbobsCOM.ServiceTypes.CampaignsService);
        SAPbobsCOM.Campaign oCampaign = oCampaignService.GetDataInterface(SAPbobsCOM.CampaignsServiceDataInterfaces.csCampaign);
        SAPbobsCOM.CampaignParams oCampaignParams = (SAPbobsCOM.CampaignParams)oCampaignService.GetDataInterface(SAPbobsCOM.CampaignsServiceDataInterfaces.csCampaignParams);
        oCampaign.TargetGroupType = SAPbobsCOM.TargetGroupTypeEnum.tgtCustomer;
        oCampaign.StartDate = DateTime.Today;
        oCampaign.FinishDate = DateTime.Today.AddYears(1);
        oCampaign.Remarks = "This is a test for Campaign";
        oCampaign.CampaignName = "TEST Campaign 111";
        for (int i = 0; i < dtdiz.Rows.Count; i++)
        {
            
            oCampaign.CampaignBusinessPartners.Add().BPCode = dtdiz.Rows[i][0].ToString();
            oCampaign.CampaignBusinessPartners.Add().CreateActivity = SAPbobsCOM.BoYesNoEnum.tNO;
            oCampaign.CampaignBusinessPartners.Add();
        }

        //oCampaign.CampaignItems.Add().ItemCode = "A00001";
        //  oCampaign.AttachementsEntry = 2; // AbsEntry from the OATC Table
        oCampaignService.Add(oCampaign);
        return true;
    }
    catch (Exception ex) 
    {
        CustomLog.MyLogger.error(ex);
        return false;
    }

}

Upvotes: 0

Views: 43

Answers (1)

Praxiom
Praxiom

Reputation: 646

i think the issue is with calling .Add multiple times for the CampaignBusinessPartners

Try to us .item() to select the record you just added and update from there:

  for (int i = 0, loopTo = dtdiz.Rows.Count - 1; i <= loopTo; i++)
{

    oCampaign.CampaignBusinessPartners.Add();
    oCampaign.CampaignBusinessPartners.Item(i).BPCode = dtdiz.Rows(i)(0).ToString();

}

please note:

After an object is added to this collection, the database is not automatically updated. You must then update the GeneralData object to which this collection belongs, by executing the Update method of the GeneralService service.

-From the SDK Help

Upvotes: 0

Related Questions