Read-only fields by UI Policy or Client script become editable after UI Action runs - why?

scottatah
Giga Expert

Hi Everyone,

 

I'm in the process of testing things for our upgrade to Eureka and I've discovered an bug in presumably our customization (exists in our current production instance (calgary) as well).   On our Change form, we've got a "Tested by" field.   We've made it read-only and added ref_contributions=add_me so that a user can only input their own name for sign off. It does it's job correctly until you click the "Request Approval" UI Action.   The Request Approval validates that all required fields are filled in and then requests the approval.   If not all fields are filled in, you're propted and required to complete all fields before moving forward.   As part of that the "tested by" field becomes editable allowing you to put in any user you want.


For whatever reason, the read-only portion was implemented with a simple onload client script, so I tried doing it as a UI policy, but there was no difference.   I'm assuming the issue is then in my UI action, but I'm not sure.  


Thoughts?

 

UI Action:

Condition: current.approval=='not requested' && gs.hasRole("itil")

Script:

function requestApproval(){

     

      g_form.setValue('approval', 'requested');

      g_form.setMandatory('assigned_to', true);

  g_form.setMandatory('assignment_group', true);

      g_form.setMandatory('start_date', true);

      g_form.setMandatory('end_date', true);

      g_form.setMandatory('u_after_hours', true);

      g_form.setMandatory('description', true);

      g_form.setMandatory('u_risk_analysis', true);

      g_form.setMandatory('u_communication_plan', true);

      g_form.setMandatory('change_plan', true);

      g_form.setMandatory('backout_plan', true);

      g_form.setMandatory('test_plan', true);

      g_form.setMandatory('u_tested_by', true);

      g_form.setMandatory('u_test_completion_date', true);

     

      //Call the UI Action and skip the 'onclick' function

      gsftSubmit(null, g_form.getFormElement(), 'request.approval');

}

 

 

// Code that runs without 'onclick'

// Ensure call to server-side function with no browser errors

if(typeof window == 'undefined'){

      serverApproval();

}

 

 

function serverApproval(){

      // Set the state to Undergoing Approval and the Approval field to requested, save the update and reload

      // the form, which starts the emergency workflow.

      action.setRedirectURL(current);

      current.approval='requested';

      current.update();

}

1 ACCEPTED SOLUTION

In the end, I added a reference qualifier of Sys id is javascript:gs.getUserID() to the field in question.



If they get the magnifying glass after the request approval fails, it limits their choice to only themselves and solves the root of my issue.


View solution in original post

9 REPLIES 9

amkatulak
Giga Expert

Is your UI Policy set to run on Load?   After clicking your UI action, does your form layout or view change to the point where your condition field is no longer on the form?


The Client script is an onload. I tried replacing it with an on load UI policy, but no change.



After clicking the UI Action, the form does not change at all (whether it's successful or not).   If successful, it moves the workflow to the next step and changes the value of the approval field from "not requested" to "requested".



If not successful, you get a popup informing you of the required fields and then you're required to fill them in.



Incidentally, I tried this in a ServiceNow instance shared by one of our reps (basically OOB).   I modified the OOB request approval UI action to run in the browser (On Click) and added a line into the script to make a single field a required value.   I added a simple UI policy to make that same field read-only and same issue.



Maybe it's meant to work this way?   Suppose I'll break down and submit a request via Hi


Have you tried debugging your UI policies to see where they might be failing?


geoffcox
Giga Guru

Your serverApproval function contains code that only runs server side. No doubt this breaks the onLoad handler and prevents your other code from completing properly so it protects the field.