cancel
Showing results for 
Search instead for 
Did you mean: 

B1iF 2.0 Draft to Document

0 Kudos
508

Hello.

I'm trying to generate a document from a Draft on B1iF. I'm working on the 2.0 version. I read the documentation and found how to do this on the 1.0 version but, as I said, I'm on the 2.0 version.

My scenario is as follow:

- Expose a webservice that receives a JSON with the DocEntry of the Draft. In my case is a Purchase Invoice Draft.

- Look for this draft on the ODRF table (just to be sure that the draft exists)

- Generate the final Purchase Invoice document FROM the Draft (This is the step that I need)

- Return the final DocNum of the Purchase Invoice in the response of the webservice call.

Many Thanks for any help 🙂

Accepted Solutions (1)

Accepted Solutions (1)

Hi Matija.

The solution is simpler than that. On the node you use to create the DI Call, you can use the command "saveDraftToDocument" as the method:

And this works nicely 🙂

mgregur
Active Contributor
0 Kudos

Hi Jose Antonio,

thanks for the comment, I actually never used a scenario for saving from Draft to a Document, but to create following documents (e.g. automatic creation of Invoice from Delivery Note, automatic PO creation for SO items that are not on stock etc.).

BR,

Matija

Answers (1)

Answers (1)

mgregur
Active Contributor

Hi,

First you need to retrieve the structure of that draft. Next, you need an atom to prepare all info, structure as follows is for DI API call based data (please check and change any IDs as per your recieved structure from this draft):

<xsl:variable name="query" select="/vpf:Msg/vpf:Body/vpf:Payload[@Role='S']/BOM/BO/AddressExtension/row"></xsl:variable>
<Envelope2 throwException="true" autoCommit="true">
                <DiCall>
                    <Header>
                        <Action>add</Action>
                    </Header>
                    <Body>
                        <BOM>
                            <BO>
                                <AdmInfo>
                                    <Object>13</Object>
                                    <Version>2</Version>
                                </AdmInfo>
                                <xsl:variable name="DocEntry">
                                    <xsl:value-of select="/vpf:Msg/vpf:Body/vpf:Payload[@Role='S']/BOM/BO/Documents/row/DocEntry"></xsl:value-of>
                                </xsl:variable>
                                <AddressExtension>
                                    <row>
                                        <xsl:copy-of select="$query/*"></xsl:copy-of>
                                    </row>
                                </AddressExtension>
                                <Document_Lines>
                                    <xsl:for-each select="/vpf:Msg/vpf:Body/vpf:Payload[@Role='S']/BOM/BO/Document_Lines/row">
                                        <row>
                                            <ItemCode>
                                                <xsl:value-of select="ItemCode"></xsl:value-of>
                                            </ItemCode>
                                            <Quantity>
                                                <xsl:value-of select="Quantity"></xsl:value-of>
                                            </Quantity>
                                            <UnitPrice>
                                                <xsl:value-of select="Price"></xsl:value-of>
                                            </UnitPrice>
                                            <Currency>
                                                <xsl:value-of select="Currency"></xsl:value-of>
                                            </Currency>
                                            <WarehouseCode>
                                                <xsl:value-of select="WarehouseCode"></xsl:value-of>
                                            </WarehouseCode>
                                            <BaseType>
                                                <xsl:value-of select="ObjType"></xsl:value-of>
                                            </BaseType>
                                            <BaseEntry>
                                                <xsl:value-of select="DocEntry"></xsl:value-of>
                                            </BaseEntry>
                                            <BaseLine>
                                                <xsl:value-of select="LineNum"></xsl:value-of>
                                            </BaseLine>
                                        </row>
                                    </xsl:for-each>
                                </Document_Lines>
                            </BO>
                        </BOM>
                    </Body>
                </DiCall>
            </Envelope2><br>

Last step is saving the new document by using B1DI Adapter. XPath would be (assuming previous atom is "DOCprepare"):

/vpf:Msg/vpf:Body/vpf:Payload[./@id='DOCprepare']/Envelope2<br>

Please note that this might need some minor tweaking, as I took this for one of my scenarios.

BR,

Matija