cancel
Showing results for 
Search instead for 
Did you mean: 

Need to add Business Partner using XML (DI Server)

Former Member
0 Kudos

Hello Experts,

I am stuck at a place and need your guidance.

I need to add a business partner into SBO using XML(DI Server).

have a look at the code given below.

Plz let me know what is the issue, or where i am wrong.

Any inputs will be helpful.

private void ADDBP_Click(object sender, EventArgs e)

        {

            this.CreateSession();

            try

            {

                string sCmd = @"<?xml version=""1.0"" encoding=""UTF-16""?>";

                sCmd += @"<Envelopes>";

                sCmd += @"<env:Envelope xmlns:env=""http://schemas.xmlsoap.org/soap/envelope/"">";

                sCmd += @"<env:Header><SessionID>" + this.sessionId + "</SessionID></env:Header>";

                sCmd += @"<env:Body>";

                sCmd += @"<dis:AddObject xmlns:dis=""http://www.sap.com/SBO/DIS"" CommandID=""Add BP"">";

                sCmd += @"<BOM>";

                sCmd += @"<BO>";

                sCmd += @"<AdmInfo>";

                sCmd += @"<Object>oBusinessPartners</Object>";

                sCmd += @"</AdmInfo>";

                sCmd += @"<BusinessPartners>";

                sCmd += @"<row>";

                sCmd += @"<CardCode>" + bpcode.Text + "</CardCode>";

                sCmd += @"</row>";

                sCmd += @"<row>";

                sCmd += @"<CardName>" + bpname.Text + "</CardName>";

                sCmd += @"</row>";

                sCmd += @"<row>";

                sCmd += @"<CardType>" + bptype.Text + "</CardType>";

                sCmd += @"</row>";

                sCmd += @"</BusinessPartners>";

                sCmd += @"<Document_Lines>";

                sCmd += @"<row>";

                sCmd += @"<TaxLiable>" + "tNO" + "</TaxLiable>";   

                sCmd += @"</row>";

                sCmd += @"<row>";

                sCmd += @"<WTLiable>" + "tNO" + "</WTLiable>";

                sCmd += @"</row>";

                sCmd += @"</Document_Lines>";

                sCmd += @"</BO>";

                sCmd += @"</BOM>";

                sCmd += @"</dis:AddObject>";

                sCmd += @"</env:Body></env:Envelope>";

                sCmd += @"</Envelopes>";

                //MessageBox.Show(sCmd);

                string itemData = node.BatchInteract(sCmd);

                MessageBox.Show(itemData);

                MessageBox.Show("Businees partner Susscesfully Add In SAP Business One");

                this.DisconnectSession();

            }

       

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message);

            }

        }

i attach snap which give me error...

Thanks

Nikunj

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Nikunj,

What Pedro Told You should Follow it once.

Also if you want to use it in the same code then you need to use the below code.

                sCmd += @"<BusinessPartners>";

                sCmd += @"<row>";

                sCmd += @"<CardCode>" + bpcode.Text + "</CardCode>";

                sCmd += @"<CardName>" + bpname.Text + "</CardName>";

                sCmd += @"<CardType>" + bptype.Text + "</CardType>";

                sCmd += @"<SubjectToWithholdingTax>" + "N" + "</SubjectToWithholdingTax>";

                sCmd += @"</row>";

                sCmd += @"</BusinessPartners>";

I am sure this will work for you.

Thanks,

Amit.

Answers (3)

Answers (3)

0 Kudos

Hello
I am facing just one problem while adding business partner in sap using DI Server.
I need to provide the card code manually in api. but I want to generate it automatically. Like in the SAP portal when we want to add any business partner if we select the code : customer it generate the code automatically and if we select manual then we need to add code.
How I can achieve this using DI Server.

I want to generate card code automatically.

maik_delly
Active Contributor
0 Kudos

Hi Nikunj,

instead of using "AddObject" of DIS use BusinessPartnerService :


<?xml version="1.0" ?>

<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>

        <MsgHeader xmlns="http://www.sap.com/SBO/DIS">

            <SessionID>71484CA7-877C-4A50-8F7F-54D68A2A7322</SessionID>

            <ServiceName>BusinessPartnersService</ServiceName>

        </MsgHeader>

    </soap:Header>

    <soap:Body>

        <Add xmlns="BusinessPartnersService">

            <BusinessPartner xmlns="http://www.sap.com/SBO/DIS">

                <CardCode>test001</CardCode>

                <CardName>mytest001</CardName>

            </BusinessPartner>

        </Add>

    </soap:Body>

</soap:Envelope>

regards,

Maik

Former Member
0 Kudos

Hi Maik,

as per your suggestion,

i did changes but now am facing below error.

Kindly help with it.



