- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2025 12:51 AM
Hello Community,
We are attempting to retrieve the "Requested For" and "Opened By" fields from the sysapproval table, but we are currently unable to retrieve these values. We would appreciate assistance in triggering the "Requested For" and "Opened By" fields. Below, I have outlined the trigger conditions and the event script.
We would be grateful for any guidance on how to resolve this issue and implement the necessary enhancement. Thank you in advance for your support.
Advanced script:
--------------------------------
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2025 01:06 AM
use this in your script
I assume event, notification is on Approval table and Event parm1 contains Recipient checkbox is True
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var gr = new GlideRecord("sc_req_item");
gr.addQuery("sys_id", current.sysapproval);
gr.query();
if (gr.next()) {
var values = gr.requested_for.toString() + ',' + gr.opened_by.toString();
gs.eventQueue("Freelancer_reject", current, values);
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
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-25-2025 01:28 AM - edited ‎02-25-2025 01:29 AM
Requested for and Opened By are not variables in RITM so we can directly access fields from sysapproval.
Kindly pass below parameters in your query. It should work.
gs.eventQueue("Freelancer_reject", current, current.sysapproval.requested_for.email,current.sysapproval.opened_by.email);
If this solution works for you, then kindly mark Accept Solution/Helpful.
Regards,
Sourabh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2025 01:00 AM
(function executeRule(current, previous ) {
var approvalRecord = new GlideRecord(current.sysapproval.getRefRecord().getTableName()); // Get related record
if (approvalRecord.get(current.sysapproval)) {
var requestedFor = approvalRecord.getValue("requested_for");
var openedBy = approvalRecord.getValue("opened_by");
gs.eventQueue("Freelancer_reject", current, openedBy, requestedFor);
}
})(current, previous);
How This Fixes the Issue
Correctly fetches the "Requested For" and "Opened By" fields from the referenced request record
Uses getRefRecord() to dynamically get the correct record type from sysapproval
Prevents errors due to missing fields in sysapproval
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2025 01:04 AM
First of all, every time you assign a value to a variable you have to check that if is a valid value, before sending or processing. I recommend to ensure that everything is ok before sending it to event. I would like to see how you configured the notification, how you assigned the parameters?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2025 01:06 AM
use this in your script
I assume event, notification is on Approval table and Event parm1 contains Recipient checkbox is True
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var gr = new GlideRecord("sc_req_item");
gr.addQuery("sys_id", current.sysapproval);
gr.query();
if (gr.next()) {
var values = gr.requested_for.toString() + ',' + gr.opened_by.toString();
gs.eventQueue("Freelancer_reject", current, values);
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2025 03:24 AM
Great thanks for your solution, I am also facing the same issue and this solution helped me to resolve my issue. Thanks