How to pass If condition in UI page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2024 04:33 AM
Hi Everyone,
i have passed the assignment group of a current record from client script to UI page:
now i want to validate it for multiple groups, but how do i do it, simply doing:
if(grpname='sysid1') - works
if(grpname='sysid1'||grpname='sysid2') - does not work
how do i check multiple if condition with OR operator?
Thanks,
kartikey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2024 05:56 AM
Hello @kartikey,
Instead of "=" try "==" like below code:
if (grpname == 'sysid1' || grpname == 'sysid2') {
// Your code block when grpname matches 'sysid1' or 'sysid2'
}
Please accept my solution if it works for you and thumps up to mark it as helpful.
Thank you!!
Thank you!!
Dnyaneshwaree Satpute
Tera Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2024 05:17 AM
Hi,
sorry for the late response, but i tried and it does not work 😞
i'm using != but it only validates for one group if i add multiple groups using || (or condition) it does not validate.
Thanks,
Kartikey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2024 05:47 AM
Hi @kartikey
Please try this code below
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null">
<g:evaluate>
// Get assignment group name from UI Page parameter
var grpname = RP.getWindowProperties()["sysparm_group"];
// Array of valid assignment group sys_ids
var validGroups = ['sys_id_of_group1', 'sys_id_of_group2']; // Replace with your actual sys_ids
// Check if the group is valid
if (validGroups.indexOf(grpname) != -1) {
// Valid group: Proceed with displaying tasks (or your desired action)
var grRITM = new GlideRecord('sc_task');
grRITM.addQuery('request_item', jelly.sysparm_request_item_id);
grRITM.addQuery('stage', '!=', 'closed_complete');
grRITM.orderBy('number');
grRITM.query();
while(grRITM.next()){
var taskNumber = grRITM.getValue('number');
var shortDescription = grRITM.getValue('short_description');
<div>${taskNumber} - ${shortDescription}</div>
}
} else {
// Invalid group: Display error message (or alternative action)
<div class="error-message">Invalid assignment group!</div>
}
</g:evaluate>
</j:jelly>
Key Changes and Explanations:
1. Retrieving Group Name:
* var grpname = RP.getWindowProperties()["sysparm_group"]; gets the group name (sys_id) passed as a parameter from the client script.
2. Valid Groups Array:
* var validGroups = ['sys_id_of_group1', 'sys_id_of_group2']; defines an array of the allowed group sys_ids. Replace the placeholders with the actual sys_ids of your valid assignment groups.
3. Validation with indexOf():
* if (validGroups.indexOf(grpname) != -1) checks if the grpname exists within the validGroups array:
* If the group is found, its index will be a non-negative number (>= 0), so the code inside the if block will execute (e.g., display tasks).
* If the group is not found, indexOf() returns -1, so the code inside the else block will execute (e.g., display an error message).
4. Conditional Logic:
* The rest of the script remains the same, with the task display logic moved inside the if block to ensure it only runs if the group is valid
Also make sure client script pass the group_sysid as a parameter
Client Ajex Script
function openUIPage() {
var ga = new GlideAjax('YourScriptIncludeName');
ga.addParam('sysparm_name', 'getAssignmentGroup'); // Call a Script Include to get the sys_id
ga.getXMLAnswer(function(response) {
var grpname = response;
var url = 'your_ui_page.do?sysparm_request_item_id=' + g_form.getUniqueValue() + '&sysparm_group=' + grpname;
window.open(url, '_blank');
});
}
If you like this solution. Please kindly mark this as your best answer and help to contribute more to this community