Aftorres02
6/4/2018 - 6:06 PM

ajax process

begin
  pkg_logi_reposicion_api.prc_logi_actualizar_reposicion(
                          p_id_repdet              => apex_application.g_x01
                        , p_fecha_programada       => to_date(apex_application.g_x02,:APP_DATE_TIME_FORMAT)
                        , p_id_organizacion_origen => apex_application.g_x03
                        , p_estado_reposicion      => apex_application.g_x04
                        , p_usuario_asignado       => apex_application.g_x05
  ); 
end;
 
  apex_json.open_object;
  apex_json.write('success',true); 
  apex_json.write('cntperuom',l_cntperuom); 
  apex_json.close_object;

exception
  when others then 
    apex_json.open_object;
    apex_json.write('success',false); 
    apex_json.write('error_msg',sqlerrm); 
    apex_json.close_object;
end; 



declare
  s number;
begin
  null;
htp.prn('{"result":"OK"}');

exception
  when OTHERS then
    htp.prn('{"result":"ERROR"}');
end;

function ajax_process_actualizar(id_repdet,fechaProgramada,idOrigenOrganizacion,estado,idUsuarioAsignado){
  
  //console.log(id_repdet + ' // '+ fechaProgramada + ' // '+ idOrigenOrganizacion + ' // '+ idUsuarioAsignado + ' // '+ estado );
 
 function toggle_inc_req(){
    apex.server.process (
        "TOGGLE_INC_REQ",
        {
         pageItems: "#P33025_VINC_REQ"
        },
        {
          success: function(pData)
           {
             if (pData.message !== null ) {
               showError(pData.message);
             }
             else{
                apex.item("P33025_VINC_REQ").disable();
             }
           }
        }
    );
}

**********

apex.server.process("ADD_ITEM_TO_COLLECTION",{ 
    x01: rcpt_subid,
    x02: fechaProgramada,
    pageItems: "#P40_SHPT_ID,#P40_PALLET_NO,#P40_BRAND"
  },
  {
    success: function(pData){
      if (pData.success){   
       apex.region('usages_selected').refresh(); 
        apex.event.trigger( "#reposiciones_header", "apexrefresh" );
      } else { 
        flash_indicator(false,'P40_SCAN_BARCODE'); 
        console.log(pData.error_msg);
      }

    }
  }
);
  
}


********



apex.server.process("CALC_POINTS_TOTAL",
        {  x01: qty
         , x02: product 
         , pageItems: "#P71_CUSTOMER_TYPE"
        }
      , {success: function(pData){
         
           if (pData.error_msg == null)  {   
             
             $(tr_element).find('input[name="f08"]').val(pData.l_total_points); // points
             $(tr_element).find('input[name="f09"]').val(pData.l_total_price); // total price
           }else {
              console.log(pData);
           }
              
           }
        }
      //, {dataType: "text"}
    );






$s("P125_ALERTIFY_MENSAJE",pData.mensaje); 


  $.event.trigger("mostrar_mensaje_error");
              apex.event.trigger( "#reposiciones_header", "apexrefresh" );
            } else { 
              $.event.trigger("mostrar_mensaje"); 
              
              
#reposiciones_header_ir tr:gt(1)

actualizarReposicionesCabecera(this.triggeringElement);



function actualizarReposicionesCabecera(elem){
  
  id_repdet            = $(elem).find("input[name='f01']").val();
  fechaProgramada      = $(elem).find("input[name='f02']").val();
  idOrigenOrganizacion =  $(elem).find("select[name='f03']").val();  
  idUsuarioAsignado    = $(elem).find("select[name='f04']").val();
  estado               = $(elem).find("select[name='f05']").val();
   
 ajax_process_actualizar(id_repdet,fechaProgramada,idOrigenOrganizacion,estado,idUsuarioAsignado);
  
}
APEX_JSON.open_object;
APEX_JSON.write('success', 'true');

APEX_JSON.open_array('items');

-- Agregar el primer elemento
APEX_JSON.open_object;
APEX_JSON.write('name', 'item1');
APEX_JSON.write('value', '12');
APEX_JSON.close_object;

-- Agregar el segundo elemento
APEX_JSON.open_object;
APEX_JSON.write('name', 'item2');
APEX_JSON.write('value', '13');
APEX_JSON.close_object;

-- Agregar el tercer elemento
APEX_JSON.open_object;
APEX_JSON.write('name', 'item3');
APEX_JSON.write('value', '14');
APEX_JSON.close_object;

-- Cerrar el array de "items"
APEX_JSON.close_array;

APEX_JSON.close_object;
https://www.linkedin.com/pulse/calling-plsql-from-javascript-rodrigo-mesquita/

Declare
   ln_error_code         Number;
   lv_error_msg          varchar2(4000);   

Begin
FOR i IN 1..apex_application.g_f01.COUNT
LOOP
PROCESS_ORDER (p_order_num => apex_application.g_f01(i),
               p_return_code => ln_error_code ,
               p_return_message => lv_error_msg);
END LOOP;

/* below, the function return a JSON formatted string with the two returned values */
apex_json.open_object;
  apex_json.open_array('output');
    apex_json.open_object;
      apex_json.write('lv_error_code', ln_error_code);
       apex_json.write('lv_error_msg', lv_error_msg);
  apex_json.close_object; 
   apex_json.close_array;
apex_json.close_object;

End;

----------

function processOrder(id) {
    /* to avoid the user to click on some other order while a order is being processed,
        we show the apex spinner, you need to set a ID on the report. in this case the ID is ORDER_REPORT */
    var lSpinner$ = apex.util.showSpinner( $( "#ORDER_REPORT" ) );
    /* ajax to call the database procedure */
    apex.server.process("PROCESS_ORDER", { // the ajax callback process name
        f01 : id, /* The order id passed from the report link */
        pageItems: "#P1_ORDER_ID" // The page item that we want to submit before calling the process.
    }, {
        success: function(pData) {
            /* now we can remove the spinner */
            lSpinner$.remove();
            
            /* The Ajax process will return lv_error_msg and lv_error_code, if lv_error_code = 0 
            show the successful message, if not show the error */ 
            var errorMsg = pData.output[0].lv_error_msg; 
            if (pData.output[0].lv_error_code == '0') {
                apex.message.clearErrors();
                apex.message.alert( 'Order processed successfully' );
            } else {
                apex.message.clearErrors();
                apex.message.showErrors([{
                    type: "error",
                    location: ["page"],
                    message: errorMsg,
                    unsafe: false
                }]);
            }
        }
    });
}