Monday, 13 October 2014

RTF Template - Word Features

Q. How to repeat table header on each page?
Ans: Right click on first row of table header and Go to table properties and click on Row Tab. Here check the second option checkbox- Repeat as header row at the top of each page. For rest of the rows uncheck this checkbox and check first option- Allow row to break across pages

Q. How to insert tag in header/footer portion of RTF template?
Ans. Usually we are not allowed to insert tag in header/footer. But we can insert text of the tag directly in header/footer, it indirectly work as a tag in template. Eg: (?CountryName?)
Q. Not able to print tag value even after opening the loop?
Ans. Sometimes we are not able to print tag value even after properly opening and closing the loop. In such case, provide complete path for tag in form field help text.
Eg: (?/OutboundPaymentInstruction/OutboundPayment/Payee/SupplierNumber?)
Q. How to remove line border between records of a table?
Ans. To manage line border between records of a table in loop, use outside border option in Formatting Menu of Word. If it still doesnt work, then create a table in excel by formatting cells and paste it in RTF template.

Note: Replace symbol '(' with '<' and ')' with '>' in all above xml/xsl syntax

RTF Template - IF Condition

You can use IF condition directly or using xdofx in RTF Template. Below are few examples
(?xdofx:if LENGTH(/XXBRPRPOP/LIST_G_INIT_INFO/G_INIT_INFO/LIST_G_HEADERS/G_HEADERS/POH_CUSTOMER)=0 THEN 'DELIVER TO:'POD_REQUESTOR_NAME'('POD_QUANTITY_ORDERED')' END IF?)


(?xdofx:if LENGTH(/XXBRPRPOP/LIST_G_INIT_INFO/G_INIT_INFO/LIST_G_HEADERS/G_HEADERS/POH_CUSTOMER) !=0 AND(/XXBRPRPOP/LIST_G_INIT_INFO/G_INIT_INFO/LIST_G_HEADERS/G_HEADERS/POH_CUSTOMER)!=POD_REQUESTOR_NAME THEN 'DELIVER TO:'POD_REQUESTOR_NAME'('POD_QUANTITY_ORDERED')' END IF?)


(?if:string-length(/XXBRPRPOP/LIST_G_INIT_INFO/G_INIT_INFO/LIST_G_HEADERS/G_HEADERS/LIST_G_CANCEL_RELEASE/CANCEL_RELEASE_DATE)!=0?)


(?xdofx:if AMOUNT > 1000 then ’Higher’
else
if AMOUNT < 1000 then ’Lower’
else
’Equal’
end if?>


Note: Replace symbol '(' with '<' and ')' with '>' for starting and ending Tags above

RTF Template - Page Break

nsert definite space in RTF templateUse below syntax in Tag to insert space before or after in your template. As point increases, space also get increased.
(xsl:attribute name='space-before')100pt(/xsl:attribute)
(xsl:attribute name='space-after')100pt(/xsl:attribute)


Inserting pagebreak
1) Below is the simple syntax to add pagebreak
(?split-by-page-break:?)

2) We can also use below syntax for before and after
(xsl:attribute name="break-before")page(/xsl:attribute)
(xsl:attribute name="break-after")page(/xsl:attribute)
3) Conditional pagebreak, use below syntax. Here we are inserting page-break if value of variable no_of_lines_per_page is equal to total records in loop inner_group. Variable is always referred by $ in XSL
(xsl:if xdofo:ctx="inblock" test="$no_of_lines_per_page=count($inner_group)")(xsl:attribute name="break-before")page(/xsl:attribute) (/xsl:if)Note: Replace symbol '(' with '<' and ')' with '>' in all above xml/xsl syntax

RTF Template Signature Printing

Fixed SignatureIf you have fixed logo or signature to print in RTF template, then perform below steps
1) Copy file in .gif format to $OA_MEDIA path at Application Server
2) Insert picture in RTF template and add below text in Web Tab
url:{'${OA_MEDIA}/MAB_NEW.gif'}