Thanks,

Nikunj

maik_delly
Active Contributor
0 Kudos

Hi Nikunj,

it is because you are using BatchInteract to send the message. You have 2 options :

1. Use Interact instead

2. Adjust the SOAP Envelope ( Basically add "Envelopes" tag )

regards,

Maik

Former Member
0 Kudos

Hi Maik,

i did changes but now am facing same error. like NO SOAP Envelop found.

Kindly help with it.


i can attach 3 image :

1) create session

2) Disconenct Session

3) add Business Partners


Plz..see image and give me idea where i am wrong.


1) create Session












2) Disconnect Session





3) Add Business Partners




maik_delly
Active Contributor
0 Kudos

It must be "Envelopes" not "Envelope" -> BatchInteract allows you to send multiple SOAP Envelopes.

Former Member
0 Kudos

Hi maik,

after making the told changes.

I again came to my initial error that "Enter PAN No. for Business Partner."

Now to enter a BP record without PAN No. I need remove the withHolding tax TICK mark in the Accounting TAB.

Kindly suggest How I can do this.

I have to use this for Indian Localization.

Let me know if you need more information. Also  I have added the error screen shot for your reference.

Thanks,

Nikunj

maik_delly
Active Contributor
0 Kudos

Hi Nikunj,

since it is an indian localization requirement I can't test, but i my understanding you just have to add this child element to BusinessPartner tag  :

<SubjectToWithholdingTax>tNO</SubjectToWithholdingTax>

And I see that this is what Pedro suggested aswell, only that now its the BusinessPartnerService.

good luck,

Maik

pedro_magueija
Active Contributor
0 Kudos

Hi Nikunj,

The message is requesting the PAN number. Could this be something specific to the localization of Business One you are using?


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn

Former Member
0 Kudos

Hi Pedro,

Yes the system is in Indian Localization.

We need to enter the PAN details if the Withholding Tax is kept to Yes.

We need to keep Withholding tax to false or tNO. while entering a BP master record to avoid inputting PAN details. But I am not able to do it using the above code. It generates the msg "Enter PAN no. " even if I used the below code.

                sCmd += @"<row>";

                sCmd += @"<TaxLiable>" + "tNO" + "</TaxLiable>"; 

                sCmd += @"</row>";

                sCmd += @"<row>";

                sCmd += @"<WTLiable>" + "tNO" + "</WTLiable>";

                sCmd += @"</row>";

Let me know if this is the right way to disable the withholding tax details.

DO Let me know if you need more information. I hope you will get what I meant to say.

Thanks and regards,

Nikunj.

http://in.linkedin.com/in/mehtanikunj

pedro_magueija
Active Contributor
0 Kudos

Hi Nikunj,

I had a look at an SOAP envelope and it should look like this:

<BOM>

  <BO>

    <AdmInfo>

      <Object>oBusinessPartners</Object>

    </AdmInfo>

    <BusinessPartners>

      <row>

        <CardCode>C23900</CardCode>

        <CardName>Efotech GmbH</CardName>

        <CardType>cCustomer</CardType>

        <SubjectToWithholdingTax>tNO</SubjectToWithholdingTax>

      </row>

    </BusinessPartners>

    ...

  </BO>

</BOM>

The <SubjectToWithholdingTax> is the WTLiable you mentioned.

You can get the template for a given business object by using:

<?xml version="1.0" encoding="UTF-16"?>

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">

<env:Header>

  <SessionID>32D83BB6-F3AD-985F-D4BC-655B3D9ACBE2</SessionID>

</env:Header>

<env:Body>

  <dis:GetBusinessObjectTemplate xmlns:dis="http://www.sap.com/SBO/DIS">

   <Object>oBusinessPartners</Object>

  </dis:GetBusinessObjectTemplate>

</env:Body>

</env:Envelope>

The server will return a template that you should use for that business object, that way you can know for sure what tags to use.


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn

Former Member
0 Kudos

Hi Pedro,

as per your suggestion,

i did changes but now am facing below error.

Kindly help with it.

Regards,

Nikunj

pedro_magueija
Active Contributor
0 Kudos

Hi Nikunj,

The GetBusinessObjectTemplate soap structure above should be just like it's posted (just change the session id). From your screen shot seems that you are sending a different soap message.

Note that when you use GetBusinessObjectTemplate you get back the xml to use for your adding message. GetBusinessObjectTemplate will not add the business partner itself.

Use the xml returned by GetBusinessObjectTemplate to build another soap message with the tags shown by the returned xml.

Understand?


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn

Former Member
0 Kudos

Hi Pedro,

i have also changed session id but it will generate error as shown above image.

i can't solve my problem.

I have attach one txt file which cover full code.

Kindly help with it.  where is, i am wrong?