Disabling Form Fields Server Side

Hello, How do I navigate, from an item to its associated form and then manipulate the associated controls. I want to disable a drop down based upon a field condition in the same form. I'd like to do this as a server side event (onAfterLock) I am able to achieve something similar from a client side as a form onLoad event but the fields do not stay locked once you've toggled the lock status. Appreciate any feedback.
  • A small update. I stumbled across this blog relating to doing what I want to achieve. The suggested event to use was the onFormPopulated. Using the following code:
    var prj = getFieldByName("project");
    var test = getFieldByName("z_test");
    
    prj.getElementsByTagName("input")[0].disabled = true;
    prj.getElementsByTagName("button")[0].disabled = true;
    test.getElementsByTagName("input")[0].value = "Done";
    
    This event though, has no effect on the project drop down. It is enabled. If I change the event to onLoad and load the item in a locked status then the field is disabled. If I load the item unlocked and then lock it, the field is enabled. What am I missing?
  • Hello, The onLoad event is called only a single time when the user initially loads the Form. It will not be repeated if the user refreshes, locks, unlocks, or saves the item. This is why the recommendation was to use an onFormPopulated event. Could you let us know what version of Aras Innovator you are using? I believe I wrote that blog post against 11.0 SP12, and there may be some slight variation between versions. One thing you could try is to follow the solution I included for disabling the Item field and place the code you have to disable the field inside of a short timeout. This was to resolve a behavior I saw where the Item field was automatically re-enabled after the Form was fully loaded. Chris
    Christopher Gillis Aras Labs Software Engineer
  • Hello Chris, Thank you for your response. I am on Version 11 SP12. You might need to give me a nudge on how to achieve: "place the code you have to disable the field inside of a short timeout." using this code and assumes that the project drop down has a value:
    
    var prj = getFieldByName("project");
    var test = getFieldByName("z_test");
    
    prj.getElementsByTagName("input")[0].disabled = true;
    prj.getElementsByTagName("button")[0].disabled = true;
    test.getElementsByTagName("input")[0].value = prj.getElementsByTagName("input")[0].value;
    Observations onLoad 1. Loading item unlocked - All fields locked. z_test textbox blank. 2. Switching loaded item to Lock - All fields are enabled and z_test textbox is blank 3. Loading item locked - All fields are enabled and z_test textbox is blank 4. Toggling Lock status - All fields are enabled and z_test textbox is blank onFormPopulated 1. Loading item unlocked - All fields locked. z_test textbox blank. 2. Switching loaded item to Lock - All fields are enabled and z_test textbox is filled with project value 3. Loading item locked - Project field is locked. z_test textbox is blank. 4. Toggling Lock status - All fields are enabled and z_test textbox is is filled with project value
  • Hello, A timeout allows a function to be called after a certain number of milliseconds has passed. For your example, you can try something like:
    
    var prj = getFieldByName("project");
    var test = getFieldByName("z_test");
    
    setTimeout(function(){
    prj.getElementsByTagName("input")[0].disabled = true;
    prj.getElementsByTagName("button")[0].disabled = true;
    test.getElementsByTagName("input")[0].value = prj.getElementsByTagName("input")[0].value;
    }, 100); // <-- this well be called after 100 milliseconds
    If this doesn't resolve the issue you are seeing, you may need to increase the amount of time you are passing into the function. Chris
    Christopher Gillis Aras Labs Software Engineer
  • Excellent Chris, that works as I'd expect. Thanks for you help.