- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2024 01:28 PM - edited 03-29-2024 01:31 PM
Hi All,
We have a requirement where we have a record on "Request" table and when a "Request" got created from a record producer it will creates a "Request" record and the record will be in "Pending" state once it gets created.
So we have approve and reject buttons on the record level. Whenever user click on "Reject" button to reject the request then we are expecting a dialog box should be pop up on the record and ask the user to "Enter the reason for rejecting the request"
If user gives any reason as comments on that dialog box then the "Request" record should get rejected and that comments should be updated in another record which is "Item" Record and it should go to "Closed Incomplete" state.
Can someone please help us on this 🙂
Thanks,
Yamini
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2024 11:55 PM
Hi @Yamini Athimuru
To achieve this functionality, you will need to use a combination of Ui Actions and business rules.
Step 1: Add Reject Button with UI Action
First, ensure you have a “Reject” button available for the request record. You do this via a UI Action.
UI Action Configuration
- Name: Reject Request
- Action name: reject_request
- Table: Request (or the exact table name, if it’s a different one)
- Condition: current.state == 'pending' (Adjust according to your field names and values)
- Type: List and Form
- Form button: True
- Script:
function confirmRejection() {
var reason = prompt("Enter the reason for rejecting the request:");
if (reason != null && reason != "") {
g_form.setValue('u_rejection_reason', reason); // Assuming ‘u_rejection_reason’ is the field to hold rejection reason on Request record
g_form.setValue('state', 'rejected'); // Update this based on your ‘Rejected’ state value
g_form.save();
}
}
confirmRejection();
Step 2: Create a Business Rule for After State Change
Next, create a business rule that triggers after the state of a request changes to handle the update on the related item record.
Business Rule Configuration
- Name: Handle Request Rejection
- Table: Request (or your specific table name)
- When to run: After, Update
- Filter Conditions: State changes to Rejected (Adjust the condition based on your field names and values)
- Script:
// Check if the rejection reason is present
if (current.u_rejection_reason.nil()) {
return; // Exit if there’s no rejection reason
}
// Retrieve the related item record. Assuming there’s a reference field to item record named ‘related_item’
var itemGR = new GlideRecord('item_table_name'); //Replace ‘item_table_name’ with the actual Item table name
if (itemGR.get(current.related_item)) {
itemGR.state = 'closed_incomplete'; // Set the state to ‘Closed Incomplete’. Update the field and value as necessary.
itemGR.u_rejection_comments = current.u_rejection_reason; // Copy the rejection reason. Adjust field names as necessary.
itemGR.update();
}
Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning
Thanks & Regards
Deepak Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2024 11:55 PM
Hi @Yamini Athimuru
To achieve this functionality, you will need to use a combination of Ui Actions and business rules.
Step 1: Add Reject Button with UI Action
First, ensure you have a “Reject” button available for the request record. You do this via a UI Action.
UI Action Configuration
- Name: Reject Request
- Action name: reject_request
- Table: Request (or the exact table name, if it’s a different one)
- Condition: current.state == 'pending' (Adjust according to your field names and values)
- Type: List and Form
- Form button: True
- Script:
function confirmRejection() {
var reason = prompt("Enter the reason for rejecting the request:");
if (reason != null && reason != "") {
g_form.setValue('u_rejection_reason', reason); // Assuming ‘u_rejection_reason’ is the field to hold rejection reason on Request record
g_form.setValue('state', 'rejected'); // Update this based on your ‘Rejected’ state value
g_form.save();
}
}
confirmRejection();
Step 2: Create a Business Rule for After State Change
Next, create a business rule that triggers after the state of a request changes to handle the update on the related item record.
Business Rule Configuration
- Name: Handle Request Rejection
- Table: Request (or your specific table name)
- When to run: After, Update
- Filter Conditions: State changes to Rejected (Adjust the condition based on your field names and values)
- Script:
// Check if the rejection reason is present
if (current.u_rejection_reason.nil()) {
return; // Exit if there’s no rejection reason
}
// Retrieve the related item record. Assuming there’s a reference field to item record named ‘related_item’
var itemGR = new GlideRecord('item_table_name'); //Replace ‘item_table_name’ with the actual Item table name
if (itemGR.get(current.related_item)) {
itemGR.state = 'closed_incomplete'; // Set the state to ‘Closed Incomplete’. Update the field and value as necessary.
itemGR.u_rejection_comments = current.u_rejection_reason; // Copy the rejection reason. Adjust field names as necessary.
itemGR.update();
}
Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning
Thanks & Regards
Deepak Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2024 10:49 AM
Hi @Deepak Shaerma,
Thanks for the script on the UI action and Business Rule. But I have achieved the same functionality using a UI Page and calling that UI page in UI action which is working as expected now.
I haven't tried your solution but marking it as helpful.
Thanks & Regards,
Yamini
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2024 12:01 AM - edited 06-04-2024 12:03 AM
Hi @Yamini Athimuru ,
even I have the same requirement on change table, can you please copy the script here, then it will be helpful for me. Already I created UI action for the Reject button, but not able to get the dialogue window for reject reason. Below is the script for reject UI action. Please copy the code using the UI page and calling the UI page in UI action. Below is my code for Reject UI action.
Note: We don't have any field called "Rejection Reason" on the table.