- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2023 03:25 AM
Hello experts,
I am trying to alert in UI’s page client script and the message to be displayed on the UI form but the script is not working for some reason.
I want a message to be displayed on below form when the user tries to press OK without filling the reference fields (Select a Parent and Select Type of Relationship).
Below is my UI Page script:
HTML section:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<j:set var="jvar_ObjList" value="${sysparm_checkedRecord}"/>
<g:ui_form id="f_id">
<center>
<table>
<tr>
<td>Select a Parent: </td>
<td><g:ui_reference name="nameCi" table = "cmdb_ci_server" query="sys_idNOT IN${sysparm_checkedRecord}"/> </td>
</tr>
<tr style="height: 25px;"/>
<tr>
<td>Select Type of Relationship: </td>
<td><g:ui_reference name = "nameRel" table = "cmdb_rel_type"/> </td>
</tr>
<tr style="height: 25px;"/>
<tr>
<td>Click OK to create these relationships</td>
</tr>
<tr>
<td align="right" colspan="2">
<br />
<input type="hidden" id="childCis" name="childCis" value="${sysparm_checkedRecord}"/>
<g:dialog_buttons_ok_cancel ok="return validate()" />
</td>
</tr>
</table>
</center>
</g:ui_form>
</j:jelly>
Client script section:
function validate() {
if (nameCi == '') {
alert('Please fill in Parent field');
}
else if (nameRel == '') {
alert('Please fill in Type of Relationship field');
}
GlideDialogWindow.get().destroy();
return true;
}
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2023 06:53 AM
Hi @EH Desev ,
the issue might be related to how you are trying to access the field values in your validation function. In Jelly, you should use '${}' syntax to reference variables, but it seems you are trying to access `nameCi` and `nameRel` directly.
Here's how you can modify your validation function:
function validate() {
var nameCiValue = '${nameCi}'; // Use ${} to get the value of the Jelly variable
var nameRelValue = '${nameRel}';
if (nameCiValue == '') {
alert('Please fill in Parent field');
return false;
} else if (nameRelValue == '') {
alert('Please fill in Type of Relationship field');
return false;
}
GlideDialogWindow.get().destroy();
return true;
}
Make sure to use '${}' to reference the Jelly variables (`nameCi` and `nameRel`). Also, I added `return false;` after each `alert` statement to prevent the form submission when validation fails.
If you still face issues, consider checking your browser's console for any JavaScript errors, which can provide more information about the problem.
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2023 09:14 AM
Hi Danish,
Unfortunately now I came across another problem.
The alert is displaying every time even when the two fileds are filled. It seems that the "if" condition returns "true" every time, even when it is "false" and triggers the alert. Any thoughts what could be causing this?
function validate() {
var nameCiValue = '${nameCi}';
var nameRelValue = '${nameRel}';
if (nameCiValue == '') {
alert('Please fill in Parent field');
} else if (nameRelValue == '') {
alert('Please fill in Type of Relationship field');
return false;
}
GlideDialogWindow.get().destroy();
return true;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2023 07:16 PM
Hi @EH Desev ,
Can u put an alert for nameCiValue field or nameRelValue field n see what it is displaying?
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2023 01:17 AM
Hi
Thanks for the proposal, this helped me troubleshoot the issue.
I had to change the values in the scrip as follows:
nameCiValue = nameCi.value;
nameRelValue = nameRel.value;