- 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-22-2024 10:45 PM
Hello @TanayaGavande , you can add query to the edit UI action itself. Parsing "uri" variable you will get the sys_id of the incident record and you can add script on UI action to get company of the current incident and add query for company in "uri.set('sysparm_query', '');". This sysparm_query is responsible for the filter on the list opening after clicking edit button.
Please accept my solution if it works for you and thumps up to mark it as helpful.
Thank you!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 04:23 AM - edited 07-23-2024 09:52 AM
Thanks for your reply @Shivam_Kumar and @Satishkumar B ! This works, but not for the reference field. The company is a Reference field. When I log current.sys_id, I get the incident sys id as expected, but if i dot walk to current.company.sys_id, the result shows null, so the filter does not work. I also tried with GlideRecord on the Incident table to get the current's account, but it shows null still.
Here's my script:
Am I doing anything wrong?
Also, is there any way we can hide this filter?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2024 02:19 AM
Hello @TanayaGavande - Using "current.sys_id" you will not get current incident sysID. you can add the below code to get incident sysId and use this sys_id to get account.
Please accept my solution if it works for you and thumps up to mark it as helpful.
Thank you!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 05:17 AM
Thanks for your reply @Shivam_Kumar , however, I have no problem getting the current incident's sys id. What I need is the sys id of the Company field of the incident, as I want to add the filter based on incident company, i.e.
uri.set('sysparm_query', 'company='+{incident.company.sys_id});
This is just a sample but I want something like this.
I tried dot-walking and also Glide Query, and even when I have the Incident sys id, I get the Company's sys id as null in the logs.
Is there any way to do this?
Thanks