How to disable Item Property Edit

Hello, my question is, there's a property in an ItemType that can be input or edited by certain identity (for example, property "Tester" can only be assigned by a Test manager, but can not be filled by other roles, only viewable to others) Permission settings is feasible only for ItemType as whole, how should I do configuration for certain item properties? Thank you for the reply. Regards
  • Hi Chenze, There are a few different ways to approach this.
    1. You could convert this from an Item Property into a Relationship and then configure the permissions of the relationship to allow adding only by a Test manager
      • Cons: This does require changing the existing data model and moving data to this new relationship
      • Pros: This could make sense if an item can have multiple Testers
    2. Attach on onFormPopulated event to the Form to check if the user is a Test Manager and disable the property if they are not
      • You can use aras.getIdentityList(); to get a comma separated list of IDs of the Identities the user belongs to
      • Pros: No changes to the data model
      • Cons: Only prevents users from editing the property on that specific form. Users can still edit the property through other means like AML
    Chris
    Christopher Gillis Aras Labs Software Engineer
  • Hi Chris, many thanks for your reply. According to your suggestion. The first one is not suitable. In the second one, if I understand it right, the returned IDs are group identities (e.g. "Test Manager, Developers") that the currently logged in users belongs to? Again, is there a function to set property "not editable"? Thank you.
  • Hi chenze, Yes, the IDs returned are group Identities that the current user is a member of.  Once verifying that the user is not a Test Manager you can disable the field with a line like getFieldByName("YOUR_FIELD_NAME").getElementsByTagName("input")[0].setAttribute("disabled", "");. Chris
    Christopher Gillis Aras Labs Software Engineer
  • Hi Christopher, I following the above example and running this method attached to on From populate but I keep getting an error. I want to disable edit for everyone else except "PLM Aministrator" ****** aras.getIdentityList(); if (Identity != "PLM Administrator") { getFieldByName("dept_discipline").getElementsByTagName("input")[0].setAttribute("disabled", "1"); } else { ("disabled", "0"); } ****** The error I get is "even handler failed with message identity is not defined (function onformpopulated userhandler) What am I missing?
  • Hello, There's a few issues with the code in that example. The specific error message that's being thrown is saying that the Identity variable you're checking in the if statement was never defined. The sample below should offer the functionality you're expecting.
    var identityList = aras.getIdentityList();
    if (!identityList.includes("REPLACE THIS WITH THE ID OF PLM ADMINISTRATOR"))
    {
    getFieldByName("name").getElementsByTagName("input")[0].setAttribute("disabled", ""); // <-- The disabled attribute does not need a value to take effect.
    }
    else
    {
    // We don't want to do anything in this case. If we enable the field, it will be enabled even the item is locked.
    }
    You will need to update the line in the If statement to include the ID of the PLM Administrator Identity in your environment. You can find this ID by right-clicking on the item and selecting Properties. You can then click the Copy ID button to get the ID. Chris
    Christopher Gillis Aras Labs Software Engineer
  • Hi Chris, thank you for your help. I used your logic above but it was complaining about something else. I got this one to work the way I would like it to. However, it still allows input although it does not save the result. How can I completely restrict edit/input? var contextItem = document.thisItem; var reqs = contextItem.newItem("part", "get"); var identity = aras.getIdentityList(); var vField1 = getFieldByName("part_desc"); if (identity != "DBA5D86402BF43D5976854B8B48FCDD1"); vField1.disabled = true; vField1.readOnly = true; return;
  • Hello, The element returned by getFieldByName is not the input element for that field. You will need to disable the input by using code like vField1.getElementsByTagName("input")[0].setAttribute("disabled", "");. Chris
    Christopher Gillis Aras Labs Software Engineer
  • ok, when I add that, I end up with this error " Unable to get property 'setAttribute' of undefined or null reference"
  • What kind of field is this? Is this a dropdown or a textarea or something else? Chris
    Christopher Gillis Aras Labs Software Engineer
  • Yes, this is a test Area. I am testing the method with one, eventually will have other fields, text and drop downs.