Edit... button filter condition issue

mpaskov
Tera Contributor

Hello,

I have overriden the Edit... button for the incident table as I have set a filter condition. The code is as below:

var uri = action.getGlideURI();
var path = uri.getFileFromPath();
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');
uri.set('sysparm_query', 'active=true^parent_incidentISEMPTY^child_incidents=0^company=' + current.company);
action.setRedirectURL(uri.toString('sys_m2m_template.do'));

The problem I am facing is that the "current" is not functioning as expected. I don't have access to any field value of the current record. Only current.sys_id is delivering random value. If I try to use the UI Action as client it won't work. Also current.variables.<field value> is not working. I even tried using onDisplay BR with g_scratchpad which didn't work.

1 ACCEPTED SOLUTION

Mahendra RC
Mega Sage

Hello @mpaskov ,

Please check with below script you can get the current record sys_id and then use the sys_id to get the required details if needed:

var incidentGuid = action.getGlideURI().getMap().get('sysparm_collectionID');

var uri = action.getGlideURI();
var incidentGuid = action.getGlideURI().getMap().get('sysparm_collectionID');
var gr = new GlideRecord("incident");
if (gr.get(incidentGuid)) {
// get the required field details
}
var path = uri.getFileFromPath();
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');
uri.set('sysparm_query', 'active=true^parent_incidentISEMPTY^child_incidents=0^company=' + current.company);
action.setRedirectURL(uri.toString('sys_m2m_template.do'));

Please mark my respsone as helpful/correct, if it answer your question.

Thanks

View solution in original post

7 REPLIES 7

AnubhavRitolia
Mega Sage
Mega Sage

If UI Action is Client Side, you need to use below function to write Servicenow Side code.

gsftSubmit(null, g_form.getFormElement(), "ui action id") triggers the UI Action which is specified in the 3rd parameter, which is the action name/element id.

 

Use below link for sample:

https://servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/

Please mark this as correct answer if it resolved, or mark this helpful if this help you to reach towards solution.

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

It is not working. This is what I am getting find_real_file.png

I have a doubt. I am setting this filter condition through code only. Once the filter is set, I want to make it Read-only for end users. No one should be able to change it manually ?

How to achieve this one?

 

Thank you, 

Hi Asmita, Did you found the solution to this. Actually I am also facing same problem and need some assistance.