Introduction:

   This post describes the steps required to lock the field.

Step:1: On-change of items, insert into lock table.

Dynamic Action : On-Change

Selector : JQuery Selector

[name=f05]

Execute Javascript Code,

/* Getting the Program Name Details*/

var c=($(this.triggeringElement ).attr(‘name’).substr(0,3));

var d=this.triggeringElement.id;

//alert(d);

var str = d.substring(4,8);

if(c==”f05″)

{

// Assigning XX Type

 

var p_XX_type=”Master”;

//alert(p_XX_type);

//getting column header value

idheader =”#f05_0001_LABEL” ;

var p_field_name = $(idheader).closest(“label”).html();

//alert(p_field_name);

//getting Master XX ID

var p_XX_id=$(‘#P77_MASTER_XX_ID’).val();

//alert(p_XX_id);

//getting Item ID

var p_item_id=$(this.triggeringElement ).attr(‘id’);

//alert(p_item_id);

//getting Item value

var p_item_val=$x(p_item_id).value;

//alert(p_item_val);

var p_item_val1    = $x(“f04_”+str).value;

var p_mas_item_id  = $x(“f03_”+str).value;

//alert(p_item_val1);

//p_item_val1  =$x(“f03_”+new1).value;

//alert(p_item_val1);

//p_item_val2  =j_item_id;

apex.server.process (

“AP_FIELD_LOCKS”

,   {   x01: p_XX_id

,   x02: p_XX_type

,   x03: p_field_name

,   x04: p_item_id

,   x05: p_item_val

,  x06:  p_item_val1

,  x07:  p_mas_item_id

}

, { dataType: ‘text’

,success: function(pData){

//alert(pData)

}

}

);

};

 

Application Process:

 

DECLARE

lv_n_user_id   NUMBER;

BEGIN

IF apex_application.g_x06 IS NOT NULL

THEN

lv_n_user_id := XX_pk_get_values.XX_fn_get_user_id (:app_user);

/*

            DELETE FROM XX_tb_mstr_user_restriction

                  WHERE session_id = :app_session;

                  */

INSERT INTO XX_tb_field_locks (lock_id,

app_id,

page_no,

session_id,

XX_id,

XX_type,

field_name,

item_id,

item_value,

XX_ITEM_ID,

item_identifier,

created_by,

created_date)

VALUES   (XX_sq_field_locks.NEXTVAL,

:app_id,

:app_page_id,

:app_session,

apex_application.g_x01,

apex_application.g_x02,

apex_application.g_x03,

apex_application.g_x04,

apex_application.g_x05,

apex_application.g_x07,

apex_application.g_x06,

lv_n_user_id,

SYSDATE);

END IF;

END;

Step:2:

 

On-page load check for locked items in field locks table and  locked field items been represented in different color using below javascript,

 

var example = $(“#P77_RESTRICT_FIELD_NAME”).val();

var session_id =$(“#P77_SESSION”).val();

var cur_session=$(“#P77_CURRENT_SESSION”).val();

var user_name =$(“#P77_USER_NAME”).val();

var session_spl =session_id.split(‘,’);

var numbers = example.split(‘,’);

var user_spl =user_name.split(‘,’);

var my_condition = true;

var session_check=””;

var user_check=””;

var master_item_row =””;

for (var i = 0; i < numbers.length; i++) {

if  (typeof session_spl[i]  !== ‘undefined’)

{

session_spl[i] = session_spl[i].replace(/^\s*/, “”).replace(/\s*$/, “”);

if (typeof user_spl[i] !== ‘undefined’)

{

user_spl[i] =  user_spl[i].replace(/^\s*/, “”).replace(/\s*$/, “”);

session_check=session_spl[i];

user_name = user_spl[i];

 

/*Checking for Session value that is not user’s current session*/

if (session_check !=cur_session)

{

var ind = numbers[i].indexOf(“:”);

var len = numbers[i].length;

var id = numbers[i].substring(0,ind);

if ( id.length !=0)

{

 

/*Getting Master Item ID*/

var id1 =id.trim();

var item_id = numbers[i].substring(ind+1,len);

var item_id1=item_id.trim();

//alert(item_id1);

 

/*Getting the Row Value Using the Master Item ID */

for (K=0;K<=10;K++)

{

b = “000” + K;

b = pad(K, 4);

var item_check = $(“#f03_”+b).val();

if (item_check == item_id1)

{

master_item_row = b;

numbers[i] = numbers[i].replace(/^\s*/, “”).replace(/\s*$/, “”);

var ind1 = numbers[i].indexOf(“:”);

 

/*Getting the Field Value from the field lock  table for the Master Item ID */

var id2 = numbers[i].substring(0,ind1);

 

/*Getting the Field Value first four Characters like  “f05_”*/

var ind_col_id =id2.substring(0,4);

 

/*Concatenate both field id and Master item id row*/

var id3 = ind_col_id+master_item_row;

 

/*Making a fields as read only*/

$(“#” + id3).prop(“readonly”, true);

$(“#” + id3).prop(“onclick”, false);

$(“#” + id3).css(“color”, “red”);

$(“#” + id3).on(‘mousedown focus’,function(e) {

if (my_condition) {

e.preventDefault();

 

/*Application Process for getting the User Name who Locked the fields*/

var get = new htmldb_Get(null, $x(‘pFlowId’).value,

‘APPLICATION_PROCESS=AP_USER_NAME’, 0);

get.add(‘AI_USER_ID’, user_name);

gReturn = get.get();

var ret = gReturn;

user_check=ret.trim();

$(“#alert”).html(“<font size=2>   This field has been locked by  ” +user_check+”</font>”);

$(“#alert”).dialog({

modal: true,

resizable: false,

minHeight: 105,

width: 420,

dialogClass: ‘testclass’

});}});

break;

}}}}}}}

 

Application Process:

 

DECLARE

lv_v_user_name   VARCHAR2 (50);

BEGIN

SELECT   INITCAP (first_name) || ‘ ‘ || INITCAP (last_name)

INTO   lv_v_user_name

FROM   XX_tb_user_defn

WHERE   user_id = :AI_USER_ID;

 

IF lv_v_user_name IS NOT NULL

THEN

HTP.p (lv_v_user_name);

END IF;

END;

 

Step:3: On-focus of locked items, alert been displayed with locked-user using following javascript,

 

var a = event.target.id;

if (a!==undefined)

{

var b=a.substring(0, 3);

//alert(‘b:’+b);

var c=a.replace(b,”f03″);

//alert(‘c:’+c);

var d=$(“#”+c).val();

//alert(‘d: ‘+d);

var e=$(“#”+a).val();

//alert(‘e:’+e);

var get = new htmldb_Get(null, $x(‘pFlowId’).value,

‘APPLICATION_PROCESS=AP_FOCUS_CHECK’, 0);

get.add(‘AI_MASTER_ITEM_ID’, d);

get.add(‘AI_FIELD_ID’, b);

gReturn = get.get();

var ret = gReturn.trim();

//alert (‘ret:’+ ret);

if (ret != ‘Not_Exists’)

{

//alert(‘Can be locked’);

$(“#”+a).prop(“readonly”, true);

$(“#”+a).prop(“onclick”, false);

$(“#”+a).css(“color”, “red”);

$(“#”+a).on(‘click’, function(e) {return false;});

$(“#” + a).on(‘mousedown focus’,function(e) {

e.preventDefault();

$(“#alert”).html(“<font size=2>   This field has been locked by  </font> “+ret);

$(“#alert”).dialog({

modal: true,

resizable: false,

minHeight: 105,

width: 420,

dialogClass: ‘testclass’

});

});

}

}

 

Application Process:

 

DECLARE

lv_n_lock_id      NUMBER;

lv_n_created_by   NUMBER;

lv_v_result       VARCHAR2 (100);

BEGIN

BEGIN

SELECT   lock_id, created_by

INTO   lv_n_lock_id, lv_n_created_by

FROM   XX_tb_field_locks

WHERE   UPPER (XX_type) = ‘MASTER’ AND XX_item_id = :ai_master_item_id

AND SUBSTR (item_id, 1, INSTR (item_id, ‘_’) – 1) =

:ai_field_id

AND session_id != :ai_app_session;

EXCEPTION

WHEN NO_DATA_FOUND

THEN

lv_n_lock_id := 0;

lv_n_created_by := 0;

WHEN TOO_MANY_ROWS

THEN

BEGIN

SELECT   DISTINCT created_by

INTO   lv_n_created_by

FROM   XX_tb_field_locks

WHERE   UPPER (XX_type) = ‘MASTER’

AND XX_item_id = :ai_master_item_id

AND SUBSTR (item_id, 1, INSTR (item_id, ‘_’) – 1) =

:ai_field_id

AND session_id != :ai_app_session;

EXCEPTION

WHEN OTHERS

THEN

lv_n_created_by := NULL;

END;

END;

 

IF lv_n_lock_id <> 0

THEN

/*SELECT XX_pk_get_values.XX_fn_get_user_name (lv_n_created_by)

        INTO lv_v_result

        FROM DUAL;*/

SELECT   INITCAP (first_name) || ‘ ‘ || INITCAP (last_name)

INTO   lv_v_result

FROM   XX_tb_user_defn

WHERE   user_id = lv_n_created_by;

 

HTP.p (lv_v_result);

ELSE

HTP.p (‘Not_Exists’);

END IF;

END;

 

Field Locks – Link level

 

On-hover of link, field locks table been checked and alert been displayed of locked user.

 

Call To Action:

For Oracle apex development and customization please do contact our company website https://doyensys.com/

 

Conclusion

        Using the above method you can lock the fields.

 

Recommended Posts

Start typing and press Enter to search