/* $Id$ */
/*============================================================================*
 |                 Copyright (c) 2008 Applaud Solutions UK Ltd                |
 |                             All rights reserved                            |
 *===========================================================================*/

SET VERIFY OFF
SET FEEDBACK OFF
WHENEVER OSERROR  EXIT FAILURE ROLLBACK
WHENEVER SQLERROR EXIT FAILURE ROLLBACK

DECLARE

  --
  -- Local constants and variables
  --
  e_no_bg_id          EXCEPTION;
  e_bg_not_exists     EXCEPTION;
  e_ff_type_not_found EXCEPTION;
  l_BG_ID   CONSTANT  NUMBER        := to_number('&1');
  l_USER_ID CONSTANT  NUMBER        := to_number('&2');
  l_START   CONSTANT  DATE          := to_date('0001-01-01','YYYY-MM-DD');
  l_END     CONSTANT  DATE          := xxas_util_pkg.eot;
  l_FF_NAME CONSTANT  VARCHAR2(80)  := 'XXAS_PG_FORM_FIELD_ATTR_EDIT';
  l_FF_DESC CONSTANT  VARCHAR2(240) := 'Edit Formula for Form Field Edit Page';
  l_FF_TYPE CONSTANT  varchar2(30)  := 'Applaud Person';
  l_formula_text      LONG;
  l_formula_type_id   NUMBER;
  l_ff_id             NUMBER;
  l_bg_exists         VARCHAR2(1);

  --
  -- Tests if the Business Group already exists
  --
  CURSOR csr_bg_exists IS
  SELECT 'Y'
  FROM   per_business_groups_perf bg
  WHERE  bg.business_group_id = l_BG_ID;

  --
  -- Gets the FF Id
  --
  CURSOR csr_ff_id IS
  SELECT ff.formula_id
  FROM   ff_formulas_f ff
  WHERE  ff.business_group_id = l_BG_ID
  AND    ff.formula_name = l_FF_NAME;

  --
  -- Gets the Formula Type Id
  --
  CURSOR csr_ff_type IS
  SELECT fft.formula_type_id
  FROM   ff_formula_types fft
  WHERE  fft.formula_type_name = l_FF_TYPE;

BEGIN

  --
  -- Check that the Business Group Id was passed in
  --
  IF l_BG_ID IS NULL THEN
    RAISE e_no_bg_id;
  END IF;

  --
  -- Check the Business Group exists
  --
  OPEN  csr_bg_exists;
  FETCH csr_bg_exists INTO l_bg_exists;
  CLOSE csr_bg_exists;

  IF l_bg_exists IS NULL THEN
    RAISE e_bg_not_exists;
  END IF;

  --
  -- Fetch the Fast Formula Id
  --
  OPEN  csr_ff_id;
  FETCH csr_ff_id INTO l_ff_id;
  CLOSE csr_ff_id;

  --
  -- Get the Formula Type; error if it cannot be found
  --
  OPEN  csr_ff_type;
  FETCH csr_ff_type INTO l_formula_type_id;
  CLOSE csr_ff_type;

  IF l_formula_type_id IS NULL THEN
    RAISE e_ff_type_not_found;
  END IF;

  --
  -- Set the Formula Text
  --
  l_formula_text := q'[


/*==============================================================================

Formula Name: XXAS_PG_FORM_FIELD_ATTR_EDIT
Formula Type: Applaud Person
Description:  Edit Formula for Form Field Edit Page

==============================================================================*/
Default for Field_Id_Value_In is 'Unknown'
Default for Field_Type_Value_In is 'Unknown'
Default for List_Provider_Type_Value_In is 'Unknown'
Default for Value_Value_In is 'Unknown' 
Default for Description_Value_iIn is 'Unknown'
Default for Label_Value_In is 'Unknown'
Default for Visible_Value_In is 'Unknown'
Default for Enabled_Value_In is 'Unknown'
Default for Required_Value_In is 'Unknown'
Default for Hideif_Value_In is 'Unknown'
Default for Posttohref_Value_In is 'Unknown'
Default for Refreshonchange_Value_In is 'Unknown'
Default for Maxlength_Value_In is 'Unknown'
Default for Servicename_Value_In is 'Unknown'
Default for Googleplacetype_Value_In is 'Unknown'
Default for Placeholder_Value_In is 'Unknown'
Default for Richtext_Value_In is 'Unknown'
Default for Container_Exists_Value_In is 'Unknown'
Default for Xdb_Uri_Value_In is 'Unknown'
Default for Flexfield_Value_In is 'Unknown'
Default for Application_Id_Value_In is 'Unknown'
Default for Application_Short_Code_Value_In is 'Unknown'
Default for List_Provider_Value_In is 'Unknown'
Default for Lookup_Type_Value_In is 'Unknown'
Default for Value_Set_Value_In is 'Unknown'
Default for Rest_Api_Value_In is 'Unknown'
Default for Rest_Api_Value is 'XXDUMMY'
Default for Value_Set_Value is 'XXDUMMY'
Default for Lookup_Type_Value is 'XXDUMMY'

