The CreatorCon Call for Content is officially open! Get started here.

Onload Clientscript

Manu143
Tera Contributor

Hi Community,

 

  How to write the onload client script  this should execute only for 'spares' view in alm_stockroom and alm_hardware table .In the onload, I have to check members part of sparing user. if yes , make all fields to read only else it should editable ?

 

 

Thanks,

Manu

5 REPLIES 5

Amit Gujarathi
Giga Sage
Giga Sage

HI @Manu143 ,
I trust you are doing great.
Please find the sample code for the same.

function onLoad() {
    // Check if the current view is 'spares'
    var viewName = g_form.getViewName();
    if (viewName !== 'spares') {
        return; // Exit if not 'spares' view
    }

    // Check if the current table is alm_stockroom or alm_hardware
    var tableName = g_form.getTableName();
    if (tableName !== 'alm_stockroom' && tableName !== 'alm_hardware') {
        return; // Exit if not the specified tables
    }

    // Check if the current user is a member of the sparing user group
    var currentUser = gs.getUser();
    var isSparingUser = currentUser.isMemberOf('your_sparing_user_group_sys_id');

    // Make fields read-only if the user is a sparing user, otherwise keep them editable
    if (isSparingUser) {
        g_form.setReadOnly(true);
    } else {
        g_form.setReadOnly(false);
    }
}

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi