- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2023 07:05 AM
Hello.
I'm working on creating a Query script for Relationship.
I would like to use the sys_id of the current record to narrow down the records displayed in the related list, but I am having trouble getting the sys_id using current.sys_id.
How can I get the sys_id of the currently displayed record?
thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2023 08:17 AM
Hey @SO10 :
if you are looking to narrow down the search of the file which has test in its name then your relationship query should be like the below and
Queries from: Attachment
Applies to : <Should be your target table>
var qc = current.addQuery('table_sys_id', parent.sys_id);
qc.addQuery('file_name', 'test.pdf');
Mark this as Helpful / Accept the Solution if this clears your issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2023 07:08 AM
Hi @SO10 Can you please post the script here?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2023 08:02 AM
@Eswar Chappa
Thank you for your reply.
I have created the following script.
(function refineQuery(current, parent) {
var attachment = new GlideSysAttachment();
var agr = attachment.getAttachments('u_test', current.sys_id);
var attachmentSysIds = [];
while (agr.next()) {
var fileName = agr.getValue('file_name');
if (fileName.includes('test.pdf')) {
attachmentSysIds.push(agr.getValue('sys_id'));
}
}
current.addQuery('u_attachment_id', attachmentSysIds);
})(current, parent);
What I want to do is query the u_attachment_id field of the related list with the sys_id of the test file attached to the record in the u_test table. For that I want to get the sys_id of the currently open record in u_test.
I'm not very good at scripting, so sorry if I'm wrong to begin with.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2023 08:17 AM
Hey @SO10 :
if you are looking to narrow down the search of the file which has test in its name then your relationship query should be like the below and
Queries from: Attachment
Applies to : <Should be your target table>
var qc = current.addQuery('table_sys_id', parent.sys_id);
qc.addQuery('file_name', 'test.pdf');
Mark this as Helpful / Accept the Solution if this clears your issue