Inputs are Field_Id_Value_In,Field_Type_Value_In,Value_Value_In,Description_Value_In,Label_Value_In,Visible_Value_In,Enabled_Value_In,Required_Value_In,Hideif_Value_In,Posttohref_Value_In,Refreshonchange_Value_In,List_Provider_Type_Value_In,Container_Exists_Value_In,Xdb_Uri_Value_In,Flexfield_Value_In,Application_Id_Value_In,Application_Short_Code_Value_In,List_Provider_Value_In,Rest_Api_Value, Value_Set_Value, Lookup_Type_Value, Lookup_Type_Value_In,Value_Set_Value_In, Rest_Api_Value_In



  Field_Id_Visible = 'false'
  Value_Visible = 'false'
  Value_Generator_Visible = 'false'
  Label_Visible = 'false'
  Description_Visible = 'false'
  Style_Visible = 'false'
  Visible_Visible = 'false'
  Refresh_on_Change_Visible = 'false'
  Max_Length_Visible = 'false'
  Google_Place_Type_Visible = 'false'
  Service_Name_Visible = 'false'
  Place_Holder_Visible = 'false'
  Hideif_Visible = 'false'
  Weight_Visible = 'false'
  Color_Visible = 'false'
  Enabled_Visible = 'false'
  List_Function_Visible = 'false'
  Rich_Text_Visible = 'false'
  Post_To_Href_Visible = 'false'
  Post_New_To_Href_Visible = 'false'
  Button_Text_Visible = 'false'
  File_name_Visible = 'false'
  File_Href_Visible = 'false'
  Decimal_Precision_Visible = 'false'
  Date_Format_Visible = 'false'
  List_Provider_Type_Visible = 'false'
  List_Provider_Visible = 'false'
  Lookup_Type_Visible = 'false'
  Value_Set_Visible = 'false'
  Rest_Api_Visible = 'false'
  Positive_Boolean_Value_Visible = 'false'
  Long_list_Visible = 'false'
  No_Data_Message_Visible = 'false'
  Question_Ref_Id_Visible = 'false'
  Create_Allowed_Visible = 'false'
  Create_Label_Visible = 'false'
  Min_Rows_Visible = 'false'
  Max_Rows_Visible = 'false'
  Include_Empty_Row_Visible = 'false'
  Flexfield_Visible = 'false'
  Column_Name_Prefix_Visible = 'false'
  Max_attachments_Visible = 'false'
  Entity_Name_Visible = 'false'
  Category_Code_Visible = 'false'
  Attachment_Title_Visible = 'false'
  Attachment_Description_Visible = 'false'
  Multirow_Xdb_Uri_Visible = 'false'
  PK1FieldName_Visible = 'false'
  PK2FieldName_Visible = 'false'
  PK3FieldName_Visible = 'false'
  PK4FieldName_Visible = 'false'
  PK5FieldName_Visible = 'false'
  Application_id_Visible = 'false'
  Application_short_code_Visible = 'false'
  Flex_code_Visible = 'false'
  Flex_structure_code_Visible = 'false'
  Descriptive_flexfield_name_Visible = 'false'
  Descriptive_flex_context_Code_Visible = 'false'
  Field_Id_enabled = 'True'
  Container_Visible = 'false'
  Container_Enabled = 'false'
  Required_Visible = 'false'
  File_Info_Provider_Visible = 'false'
  File_Types_Visible = 'false'
  Lookup_Type_Refresh_On_Change = 'false'
  Lookup_Type_Enabled = 'false'
  Value_Set_Enabled = 'false'
  Value_Set_Refresh_On_Change = 'false'
  Icon_Visible = 'false'
  Icon_Color_Visible = 'false'
  Multi_Color_Visible = 'false'
  Min_Visible = 'false'
  Max_Visible = 'false'
  Min_Label_Visible = 'false'
  Max_Label_Visible = 'false'


    
