- 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-16-2023 06:30 AM
Hi @EH Desev
you write " but the script is not working for some reason."
--> What exactly is not working? Please describe the observed behavior.
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2023 08:10 AM
Hi Maik,
It is not displaying the alert with the message.
Best regards,
- 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 08:17 AM
Thank you very much, Danish! Changed the code and that displayed the alert.