Allow to edit model category for HAM Admin in case of mismatch between model category and CI class

devanshsing
Tera Contributor

Given I am a user with 'ham_admin' role When I open an asset record that satisfied the below condition:  'CI Class' field of asset's 'Model Category' does not match to the class of the CI that is linked to the asset THEN I should be able to modify the 'Model Category' field of the asset.

 

 

This is the requirement I need help for this implementation like what approach will work here

2 REPLIES 2

pavani_paluri
Tera Guru

Hi @devanshsing 

 

You can restrict update using UI Policy and Business Rule
UI Policy :
This runs when the form is opened. It checks if the asset’s Model Category CI Class is different from the linked CI’s Class.
If they don’t match → make the Model Category field editable.
If they do match → keep it read‑only.
This gives the user the right experience on the screen.
Business Rule:
This runs when the record is being saved. It double‑checks the same condition.
If mismatch and user is ham_admin → allow the update.
Otherwise → block the update.
This ensures the rule is enforced even if someone tries to bypass the UI (like through APIs or imports).

 

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Pavani P

 

(function onCondition(){
 

  //1. if role of user is != ham_admin model_category is set to be read only.
    if(g.user.hasRole('ham_admin')){
        g_form.setReadOnly('model_category',true);
        return ;
    }

  //2. CI class should be present

  var ciSysID = g_form.getValue('ci');
  if (!ciSysID){

    g_form.setReadOnly('model_category',true);
    return;

  }

  //3. Model Category must be present.
  var modelCategory = g_form.getValue('model_category');
  if(!modelCategory){
    g_form.setReadOnly('model_category',true);
    return;
  }

  //4. get CI record

  g_form.getReference('ci',function(ciRecord){

    if(!ciRecord){
        g_form.setReadOnly('model_category',true);
    }

// CI actual class


    //5. get model category record

    g_form.getReference('model_category',function(){

        g_form.setReadOnly('model_category',true);
        return;

    }


    //
   
   
   
    );

   



  });



 


});
 
@pavani_paluri I have written the UI policy although it is not working can you help me on this