If Field_Id_Value_In Was Not Defaulted Then
(
  Field_Id_Description = Replace(Field_Id_Value_In,'-','_')
  Field_Id_enabled = 'false'
)
If Container_Exists_Value_In = 'Y' And Field_Type_Value_In <> 'CONTAINER' And Field_Type_Value_In Was Not Defaulted Then
(
  Container_Visible = 'True'
  Container_Enabled = 'True'
  Container_Value = xxas_form_field_container(Xdb_Uri_Value_In,Field_Id_Value_In)
)
  
If Field_Type_Value_In = 'HIDDEN' Then
(
  Field_Id_Visible = 'True'
  Value_Visible = 'True'
  Value_Generator_Visible = 'True'
)
If Field_Type_Value_In = 'SUBMIT' Then
(
  Field_Id_Visible = 'True'
  Label_Visible = 'True'
  Visible_Visible = 'True'
  Hideif_Visible = 'True'
  Weight_Visible = 'True'
  Color_Visible = 'True'
)
If Field_Type_Value_In = 'HTML' Then
(
  Field_Id_Visible = 'True'
  Label_Visible = 'True'
  Value_Visible = 'True'
  Hideif_Visible = 'True'
  Visible_Visible = 'True'
)
If Field_Type_Value_In = 'ITEM' Then
(
  Field_Id_Visible = 'True'
  Label_Visible = 'True'
  Visible_Visible = 'True'
  Hideif_Visible = 'True'
)
If Field_Type_Value_In = 'LIST' Then
(
  Field_Id_Visible = 'True'
  Label_Visible = 'True'
  Visible_Visible = 'True'
  Description_Visible = 'True'
  Hideif_Visible = 'True'
  Style_Visible = 'false'
  List_Function_Visible = 'True'
  Value_Visible = 'True'
 )
