- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2024 11:05 AM
Hi All,
I have a requirement on the Incident form related list, i.e. the list of incidents with their parent as the form incident. I only have the Edit UI action present on the list, and I want to add filter based on the Account of the main incident, i.e. If the Account of the parent incident is XYZ company, I want the list to show incidents of the XYZ company only, when I click 'Edit' on the related list.
I tried adding filter on the list control, but I don't know how to make it dynamic according to the form. Any help is appreciated.
Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 10:10 AM
@TanayaGavande Worked for me. check the below code .
var uri = action.getGlideURI(); uri.set('sysparm_m2m_ref', current.getTableName()); uri.set('sysparm_collection_related_file', current.getTableName()); uri.set('sysparm_form_type', 'o2m'); uri.set('sysparm_stack', 'no'); // Generate redirect URL var redirectUrl = uri.toString('sys_m2m_template.do'); // Extract sys_id from the URL function extractSysId(url) { var start = url.indexOf('sysparm_collectionID=') + 'sysparm_collectionID='.length; return start === -1 ? null : url.substring(start, start + 32); } var extractedSysId = extractSysId(redirectUrl); gs.info('Extracted Sys ID: ' + extractedSysId); // Query and update URI based on the extracted sys_id var gr = new GlideRecord(current.getTableName()); if (gr.get(extractedSysId)) { gs.info('Service Offering Field Value: ' + serviceOffering); uri.set('sysparm_query', 'company=' + gr.getValue('company')); } else { uri.set('sysparm_query', ''); } action.setRedirectURL(uri.toString('sys_m2m_template.do'));
……………………………………………………………………………………………………
Please Mark it helpful and Accept Solution!! If this helps you!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 09:17 AM - edited 07-25-2024 10:11 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 10:23 AM
Hi @Satishkumar B , thanks a lot! This worked for me. However, is there any way I can make this filter read only or hide it? I don't want someone to simply remove it and get access to all the records.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 09:22 AM - edited 07-25-2024 09:23 AM
Hi @TanayaGavande
can you please update your below code in your Edit button. below code worked for me to get the sysid of company and was able to filter based on that.
//Initialize URI and set parameters
var uri = action.getGlideURI();
uri.set('sysparm_m2m_ref', current.getTableName());
uri.set('sysparm_collection_related_file', current.getTableName());
uri.set('sysparm_form_type', 'o2m');
uri.set('sysparm_stack', 'no');
// Generate redirect URL
var redirectUrl = uri.toString('sys_m2m_template.do');
// Extract sys_id from the URL
function extractSysId(url) {
var start = url.indexOf('sysparm_collectionID=') + 'sysparm_collectionID='.length;
return start === -1 ? null : url.substring(start, start + 32);
}
var extractedSysId = extractSysId(redirectUrl);
gs.info('Extracted Sys ID: ' + extractedSysId);
// Query and update URI based on the extracted sys_id
var gr = new GlideRecord(current.getTableName());
if (gr.get(extractedSysId)) {
gs.info('Service Offering Field Value: ' + serviceOffering);
uri.set('sysparm_query', 'company=' + gr.getValue('company'));
} else {
uri.set('sysparm_query', '');
}
action.setRedirectURL(uri.toString('sys_m2m_template.do'));
……………………………………………………………………………………………………
Please Mark it helpful 👍and Accept Solution✔️!! If this helps you!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 09:25 AM
Hi @TanayaGavande
can you please update your below code in your Edit button. below code worked for me to get the sysid of company and was able to filter based on that.
//Initialize URI and set parameters
var uri = action.getGlideURI();
uri.set('sysparm_m2m_ref', current.getTableName());
uri.set('sysparm_collection_related_file', current.getTableName());
uri.set('sysparm_form_type', 'o2m');
uri.set('sysparm_stack', 'no');
// Generate redirect URL
var redirectUrl = uri.toString('sys_m2m_template.do');
// Extract sys_id from the URL
function extractSysId(url) {
var start = url.indexOf('sysparm_collectionID=') + 'sysparm_collectionID='.length;
return start === -1 ? null : url.substring(start, start + 32);
}
var extractedSysId = extractSysId(redirectUrl);
gs.info('Extracted Sys ID: ' + extractedSysId);
// Query and update URI based on the extracted sys_id
var gr = new GlideRecord(current.getTableName());
if (gr.get(extractedSysId)) {
gs.info('Service Offering Field Value: ' + serviceOffering);
uri.set('sysparm_query', 'company=' + gr.getValue('company'));
} else {
uri.set('sysparm_query', '');
}
action.setRedirectURL(uri.toString('sys_m2m_template.do'));
……………………………………………………………………………………………………
Please Mark it helpful 👍and Accept Solution✔️!! If this helps you!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 09:30 AM
Hi @TanayaGavande ,
Hi @TanayaGavande ,
Please refer to below thread:
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
Thanks & Regards,
Sumanth Meda