We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Catalog UI Policy script with multiple conditions

Jeremy F_
Giga Expert

Greetings All,

I am brand new to scripting, so any assistance I can get here is greatly appreciated. I am working on a complex catalog item created by the previous administrator. I have been able to solve for most of the gaps needing addressed, but I am stuck on a few items that look like scripting will be required to solve. From this post, I'm seeking scripting help to make a specific set of variables available based on the following conditions:

If field "access_requested_for" is not empty, then search for user department
If user department is Information Technology, then visible = true

If (checkbox) Team Member Not Found = true and "team_member_department" field is "Information Technology", then visible = true

9 REPLIES 9

Sorry, that detail escaped my attention.

In this case, you can try to use producer.variable_name passing your conditions and setting up your parameters after that.

I strongly recommend you research about it.

If I could help you, please mark it as Helpful and Correct.

You should be able to set the 2nd condition, if you have department name setup in team_member_department field.

 

For first condition, you might have to use client script. Client Script will be onchange script on access_requested_for field.

 

 

 

Thank you for pointing me in the right direction. Here is my rudimentary attempt at scripting this. I could use some more guidance if you are willing.

//I'm guessing on how to start this script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

//Attempting to pull department field from the sys_user table
var userInfo = new GlideRecord('sys_user');
gr.addQuery('department');
//access_requested_for is a refrence field pulling from the sys_user table.
//I need to get the access_requested_for user department
var Dept = g_form.getValue('variables.access_requested_for', 'department');
//If access_requested_for user departement is Information Technology
//Then it_access variable set is visible
if (Dept == 'Information Technology'){
g_form.setVisible('it_access', true);
}
}

Jeremy F_
Giga Expert

When the setDisplay is true, the variables always show. When the setDisplay is false, it does not sure. Not sure why the "if" condition is being ignored. Also, I can't get the script to accept an "else" condition.

find_real_file.png

-O-
Kilo Patron

You have an extra ; after the if statement condition. Basically you have a - say - empty if that does nothing.

Another problem is that the second condition of the if block will never be true: getReference returns an object and that will not be equal to string 769ff..19c1. You need to get to the sys_id of the loaded reference record and compare to that.

Also don't compare values obtained by calling g_form.getValue() to true or false. Use g_form.getBooleanValue instead of g_form.getValue().