If Field_Type_Value_In = 'LINK' Then
(
  Label_Visible = 'True'
  Visible_Visible = 'True'
  Hideif_Visible = 'True'
  Value_Visible = 'True'
)
If Field_Type_Value_In = 'TEXT' Then
(
  Field_Id_Visible = 'True'
  Label_Visible = 'True'
  Value_Visible = 'True'
  Visible_Visible = 'True'
  Description_Visible = 'True'
  Refresh_On_Change_Visible = 'True'
  Enabled_Visible = 'True'
  Required_Visible = 'True'
  Hideif_Visible = 'True'
  Max_Length_Visible = 'True'
  Place_Holder_Visible = 'True'
)
If Field_Type_Value_In = 'TEXTINPUT' Then
(
  Field_Id_Visible = 'True'
  Label_Visible = 'True'
  Value_Visible = 'True'
  Visible_Visible = 'True'
  Description_Visible = 'True'
  Refresh_On_Change_Visible = 'True'
  Enabled_Visible = 'True'
  Required_Visible = 'True'
  Hideif_Visible = 'True'
  Max_Length_Visible = 'True'
  Place_Holder_Visible = 'True'
)
If Field_Type_Value_In = 'TEXTAREA' Then
(
  Field_Id_Visible = 'True'
  Label_Visible = 'True'
  Value_Visible = 'True'
  Visible_Visible = 'True'
  Description_Visible = 'True'
  Refresh_On_Change_Visible = 'True'
  Enabled_Visible = 'True'
  Required_Visible = 'True'
  Hideif_Visible = 'True'
  Max_Length_Visible = 'True'
  Place_Holder_Visible = 'True'
  Rich_Text_Visible = 'True'
)
If Field_Type_Value_In = 'LOCATION' Then
(
  Post_To_Href_Visible = 'True'
  Field_Id_Visible = 'True'
  Label_Visible = 'True'
  Value_Visible = 'True'
  Visible_Visible = 'True'
  Description_Visible = 'True'
  Refresh_On_Change_Visible = 'True'
  Enabled_Visible = 'True'
  Required_Visible = 'True'
  Hideif_Visible = 'True'
  Max_Length_Visible = 'True'
  Service_Name_Visible = 'True'
  Google_Place_Type_Visible = 'True'
)
If Field_Type_Value_In = 'PASSWORD' Then
(
  Field_Id_Visible = 'True'
  Label_Visible = 'True'
  Value_Visible = 'True'
  Visible_Visible = 'True'
  Description_Visible = 'True'
  Refresh_On_Change_Visible = 'True'
  Enabled_Visible = 'True'
  Required_Visible = 'True'
  Hideif_Visible = 'True'
  Max_Length_Visible = 'True'
  Place_Holder_Visible = 'True'
)
If Field_Type_Value_In = 'EMAIL' Then
(
  Field_Id_Visible = 'True'
  Label_Visible = 'True'
  Value_Visible = 'True'
  Visible_Visible = 'True'
  Description_Visible = 'True'
  Refresh_On_Change_Visible = 'True'
  Enabled_Visible = 'True'
  Required_Visible = 'True'
  Hideif_Visible = 'True'
  Max_Length_Visible = 'True'
  Place_Holder_Visible = 'True'
)
If Field_Type_Value_In = 'ATTACHMENT' Then
( 
  Field_Id_Visible = 'True'
  Label_Visible = 'True'
  Description_Visible = 'True'
  Visible_Visible = 'True'
  Enabled_Visible = 'True'
  Required_Visible = 'True'
  Entity_Name_Visible = 'True'
  Category_Code_Visible = 'True'
  Attachment_Title_Visible = 'True'
  Attachment_Description_Visible = 'True'
  PK1FieldName_Visible = 'True'
  PK2FieldName_Visible = 'True'
  PK3FieldName_Visible = 'True'
  PK4FieldName_Visible = 'True'
  PK5FieldName_Visible = 'True'
)
If Field_Type_Value_In = 'UPLOAD' Then
(
  Post_To_New_Href_Visible = 'True'
  Field_Id_Visible = 'True'
  Label_Visible = 'True'
  Description_Visible = 'True'  
  Button_Text_Visible = 'True'
  Refresh_On_Change_Visible = 'True'
  Visible_Visible = 'True'
  Enabled_Visible = 'True'
  Required_Visible = 'True'
  Hideif_Visible = 'True'
  Value_Visible = 'True'
  File_Types_Visible = 'True'
  File_Name_Visible = 'false'
  File_Href_Visible = 'false'
  File_Info_Provider_Visible = 'True'
  Post_New_To_Href_Visible = 'True'
)
If Field_Type_Value_In = 'NUMBER' Then
(
  Field_Id_Visible = 'True'
  Label_Visible = 'True'
  Value_Visible = 'True'
  Visible_Visible = 'True'
  Description_Visible = 'True'
  Refresh_On_Change_Visible = 'True'
  Enabled_Visible = 'True'
  Required_Visible = 'True'
  Hideif_Visible = 'True'
  Decimal_Precision_Visible = 'True'
  Place_Holder_Visible = 'True'
)
If Field_Type_Value_In = 'DATE' Then
(
  Field_Id_Visible = 'True'
  Label_Visible = 'True'
  Value_Visible = 'True'
  Visible_Visible = 'True'
  Description_Visible = 'True'
  Refresh_On_Change_Visible = 'True'
  Enabled_Visible = 'True'
  Required_Visible = 'True'
  Hideif_Visible = 'True'
  Date_Format_Visible = 'false'
  Place_Holder_Visible = 'True'
)
If Field_Type_Value_In = 'DATETIME-LOCAL' Then
(
  Field_Id_Visible = 'True'
  Label_Visible = 'True'
  Value_Visible = 'True'
  Visible_Visible = 'True'
  Description_Visible = 'True'
  Refresh_On_Change_Visible = 'True'
  Enabled_Visible = 'True'
  Required_Visible = 'True'
  Hideif_Visible = 'True'
  Date_Format_Visible = 'false'
  Place_Holder_Visible = 'True'
)
If Field_Type_Value_In = 'TIME' Then
(
  Field_Id_Visible = 'True'
  Label_Visible = 'True'
  Value_Visible = 'True'
  Visible_Visible = 'True'
  Description_Visible = 'True'
  Refresh_On_Change_Visible = 'True'
  Enabled_Visible = 'True'
  Required_Visible = 'True'
  Hideif_Visible = 'True'
  Date_Format_Visible = 'false'
  Place_Holder_Visible = 'True'
)
If Field_Type_Value_In = 'CHECKBOX' Then
(
  Field_Id_Visible = 'True'
  Label_Visible = 'True'
  Value_Visible = 'True'
  Visible_Visible = 'True'
  Description_Visible = 'True'
  Refresh_On_Change_Visible = 'True'
  Enabled_Visible = 'True'
  Required_Visible = 'True'
  Hideif_Visible = 'True'
  List_Provider_Type_Visible = 'True'

  If List_Provider_Type_Value_In = 'LOOKUP_TYPE'   Then
    (Lookup_Type_Visible = 'True'
    Lookup_Type_Refresh_On_Change = 'true'
    If Lookup_Type_Value_In was not defaulted Then
      (Lookup_Type_Value = Lookup_Type_Value_In
       )
     )
  If List_Provider_Type_Value_In = 'VALUE_SET_NAME' Then
    (Value_Set_Visible = 'True'
     Value_Set_Required = 'true'
     Value_Set_Enabled = 'True'
    Value_Set_Refresh_On_Change = 'true'
    If Value_Set_Value_In was not defaulted Then
      (Value_Set_Value = Value_Set_Value_In
       )
     )
  If List_Provider_Type_Value_In = 'REST' Then
    (Rest_Api_Visible = 'True'
     If Rest_Api_Value = 'XXDUMMY' Then
      Rest_Api_Value = 'XXASNULLVAL'
     Rest_Api_Refresh_On_Change = 'true'
     if Rest_Api_Value_In was not defaulted Then
      (Rest_Api_Value = Rest_Api_Value_In
       )
    )
  Positive_Boolean_Value_Visible = 'True'
)
If Field_Type_Value_In = 'RADIO' OR Field_Type_Value_In = 'SELECT-SINGLE' Then
(
  Field_Id_Visible = 'True'
  Label_Visible = 'True'
  Value_Visible = 'True'
  Visible_Visible = 'True'
  Description_Visible = 'True'
  Refresh_On_Change_Visible = 'True'
  Enabled_Visible = 'True'
  Required_Visible = 'True'
  Hideif_Visible = 'True'
  List_Provider_Type_Visible = 'True'
  List_Provider_Type_Required = 'true'
  If List_Provider_Type_Value_In = 'LOOKUP_TYPE' Then
    (Lookup_Type_Visible = 'True'
    Lookup_Type_Required = 'true'
    Lookup_Type_Enabled = 'True'
	IF Lookup_Type_Value_In was not defaulted then
    (
       Lookup_Type_Value = Lookup_Type_Value_In
     )
	 )
  If List_Provider_Type_Value_In = 'VALUE_SET_NAME' Then
    (Value_Set_Visible = 'True'
     Value_Set_Required = 'true'
     Value_Set_Enabled = 'True'
	 IF Value_Set_Value_In was not defaulted then
    (
       Value_Set_Value = Value_Set_Value_In
     )
	 )
  If List_Provider_Type_Value_In = 'REST' Then
    (Rest_Api_Visible = 'True'
    Rest_Api_Required = 'true'
	IF Rest_Api_Value_In was not defaulted then
    (
       Rest_Api_Value = Rest_Api_Value_In
     )
	 ) 
  Long_List_Visible = 'True'
  No_Data_Message_Visible = 'True'
  Place_Holder_Visible = 'True'
) 
If Field_Type_Value_In = 'SELECT-MULTIPLE' OR Field_Type_Value_In = 'POPLIST' OR  Field_Type_Value_In = 'COMBOLIST'   Then
(
  Field_Id_Visible = 'True'
  Label_Visible = 'True'
  Value_Visible = 'True'
  Visible_Visible = 'True'
  Description_Visible = 'True'
  Refresh_On_Change_Visible = 'True'
  Enabled_Visible = 'True'
  Required_Visible = 'True'
  Hideif_Visible = 'True'
  List_Provider_Type_Visible = 'True'
  List_Provider_Type_Required = 'true'
  If List_Provider_Value_In was not Defaulted Then
  (
    List_Provider_Visible = 'True'
    List_Provider_Enabled = 'false'
  )
 /* If List_Provider_Value_In was not Defaulted Then
  (
    If INSTR(List_Provider_Value_In,'REST') = 1 Then
    (
      List_Provider_Type_Value = 'REST'
      Rest_Api_Value = SUBSTR(List_Provider_Value_In,5)
      Rest_Api_Visible = 'True'
    )
    If INSTR(List_Provider_Value_In,'VALUE_SET_NAME') = 1 Then
    (
      List_Provider_Type_Value = 'VALUE_SET_NAME'
      Value_Set_Value = SUBSTR(List_Provider_Value_In,15)
      Value_Set_Visible = 'True'
    )
    If INSTR(List_Provider_Value_In,'LOOKUP_TYPE') = 1 Then
    (
      List_Provider_Type_Value = 'LOOKUP_TYPE'
      Lookup_Type_Value = SUBSTR(List_Provider_Value_In,12)
      Lookup_Type_Visible = 'True'
    )
    
  )*/  
  If List_Provider_Type_Value_In = 'LOOKUP_TYPE' Then
    (Lookup_Type_Visible = 'True'
     Lookup_Type_Required = 'true'
     Lookup_Type_Enabled = 'True'
	 IF Lookup_Type_Value_In was not defaulted then
    (
       Lookup_Type_Value = Lookup_Type_Value_In
     )
	 )
  If List_Provider_Type_Value_In = 'VALUE_SET_NAME' Then
    (Value_Set_Visible = 'True'
     Value_Set_Required = 'true'
     Value_Set_Enabled = 'True'
	 IF Value_Set_Value_In was not defaulted then
    (
       Value_Set_Value = Value_Set_Value_In
     )
	 )
  If List_Provider_Type_Value_In = 'REST' Then
    (Rest_Api_Visible = 'True'
     Rest_Api_Required = 'true'
	 IF Rest_Api_Value_In was not defaulted then
    (
       Rest_Api_Value = Rest_Api_Value_In
     )
	 ) 
  Long_List_Visible = 'True'
  No_Data_Message_Visible = 'True'
  Place_Holder_Visible = 'True'
  Style_Visible = 'True'
 /* Positive_Boolean_Value_Visible = 'True' */
)
If Field_Type_Value_In = 'CONTAINER' Then
(
  Field_Id_Visible = 'True'
  Label_Visible = 'True'
  Visible_Visible = 'True'
  Description_Visible = 'True'
  Hideif_Visible = 'True'
)

