- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2022 01:41 AM
Hi All,
There is a check box field called "Activate" under the section of "Times" in the form. I need "Activate" check box TRUE.
This section "Times" and fields under this section will be shown when the "Attach Time" check box is TRUE, so I tried to make "Activate" check box field true in the configure dictionary and it's not working.
So I decided to write UI policy script "when to apply" condition is "Attach Time is TRUE"
In script: Execute if true is " g_form.setValue('u_activate', true);" and Execute if false is " g_form.setValue('u_activate', false);" it's working fine.
Here my concern is under "Activate" check box there are a few duration fields like P1, P2 & P3. When user don't need these value they will uncheck "Activate" check box then P1, P2 & P3 fields will be hidden(using UI policy).
When user unchecked "Activate" check box and save the form, this field value is still TRUE because of the UI policy script.
How can I make "Activate" field TRUE by default without based on "Attach Time" field?
Note; Tried default true in the config dictionary.
Please help!
Thanks,
Ksnow
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2022 05:39 AM
Hi
What you can do here is try to handle the logic in an On Change Client script including what is required on On Load as well in the same script:
1) Create a On Change Client script and use the sample script below:
First Scenario: When Attach checkbox is marked as True then display the field and Tabs you want in On Change Script and Also make Activate checkbox as True.
2) For the scenario where you are stuck, evaluate in the same On Change script that when Activate changes to false, hide the fields you want.
3) At the same time in the loading area of On Change client script, evaluate the oldValue of Activate checkbox and then control the visibility of fields P1, P2 etc.
Sample script shown below:
On Change script will be on Attach field, please make sure you select Attach field after selecting On Change Type in your client script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
if (g_form.getValue('Attach Field Name') == true && g_form.getValue('Activate Field Name') == true) {
g_form.setDisplay('Field Name', true);
g_form.setDisplay('Field Name', true);
}else if(g_form.getValue('Attach Field Name') == true && g_form.getValue('Activate Field Name') != true){
g_form.setDisplay('Field Name', false);
g_form.setDisplay('Field Name', false); // Field you want to hide
}
return;
}
if (newValue) {
g_form.setDisplay('activate', true);
}
//Type appropriate comment here, and begin script below
}
Along with this just have one UI Policy for showing or hiding Field P1, P2 on change of Activate checkbox.
This should work for your scenario.
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2022 02:01 AM
Hi,
based on u_activate you want to show/hide some fields?
Did you ensure onLoad checkbox is true?
Did you ensure Reverse if false checkbox is true?
can you share your UI policy screenshot
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2022 02:14 AM
Hi
Yes, based on u_activate I want to show/hide some fields.
Yes, onLoad checkbox is true and Reverse if false is true.
UI policy is working fine. My concern is to make "Activate" field TRUE by default.
Tried true in the default field config dictionary
Currently I am making it TRUE in UI policy due to this when user made "Activate" FALSE also it not getting unchecked.
Please help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2022 02:32 AM
Hi,
don't make it true in UI policy
Try to set u_activate as true in onload client script
client script executes first and then UI policy so your UI policy will work accordingly.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2022 02:29 AM
Hi,
In this case don't use type TRUE/False for 'Activate' field. Instead use a select box and give choices: True (order 1) and False (order 2).
This way you can have default True choice value. And your ui policies will work the same.
Please mark the answer helpful/correct based on impact!
Thanks,