This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to create Form Action to enable/disable single-relational field

I have a Single-Relational "Existing Supplier" field in the primary table, which link to the Multi-Relational field "Available Suppliers" in Suppliers auxiliary table. "Value display format" of Suppliers table is "{FirstName}, <b>{LastName}</b> - <b>{Code}</b>". The submit form shows 2 fields "New Supplier?" Binary/Trinary filed (with 2 options: New Supplier, Existing Supplier). and "Existing Supplier" field. How can I control "Existing Supplier" field based on "New Supplier?" field?

For example:

   If "New Supplier?" is New Supplier

         disable "Existing Supplier" field dropdown list

   Else if "New Supplier?" is Existing Supplier

          disable the icon next the dropdown list of "Existing Supplier" field. which link to adding new record form

Thank you

  • Verified Answer

    +1  

    The form action is pretty simple. It would look something like below. Then, you would click each of the underline sections to select the fields and values you want to use. The trick will be the last part about disabling the icon next to the drop down. That is not a built-in feature of SBM. It is probably possible using javascript, but you would need to figure out the script. Maybe someone else on here will jump in with some code they have used in the past. 

    Anyone else have some sample code to remove/disable the submit button next to a relational field dropdown?

    Steps to make a form action:

  • 0 in reply to   

    Thank you Vickie for your detail explain. I have made sense about Form Actions.

    Does someone here use javascript to figure it out in the past?

    Thanks

  • 0  

        I am not sure I understand the description vs. example.  If you are simply trying to hide the "create new item" icon, then check this out: https://knowledgebase.serena.com/InfoCenter/index?page=content&id=S141731.  This will remove the icon all the time.

    To disable / enable fields in general, the form action is pretty powerful.  You can even run javascript.  You can add javascript and attach to the form as well.  Here is a basic javascript based on the example.

    function doSomething() {

    var check = GetFieldValue("NEW_SUPPLIER");

    If (check == "New Supplier") {

        DisableField("Existing Supplier");

    } else {

    //disable icon next to drop down.

    }

    AddChangeCallback("NEW_SUPPLIER", doSomething);

  • Verified Answer

    +1   in reply to 

    That is tricky. Using the If then that Vickie demonstrated and which you described at the beginning, on the If "New Supplier" you could try executing the following javascript:

    jQuerySBM(GetFieldByName("Existing Supplier")).next().show()

    jQuerySBM(GetFieldByName("Existing Supplier")).attr("disabled",true)

    the Else If for Existing Supplier would be to execute the following javascript:

    jQuerySBM(GetFieldByName("Existing Supplier")).next().hide();

    jQuerySBM(GetFieldByName("Existing Supplier")).attr("disabled",false);

    Though I think after using the image to add a new supplier the form will refresh and you will have to figure out a way to enable the field again. 

  • 0 in reply to   

    Thank you David

  • 0 in reply to   

    Hi Michael,

    I used the Form Action that Vickie demonstrated and followed the JavaScript you designed. and it works great without any issues. The result is definitely what I need.

    I am a newbie of the SBM. Can you advise the SBM JavaScript Document I need to learn from beginning?

    Again, Thank you all!

  • 0 in reply to   

    Thank you Vickie, I followed your Form Action you mentioned here, and the JavaScript Michael designed. It works. I apricate it.

  • 0   in reply to 

    The SBM Documentation talks about the javascript api.  You will find the GetFieldByName in this document.  

    SBM JavaScript Library - Solutions Business Manager (microfocus.com)