If Field_Type_Value_In = 'MULTIROW' Then
(
  Field_Id_Visible = 'True'
  Label_Visible = 'True'
  Visible_Visible = 'True'
  Description_Visible = 'True'
  Hideif_Visible = 'True'
  Create_Allowed_Visible = 'True'
  Create_Label_Visible = 'True'
  Min_Rows_Visible = 'True'
  Max_Rows_Visible = 'True'
  Include_Empty_Row_Visible = 'True'
  Multirow_Xdb_Uri_Visible = 'True'
)
Flexfield_Type = ' '
Application_Short_Code_Value = 'Unknowntest'
If Field_Type_Value_In = 'FLEXFIELD' Then
(
  Field_Id_Visible = 'True'
  Application_id_Visible = 'True'
  /*Flexfield_Visible = 'True'*/
  If Application_Id_Value_In Was Not Defaulted Then
  (
     Flexfield_Visible = 'True'
  )
  Flexfield_Type = xxas_get_flexfield_type(Flexfield_Value_In)

  If Flexfield_Type = 'KFF' Then
  (
    Flex_code_Visible = 'True'
    Flex_structure_code_Visible = 'True'

  )
  If Flexfield_Type = 'DFF' Then
  (
    Descriptive_flex_context_Code_Visible = 'True'
    Column_Name_Prefix_Visible = 'True'

  )
  
)
If Field_Type_Value_In = 'OLMQUESTION' Then
(
  OLMQUESTION_label = 'Oracle Learning Management question'
  Field_Id_Visible = 'True'
  Question_Ref_Id_Visible = 'True'
  Value_Visible = 'True'
)

