Friday, April 27, 2012

Script to register custom table

-->
DECLARE
  x_appl_short_name VARCHAR2(30) :=  'you application short name eg SQLAP for payables';
  x_appl_table_name VARCHAR2(30) := 'you custom table name';
BEGIN
  ad_dd.register_table(x_appl_short_name, x_appl_table_name, 'T');
  FOR cur_sh IN ( SELECT * FROM dba_tab_columns t
                  WHERE t.OWNER = x_appl_short_name
                        AND t.TABLE_NAME = x_appl_table_name
                ) LOOP
      AD_DD.delete_column(x_appl_short_name, x_appl_table_name, cur_sh.column_name);
      AD_DD.REGISTER_COLUMN ( x_appl_short_name,
                              x_appl_table_name,
                              cur_sh.column_name,
                              cur_sh.column_id,
                              cur_sh.data_type,
                              cur_sh.data_length,
                              cur_sh.nullable,
                              'N' );
  END LOOP;
END;



Then go to Application Developer responsibility, menu->Application->Database->Table, see you custom table registered.

Wednesday, January 18, 2012

Hide diagnostics menu


-->
In this menu it is very handy to do lot of things like look at hidden field values like invoice_id's etc, yet it possible to change values wich is not allowed by standard form behavior, so it makes you instance potentialy vulnerable when used by curious users.
By defaul it looks like this
 Then disable it by changing profile
An finally diagnostics menu disabled

Monday, December 26, 2011

Daily uploading currency xchange rates from central bank site


-->
Daily maintaining of currency rates can be boring task and things can go worse if you operate in multi time zones.
I provided simple example script populating GL interface table with daily rates for all enabled currencies, from Russian central bank.
It can be esily tailored to you needs by chanching part responsible for parsing XML stuff provided by central bank of you country.  If you in Europe for instanse, go here http://www.ecb.int/stats/exchange/eurofxref/html/index.en.html.
I used this script on the number of my projects as basis to  сustom concurent programs which scheduled to run on daily basis whithout any human involvment.

declare
l_date date;
l_rate number;
x_rate number;
l_currency varchar2(20);
  BEGIN   
 -- cycle all enabled currencies except funcional, SATAT and other special currencies not neded xchange rates mantained
 for i in (select currency_code from FND_CURRENCIES_VL where enabled_flag='Y' and currency_code not in ('STAT', 'RUB', 'XDR', 'UEG', 'UEE', 'UED')) loop
    l_currency   := i.currency_code;
    -- load xchange rate from central bank site
    SELECT to_number(VALUE(p).EXTRACT('Valute/Value/text()').getStringVal(), '99999999990d9999', 'NLS_NUMERIC_CHARACTERS = '',.''') / VALUE(p) .EXTRACT('Valute/Nominal/text()').getNumberVal()
      INTO l_rate
      FROM TABLE(XMLSEQUENCE(HTTPURITYPE('http://212.40.192.49/scripts/xml_daily.asp?date_req='
        || TO_CHAR(l_date, 'dd.mm.yyyy')) .getxml().EXTRACT('/ValCurs/Valute'))) p
      WHERE VALUE(p).EXTRACT('Valute/CharCode/text()') .getStringVal() = l_currency;
     begin
      -- upload only rates not already been uploaded
      select conversion_rate into x_rate from gl_daily_rates_interface
      where from_currency=l_currency
      and  to_currency='RUB' -- functional currency here
      and from_conversion_date=l_date
      and user_conversion_type='ЦБРФ'; -- conversion type of you choice
      exception
      WHEN no_data_found THEN
      INSERT
      INTO gl_daily_rates_interface
        (
          from_currency,
          to_currency,
          from_conversion_date,
          to_conversion_date,
          user_conversion_type,
          conversion_rate,
          mode_flag
        )
        VALUES
        (
          l_currency,
          'RUB', -- functional currency here
          l_date,
          l_date,
          'ЦБРФ',  -- conversion type of you choice
          l_rate,
          'I'
        );
     end;
   end loop;
  END;