Dynamic Signature
If you want to print signature based on Tag value in RTF template, then perform below steps
1) Copy file in .gif format to $OA_MEDIA path at Application Server
2) File name must be same as Tag value. For example, if tag value is Amit, then your file name should be Amit.gif
3) Finally, Insert picture in RTF template and add below text in Web Tab
url:{concat('$[OA_MEDIA]/',.//PO_NUMBER)}

RTF Template Variable

Define Constant Variable
This variable remains constant for entire file
(xsl:variable name="no_of_lines_per_page" select="number(15)"/)

Assigning Group/Repeating Frame to Variable
(xsl:variable xdofo:ctx="incontext" name="inner_group" select=".//DocumentPayable"/)
Here DocumentPayable is a Group which is assigned to variable inner_group. So we can loop through this variable as below
(?for-each:$inner_group?)
Here you can also get total records in a group anytime using count($inner_group)

Incrementing Variable in Loop
Declare variable before loop and increment it inside loop as below
(?xdoxslt:set_variable($_XDOCTX, ‘counter’, 0)?)
(?for-each:G_LINES?)
(?xdoxslt:set_variable($_XDOCTX, ‘counter’, xdoxslt:get_variable($_XDOCTX, ‘counter’) + 1)?)
(?xdoxslt:get_variable($_XDOCTX, ‘counter’)?)
(?end for-each?)

However, this variable is not referenced using $ symbol

Printing Variable ValueThe "xsl:value-of" element can be used to select the value of an XML element and add it to the output
(xsl:value-of select=”$var1”/)

Note: Replace symbol '(' with '<' and ')' with '>' for starting and ending Tags above

XML Creation Thru PLSQL

CREATE OR REPLACE PROCEDURE gl_inter_company_trans 
(retcode OUT VARCHAR2,
errbuf OUT VARCHAR2,
p_period VARCHAR2,
p_operating_unit VARCHAR2,
p_status1 VARCHAR2)
IS

CURSOR gl_detail 
(p_status IN VARCHAR2,
p_period VARCHAR2,
p_operating_unit VARCHAR2)
IS
SELECT receiver, sender, transaction_number, period, entered_date,
description, note, amount, NAME, attribute10, status, gl_date,
sendor_gl_transfer, receiver_gl_transfer, CONTEXT
FROM (SELECT rsub.NAME receiver, ssub.NAME sender,
gl_.transaction_number, gl_.sender_period_name period,
gl_.entered_date, gl_.description, gl_.note,
( NVL (gl_.sender_running_total_dr, 0)
- NVL (gl_.sender_running_total_cr, 0)
) amount,
REPLACE (typ.NAME, '&', '') NAME, gl_.attribute10,
DECODE (gl_.status, 'R', 'Review', 'Approved') status,
gl_.gl_date,
DECODE (gl_.sender_transfer_flag, 'Y', 'Yes', 'No') sendor_gl_transfer,
DECODE (gl_.receiver_transfer_flag, 'Y', 'Yes', 'No') receiver_gl_transfer,
gl_.CONTEXT
FROM gl.gl_iea_transactions gl_,
gl.gl_iea_transaction_types typ,
gl.gl_iea_subsidiaries ssub,
gl.gl_iea_subsidiaries rsub
WHERE typ.transaction_type_id = gl_.transaction_type_id
AND ssub.subsidiary_id = gl_.sending_subsidiary_id
AND rsub.subsidiary_id = gl_.receiving_subsidiary_id
AND gl_.status = 'R'
AND gl_.status = NVL (p_status, gl_.status)
AND gl_.sender_period_name = NVL (p_period, gl_.sender_period_name)
AND ( ssub.NAME = NVL (p_operating_unit, ssub.NAME)
OR rsub.NAME = NVL (p_operating_unit, rsub.NAME)));

p_status VARCHAR2 (100);
v_transaction_num_prev VARCHAR2 (50) := '00000';
v_transaction_num_curr VARCHAR2 (50) := '11111';

BEGIN

BEGIN
IF p_status1 = 'Approved'
THEN
p_status := 'A';
ELSIF p_status1 = 'Review'
THEN
p_status := 'R';
ELSIF p_status1 = 'ALL'
THEN
p_status := NULL;
END IF;
END;

fnd_file.put_line (fnd_file.output, '(?xml version="1.0" encoding="UTF-8"?)');
fnd_file.put_line (fnd_file.output, '(Pending_Transac)'); -- Main Tag
fnd_file.put_line (fnd_file.output, '(PERIOD)' || p_period || '');
fnd_file.put_line (fnd_file.output, '(OPERATING_UNIT)' || p_operating_unit || '(/OPERATING_UNIT)');
fnd_file.put_line (fnd_file.output, '(STATUS)' || p_status1 || '(/STATUS)');

FOR rec_gl_detail IN gl_detail (p_status, p_period, p_operating_unit)
LOOP
v_transaction_num_curr := rec_gl_detail.transaction_number;
IF p_operating_unit IS NOT NULL
THEN
fnd_file.put_line (fnd_file.output, '(G_GL_DETAIL)'); -- Masters tag
fnd_file.put_line (fnd_file.output, '(STATUS)' || rec_gl_detail.status || '(/STATUS)');
fnd_file.put_line (fnd_file.output, '(TRANSACTION_NUMBER)' || rec_gl_detail.transaction_number
'(/TRANSACTION_NUMBER)
');
fnd_file.put_line (fnd_file.output, '(ENTERED_DATE)' || rec_gl_detail.entered_date ||
'(/ENTERED_DATE)
');
fnd_file.put_line (fnd_file.output, '(GL_DATE)' || rec_gl_detail.gl_date || '(/GL_DATE)');
fnd_file.put_line (fnd_file.output, '(PERIOD)' || rec_gl_detail.period || '(/PERIOD)');
fnd_file.put_line (fnd_file.output, '(NAME)' || rec_gl_detail.NAME || '(/NAME)');
fnd_file.put_line (fnd_file.output, '(SENDER)'  || rec_gl_detail.sender || '(/SENDER)');
fnd_file.put_line (fnd_file.output, '(SENDOR_GL_TRANSFER)' || rec_gl_detail.sendor_gl_transfer ||
'(/SENDOR_GL_TRANSFER)
');
fnd_file.put_line (fnd_file.output, '(RECEIVER)' || rec_gl_detail.receiver || '(/RECEIVER)');
fnd_file.put_line (fnd_file.output, '(RECEIVER_GL_TRANSFER)' || rec_gl_detail.receiver_gl_transfer ||
'(/RECEIVER_GL_TRANSFER)
');
fnd_file.put_line (fnd_file.output, '(AMOUNT)' || rec_gl_detail.amount || '(/AMOUNT)');
fnd_file.put_line (fnd_file.output, '(DESCRIPTION)' || rec_gl_detail.description || '(/DESCRIPTION)');
fnd_file.put_line (fnd_file.output, '(NOTE)' || rec_gl_detail.note || '(/NOTE)');
fnd_file.put_line (fnd_file.output, '(ATTRIBUTE10)' || rec_gl_detail.attribute10 || '(/ATTRIBUTE10)');
fnd_file.put_line (fnd_file.output, '(CONTEXT)' || rec_gl_detail.CONTEXT || '(/CONTEXT)');
fnd_file.put_line (fnd_file.output, '(/G_GL_DETAIL)
');

ELSIF p_operating_unit IS NULL
THEN

IF ( ( v_transaction_num_curr <> v_transaction_num_prev
AND rec_gl_detail.status = 'Approved')
OR rec_gl_detail.status = 'Review')
THEN
fnd_file.put_line (fnd_file.output, '(G_GL_DETAIL)'); -- Masters tag
fnd_file.put_line (fnd_file.output, '(STATUS)' || rec_gl_detail.status || '(/STATUS)');
fnd_file.put_line (fnd_file.output, '(TRANSACTION_NUMBER)' || rec_gl_detail.transaction_number ||
'(/TRANSACTION_NUMBER)');
fnd_file.put_line (fnd_file.output, '(ENTERED_DATE)' || rec_gl_detail.entered_date ||
'(/ENTERED_DATE)');
fnd_file.put_line (fnd_file.output, '(GL_DATE)' || rec_gl_detail.gl_date || '(/GL_DATE)');
fnd_file.put_line (fnd_file.output, '(PERIOD)' || rec_gl_detail.period || '(/PERIOD)');
fnd_file.put_line (fnd_file.output, '(NAME)' || rec_gl_detail.NAME || '(/NAME)');
fnd_file.put_line (fnd_file.output, '(SENDER)' || rec_gl_detail.sender || '(/SENDER)');
fnd_file.put_line (fnd_file.output, '(SENDOR_GL_TRANSFER)' || rec_gl_detail.sendor_gl_transfer ||
'(/SENDOR_GL_TRANSFER)');
fnd_file.put_line (fnd_file.output, '(RECEIVER)' || rec_gl_detail.receiver || '(/RECEIVER)');
fnd_file.put_line (fnd_file.output, '(RECEIVER_GL_TRANSFER)' || rec_gl_detail.receiver_gl_transfer ||
'(/RECEIVER_GL_TRANSFER)');
fnd_file.put_line (fnd_file.output, '(AMOUNT)' || rec_gl_detail.amount || '(/AMOUNT)');
fnd_file.put_line (fnd_file.output, '(DESCRIPTION)' || rec_gl_detail.description || '(/DESCRIPTION)');
fnd_file.put_line (fnd_file.output, '(NOTE)' || rec_gl_detail.note || '(/NOTE)');
fnd_file.put_line (fnd_file.output, '(ATTRIBUTE10)' || rec_gl_detail.attribute10 || '(/ATTRIBUTE10)');
fnd_file.put_line (fnd_file.output, '(CONTEXT)' || rec_gl_detail.CONTEXT || '(/CONTEXT)');
fnd_file.put_line (fnd_file.output, '(/G_GL_DETAIL)');
END IF;

v_transaction_num_prev := v_transaction_num_curr;

END IF;
END LOOP;

fnd_file.put_line (fnd_file.output, '(/Pending_Transac)
'); -- End Main Tag

EXCEPTION
WHEN OTHERS
THEN
fnd_file.put_line (fnd_file.LOG, 'Entered into Exception');
END gl_inter_company_trans;

Script to delete XML Templates

DECLARE
   p_template_code   xdo_templates_b.template_code%TYPE
                        := 'PRNT_XXX_YYY';
BEGIN
   DELETE FROM xdo_templates_b
         WHERE template_code = p_template_code;

   DELETE FROM xdo_templates_tl
         WHERE template_code = p_template_code;

   DELETE FROM xdo_lobs
         WHERE lob_code = p_template_code;

   COMMIT;
   DBMS_OUTPUT.put_line ('Total Rows Deleted ' || SQL%ROWCOUNT);
EXCEPTION
   WHEN OTHERS
   THEN
      DBMS_OUTPUT.put_line ('Error ' || SQLERRM);
END;

Sunday, 12 October 2014

Creating Custom Top and user

CUSTOM TOP CREATION 

cd $APPL_TOP
mkdir xxf/
mkdir xxf/1.0.0/
mkdir xxf/1.0.0/admin
mkdir xxf/1.0.0/bin
mkdir xxf/1.0.0/dll
mkdir xxf/1.0.0/forms
mkdir xxf/1.0.0/help
mkdir xxf/1.0.0/html
mkdir xxf/1.0.0/java
mkdir xxf/1.0.0/jlt
mkdir xxf/1.0.0/lib
mkdir xxf/1.0.0/log
mkdir xxf/1.0.0/mds
mkdir xxf/1.0.0/mesg
mkdir xxf/1.0.0/out
mkdir xxf/1.0.0/resource
mkdir xxf/1.0.0/scripts
mkdir xxf/1.0.0/servlets
mkdir xxf/1.0.0/share
mkdir xxf/1.0.0/sql
mkdir xxf/1.0.0/xml

CUSTOM TOP ENTRY

"export XXF_TOP=$APPL_TOP/xxf/1.0.0" added to custom environment file- D1FEMP00_phls6015.env 

CUSTOM USER CREATION

CREATE USER XXF IDENTIFIED BY xxf123
DEFAULT TABLESPACE apps_ts_tx_data
TEMPORARY TABLESPACE TEMP
PROFILE DEFAULT
ACCOUNT UNLOCK;
GRANT CONNECT TO XXF;
GRANT RESOURCE TO XXF;
ALTER USER XXF DEFAULT ROLE ALL;
GRANT UNLIMITED TABLESPACE TO XXF;

Script to create Missing Workflow Activities for SO Header

DECLARE
   l_header_id    NUMBER := 1860455;  --Input sales order header_id
   l_count        NUMBER := 0;
   l_user         NUMBER := 110816;
   l_resp         NUMBER := 64421;
   l_appl         NUMBER := 660;
   wf_process     VARCHAR2 (100);
   l_org_id       NUMBER := -99;
   l_item_type    VARCHAR2 (30);
   p_line_rec     OE_Order_PUB.Line_Rec_Type;
   l_aname        wf_engine.nametabtyp;
   l_aname2       wf_engine.nametabtyp;
   l_avalue       wf_engine.numtabtyp;
   l_avaluetext   wf_engine.texttabtyp;
   l_user_name    VARCHAR2 (100);

   CURSOR items
   IS
        SELECT h.org_id,
               h.order_number,
               h.header_id,
               h.flow_status_code,
               h.open_flag,
               h.booked_flag,
               h.creation_date,
               h.order_type_id,
               h.order_category_code,
               TO_CHAR (h.header_id) item_key
          FROM oe_order_headers_all h
         WHERE     h.open_flag = 'Y'
               AND NVL (h.cancelled_flag, 'N') = 'N'
               AND h.header_id = l_header_id
               AND NOT EXISTS
                          (SELECT 1
                             FROM wf_items itm
                            WHERE     itm.item_type = 'OEOH'
                                  AND itm.item_key = TO_CHAR (h.header_id))
      ORDER BY h.org_id, h.order_number;

   FUNCTION Get_ProcessName (
      p_itemtype           IN VARCHAR2,
      p_itemkey            IN VARCHAR2,
      p_wfasgn_item_type   IN VARCHAR2 := FND_API.G_MISS_CHAR)
      RETURN VARCHAR2
   IS
      l_process_name   VARCHAR2 (30) := NULL;

      CURSOR find_HdrProcessname (
         itemkey VARCHAR2)
      IS
         SELECT wf_assign.process_name
           FROM oe_workflow_assignments wf_assign, oe_order_headers header
          WHERE     header.header_id = TO_NUMBER (itemkey)
                AND header.order_type_id = wf_assign.order_type_id
                AND SYSDATE >= wf_assign.start_date_active
                AND SYSDATE <= NVL (wf_assign.end_date_active, SYSDATE)
                AND wf_assign.line_type_id IS NULL;


      CURSOR find_LineProcessname (
         itemkey VARCHAR2)
      IS
           SELECT wf_assign.process_name
             FROM oe_workflow_assignments wf_assign,
                  oe_order_headers header,
                  oe_order_lines line
            WHERE     line.line_id = TO_NUMBER (itemkey)
                  AND NVL (p_wfasgn_item_type, '-99') =
                         NVL (wf_assign.item_type_code,
                              NVL (p_wfasgn_item_type, '-99'))
                  AND header.header_id = line.header_id
                  AND header.order_type_id = wf_assign.order_type_id
                  AND line.line_type_id = wf_assign.line_type_id
                  AND wf_assign.line_type_id IS NOT NULL
                  AND SYSDATE >= wf_assign.start_date_active
                  AND SYSDATE <= NVL (wf_assign.end_date_active, SYSDATE)
         ORDER BY wf_assign.item_type_code;
   --
   --
   BEGIN
      IF (p_itemtype = OE_GLOBALS.G_WFI_HDR)
      THEN
         OPEN find_HdrProcessname (p_itemkey);

         FETCH find_HdrProcessname INTO l_process_name;

         CLOSE find_HdrProcessname;
      ELSE
         OPEN find_LineProcessname (p_itemkey);

         FETCH find_LineProcessname INTO l_process_name;

         CLOSE find_LineProcessname;
      END IF;


      RETURN l_process_name;
   EXCEPTION
      WHEN NO_DATA_FOUND
      THEN
         RAISE;
      WHEN OTHERS
      THEN
         RAISE;
   END Get_ProcessName;
BEGIN
   DBMS_OUTPUT.put_line (
      'Org id: order number: header id: status: booked flag: open flag: created: WF process');
   DBMS_OUTPUT.put_line ('----------------------------------');

   DELETE wf_items
    WHERE item_key = '1860455' AND item_type = 'OEOH'; --Input sales order header_id

   COMMIT;

   DELETE WF_ITEM_ATTRIBUTE_VALUES ATV
    WHERE ATV.ITEM_TYPE = 'OEOH' AND ATV.ITEM_KEY = '1860455'; --Input sales order header_id

   COMMIT;

   FOR c IN items
   LOOP
      BEGIN
         SAVEPOINT loop_start;

         IF l_org_id <> c.org_id
         THEN
            l_org_id := c.org_id;
            fnd_client_info.set_org_context (l_org_id);
         END IF;

         wf_process := NULL;
         wf_process := Get_ProcessName (OE_GLOBALS.G_WFI_HDR, c.item_key);
         DBMS_OUTPUT.put_line (
               TO_CHAR (c.org_id)
            || ': '
            || TO_CHAR (c.order_number)
            || ': '
            || c.item_key
            || ': '
            || c.flow_status_code
            || ': '
            || c.booked_flag
            || ': '
            || c.open_flag
            || ': '
            || TO_CHAR (c.creation_date)
            || ': '
            || wf_process);

         SELECT COUNT (*)
           INTO l_count
           FROM DUAL
          WHERE     EXISTS
                       (SELECT 1
                          FROM fnd_responsibility
                         WHERE     application_id = l_appl
                               AND responsibility_id = l_resp)
                AND EXISTS
                       (SELECT 1
                          FROM fnd_user
                         WHERE user_id = l_user);

         IF wf_process IS NULL OR wf_process LIKE 'UPG%'
         THEN
            DBMS_OUTPUT.put_line ('No eligible workflow assignment found.');
         ELSIF     l_user IS NOT NULL
               AND l_resp IS NOT NULL
               AND l_appl IS NOT NULL
               AND l_count > 0
               AND l_org_id = fnd_profile.value_specific ('ORG_ID',
                                                          l_user,
                                                          l_resp,
                                                          l_appl)
         THEN
            fnd_global.apps_initialize (l_user, l_resp, l_appl);

            WF_ENGINE.CreateProcess (OE_Globals.G_WFI_HDR,
                                     c.item_key,
                                     wf_process);

            -- Set various Header Attributes
            l_aname (1) := 'USER_ID';
            l_avalue (1) := l_user;
            l_aname (2) := 'APPLICATION_ID';
            l_avalue (2) := l_appl;
            l_aname (3) := 'RESPONSIBILITY_ID';
            l_avalue (3) := l_resp;
            l_aname (4) := 'ORG_ID';
            l_avalue (4) := l_org_id;
            l_aname (5) := 'ORDER_NUMBER';
            l_avalue (5) := c.order_number;

            wf_engine.SetItemAttrNumberArray (OE_GLOBALS.G_WFI_HDR,
                                              c.item_key,
                                              l_aname,
                                              l_avalue);

            /* new logic to get FROM_ROLE */
            BEGIN
               SELECT user_name
                 INTO l_user_name
                 FROM fnd_user
                WHERE user_id = l_user;
            EXCEPTION
               WHEN OTHERS
               THEN
                  l_user_name := NULL;            -- do not set FROM_ROLE then
            END;


            l_aname2 (1) := 'ORDER_CATEGORY';
            l_avaluetext (1) := c.order_category_code;
            l_aname2 (2) := 'NOTIFICATION_APPROVER';
            l_avaluetext (2) :=
               FND_PROFILE.VALUE_specific ('OE_NOTIFICATION_APPROVER',
                                           l_user,
                                           l_resp,
                                           l_appl);
            l_aname2 (3) := 'NOTIFICATION_FROM_ROLE';
            l_avaluetext (3) := l_user_name;

            wf_engine.SetItemAttrTextArray (OE_GLOBALS.G_WFI_HDR,
                                            c.item_key,
                                            l_aname2,
                                            l_avaluetext);

            IF c.booked_flag = 'Y' AND c.flow_status_code = 'BOOKED'
            THEN
               wf_engine.handleerror (OE_GLOBALS.G_WFI_HDR,
                                      c.item_key,
                                      'BOOK_ORDER',
                                      'SKIP',
                                      'COMPLETE');
            ELSIF c.flow_status_code = 'ENTERED'
            THEN
               wf_engine.startprocess (OE_GLOBALS.G_WFI_HDR, c.item_key);
            END IF;
         ELSE
            DBMS_OUTPUT.put_line (
               'User, responsibility and appl id do not match org.');
         END IF;
      EXCEPTION
         WHEN OTHERS
         THEN
            DBMS_OUTPUT.put_line (SQLERRM);
            ROLLBACK TO loop_start;
      END;
   END LOOP;
   COMMIT;
END;