If Field_Type_Value_In = 'RATING' Then
(
  Field_Id_Visible = 'True'
  Label_Visible = 'True'
  Visible_Visible = 'True'
  Enabled_Visible = 'True'
  Required_Visible = 'True'
  Value_Visible = 'True'
  Icon_Visible = 'True'
  Icon_Color_Visible = 'True'
  Multi_Color_Visible = 'True'
  Min_Visible = 'True'
  Max_Visible = 'True'
  Min_Label_Visible = 'True'
  Max_Label_Visible = 'True'
  List_Provider_Type_Visible = 'True'
  List_Provider_Type_Required = 'true'
  If List_Provider_Value_In was not Defaulted Then
  (
    List_Provider_Visible = 'True'
    List_Provider_Enabled = 'false'
  )
  If List_Provider_Type_Value_In = 'LOOKUP_TYPE' Then
    (Lookup_Type_Visible = 'True'
     Lookup_Type_Required = 'true'
     Lookup_Type_Enabled = 'True')
  If List_Provider_Type_Value_In = 'VALUE_SET_NAME' Then
    (Value_Set_Visible = 'True'
     Value_Set_Required = 'true'
     Value_Set_Enabled = 'True')
  If List_Provider_Type_Value_In = 'REST' Then
    (Rest_Api_Visible = 'True'
     Rest_Api_Required = 'true')
)

