Evaluate UI Policies in a script

gflewis
Kilo Expert

Is it possible to write a script that evaluates UI policies for the current record, returning true if all mandatory fields are completed and false if mandatory fields are blank?

I need to make the "State" field on my "Change Request" form read-only, and require users to click a button (UI Action) to advance the ticket to the next state. However, I only want the button to be visible if all UI policies are satisfied. We have made a lot of extensions to our Change Request form, and there are a lot of UI policies. I am now faced with the prospect of duplicating all this logic in the "Condition" field of my UI Action. Is there an easier way?

5 REPLIES 5

In the end, I did not need to evaluate the UI policies. Once I moved my UI actions from server to client, the gsftSubmit() function took care of them for me automatically.

This is what I did.

  1. I used an ACL to make the State field read-only.
  2. I created the following onLoad Client Script on the Task table. I checked the Inherited box so that I could use the script for any table based on Task.


    function onLoad() {}

    function advanceStateTo(newvalue) {
    g_form.setValue('state', newvalue);
    gsftSubmit(gel('sysverb_update_and_stay'));
    }

  3. For each legitimate state transition, I created a UI Action, checking the Client box.
    In the Condition field I specified the old state, for example


    current.state==2

    In the OnClick field I called my advanceStateTo function, for example


    advanceStateTo(3)

  4. I used Business Rules for the auxiliary processing. For example, there is a business rule for Condition


    current.state.changesTo(2)

    which runs the following script


    current.work_start = gs.nowDateTime();



Originally I was trying to avoid this division of processing between client and server. However, in the end it turned out to be a very clean solution.

I was pleased to learn that the gsftSubmit() function automatically enforced the UI policies and popped up a nice error message, so that I did not need to worry about them.

One thing that surprised me was that the client script allowed a read-only field to be updated.