UI policy "Clear the variable value" makes a field editable in requested item view
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2020 02:29 AM
I've created a catalog item with several variables, then added UI policy to show and require some variables based on answer to a previous question.
- "Applies on Requested Items" is checked on UI Policy
- UI Policy Action is configured as follows:
It works fine in service portal, but then on requested item view the variable is editable (should be read-only) and the value is empty (it should include user's answer).
It works if I uncheck the 'Clear the variable value', but I want it to be cleared when user selects something else... Is there any other way to make it work?
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2022 09:29 AM
Hello.
Does your Catalog UI Policy run On load?
I think if the Catalog UI Policy run On load and Applies on Requested Items, if the Catalog UI Policy Action is set to true in Clear the variable value option, when the requested item loads the variable is already fulfilled and because of that the Catalog Conditions are evaluated returning true and so the Catalog UI Policy Action will be applied - meaning, will clear the variable on the requested item.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2022 02:14 AM
any solution for this I am facing the same issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2024 01:58 AM
Any solution for this I am facing same issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2024 02:06 AM
Hi @Anirudh_saraf @Noor Mohammad1
Here's how you can implement the solution using Client Scripts in ServiceNow:
Client Script for Read-Only Behavior (onLoad function)
// Client Script to set read-only behavior based on conditions
function onLoad() {
var answerToPreviousQuestion = g_form.getValue('previous_question_variable'); // Replace with actual variable name
var fieldSysId = g_form.resolveNameMap('variable_name'); // Replace with actual variable name
if (answerToPreviousQuestion === 'desired_value') {
g_form.setReadOnly(fieldSysId, true);
} else {
g_form.setReadOnly(fieldSysId, false);
}
}
Client Script for Value Clearing (onChange function)
// Client Script to clear variable value based on conditions
function onChange(control, oldValue, newValue, isLoading) {
if (!isLoading) {
if (newValue !== 'desired_value') {
g_form.clearValue('variable_name'); // Replace with actual variable name
}
}
}
These Client Scripts provide granular control over field behaviors in ServiceNow, ensuring fields are correctly read-only or cleared based on user interactions.
--------------------------------------------------------------------------------------------------------------------
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful." This action benefits both the community and me.