Return Field_Id_Description,Field_Id_enabled,Field_Id_Visible,  Value_Visible,  Value_Generator_Visible,  Label_Visible,  Description_Visible,  Style_Visible,  Visible_Visible,  Refresh_on_Change_Visible, Max_Length_Visible,  Google_Place_Type_Visible,  Service_Name_Visible,  Place_Holder_Visible,  Hideif_Visible,  Weight_Visible,  Color_Visible,  Enabled_Visible, List_Function_Visible,  Rich_Text_Visible,  Post_To_Href_Visible,  Post_New_To_Href_Visible,  Button_Text_Visible,  File_name_Visible,  File_Href_Visible, Decimal_Precision_Visible,  Date_Format_Visible,  List_Provider_Type_Visible,  Lookup_Type_Visible,  Value_Set_Visible,  Rest_Api_Visible, Positive_Boolean_Value_Visible,  Long_list_Visible,  No_Data_Message_Visible,  Question_Ref_Id_Visible,  Create_Allowed_Visible,  Create_Label_Visible,  Min_Rows_Visible,  Max_Rows_Visible,  Include_Empty_Row_Visible,    Column_Name_Prefix_Visible,  Max_attachments_Visible,  Entity_Name_Visible, Category_Code_Visible,  Attachment_Title_Visible,  Attachment_Description_Visible,  PK1FieldName_Visible,  PK2FieldName_Visible,  PK3FieldName_Visible, PK4FieldName_Visible,  PK5FieldName_Visible,Application_id_Visible,  Application_short_code_Visible,  Flex_code_Visible,  Flex_structure_code_Visible,  Descriptive_flexfield_name_Visible,  Descriptive_flex_context_Code_Visible,Multirow_Xdb_Uri_Visible,Container_Visible,Container_Enabled,Container_Value,Required_Visible,Flexfield_Visible,File_Info_Provider_Visible,File_Types_Visible,List_Provider_Visible,List_Provider_Enabled,List_Provider_Type_Required,Lookup_Type_Required, Value_Set_Required, Rest_Api_Required, Rest_Api_Value, Value_Set_Value,  Lookup_Type_Refresh_On_Change, Value_Set_Refresh_On_Change
,Icon_Visible,Multi_Color_Visible,Min_Visible,Max_Visible,Min_Label_Visible,Max_Label_Visible,Icon_Color_Visible,Value_Set_Enabled,Lookup_Type_Value  

]';


  BEGIN

    IF l_ff_id IS NULL THEN
      --
      -- Create the Fast Formula
      --
      INSERT INTO ff_formulas_f
        (formula_id
        ,effective_start_date
        ,effective_end_date
        ,business_group_id
        ,formula_type_id
        ,formula_name
        ,description
        ,formula_text)
      VALUES
        (ff_formulas_s.nextval
        ,l_START
        ,l_END
        ,l_BG_ID
        ,l_formula_type_id
        ,l_FF_NAME
        ,l_FF_DESC
        ,l_formula_text);

    ELSE
      --
      -- Update the existing Fast Formula text
      -- (if it has multiple date-track versions the text of
      -- all versions is updated).
      --
      UPDATE ff_formulas_f
      SET    formula_text = l_formula_text
            ,description  = l_FF_DESC
      WHERE  formula_id = l_ff_id;

    END IF;

    COMMIT;

    EXCEPTION
      WHEN others THEN
        ROLLBACK;
        RAISE;
    END;

    --
    -- Compile the Fast Formula
    --
    xxas_util_pkg.compile_ff
      (p_user_id => l_USER_ID
      ,p_ff_type => l_FF_TYPE
      ,p_ff_name => l_FF_NAME);

EXCEPTION

  WHEN e_no_bg_id THEN
    RAISE no_data_found;

  WHEN e_bg_not_exists THEN
    RAISE no_data_found;

  WHEN e_ff_type_not_found THEN
    RAISE no_data_found;

END;
/
COMMIT;
EXIT;
