Use PDIs? Take our 5-minute survey to help shape the PDI roadmap.

Catalog UI Policy and Catalog UI Policy Action

DeIvory Gordon
Tera Guru

Hello,

 

I am creating a catalog item and I need to create a catalog UI Policy and Catalog UI Action based on the variable below:

 

* Is Terminated User a Manager?

    Dropdown List with Two options:

      - Yes
      - No

 

UI Action if Yes is selected:

 

Direct Reports

This should auto populate a list of the manager's direct reports.

 

I do not know how to set up the UI Policy Action so that a list of the manager's direct reports auto populates.  Thank you for any help you can offer.

 

2 ACCEPTED SOLUTIONS

Dr Atul G- LNG
Tera Patron

Hi @DeIvory Gordon 

 

In this case, you need to set the value using a script. A UI Policy can only perform three actions: make a field Read-only, Mandatory, or Visible. If you want to set or modify a field value, you need to write a script in the Advanced section of the UI Policy.

****************************************************************************************
Regards
Dr Atul G. - Learn N Grow Together ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
******************************************************************************************

View solution in original post

Nishant8
Tera Sage

Hello @DeIvory Gordon , If I understand the requirement correctly then you'd like to show direct report based on user selected in another variable. If so, I think there is no need of UI policy here,. Instead, you can have/create two reference variables that refer to User [sys_user] table and one On Change client script.

- First reference variable should be of type simple and referring to User table

- Second reference variable should be of type Advanced with following configuration:

  • Reference qualifier: javascript&colon; 'manager=' + current.variables.<first_variable>;
  • Variable attributes: ref_qual_elements=<first_variable>

- Create additional On Change Client Script to clear the value:

   

function onChange(control, oldValue, newValue, isLoading) {
    // Do not run when the form is loading
    if (isLoading) {
        return;
    }
    g_form.clearValue('<second_variable>'); 
}

OR

Alternatively, you can hide the second variable initially and make visible based on the UI policy that you referred to. Also, you can have the Checkbox variable included in the reference qualifier of second variable.

 

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron

@DeIvory Gordon 

where should the manager's direct reportees be auto-populated?

share form screenshots

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Tanushree Maiti
Tera Patron

Hi @DeIvory Gordon ,

 

Using Catalog UI policy and Catalog UI policy Action , for the specific condition , you can make variable

  •  Mandatory or optional.
  •  Visible (show) or hidden.
  •  Read-only or editable

It is not for auto-populate.

 

To auto-populate you can use a onchange client script and a script include.

If your Direct Reports variable is a reference variable/list collector variable etc where you want to populate, you can try this code .

 

Sample code/ Not tested: (update as per your requirement)

 

1: Create a Script IncludeCreate marked as Client callable

GetDirectReports = Class.create();
GetDirectReports.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getReports: function() {
var managerID = this.getParameter('sysparm_manager_id');
var reports = [];
var gr = new GlideRecord('sys_user');
gr.addQuery('manager', managerID);
gr.addQuery('active', 'true');
gr.query();
while (gr.next()) {
reports.push(gr.getValue('sys_id'));
}
return reports.join(',');
},
type: 'GetDirectReports'
});

 

2: Create an onChange Catalog Client Script running on your "Yes/No"

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var selectedChoice = g_form.getValue('is_terminated_user_is_a_manager_variable'); //update your actual variable name
var managerID = g_form.getValue('requested_for');

if (selectedChoice == 'Yes' && managerID) {
var ga = new GlideAjax('GetDirectReports');
ga.addParam('sysparm_name', 'getReports');
ga.addParam('sysparm_manager_id', managerID);
ga.getXMLAnswer(function(answer) {
if (answer) {
g_form.setValue('direct_reports_variable', answer); //update your actual variable name
} else {
g_form.clearValue('direct_reports_variable');
}
});
} else {
g_form.clearValue('direct_reports_variable');
}
}

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti