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

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

Your solution is working for me. Thanks a lot! 🙂

var query = 'active=true^parent_incidentISEMPTY^child_incidents=0';
var incidentGuid = action.getGlideURI().getMap().get('sysparm_collectionID');
var gr = new GlideRecord("incident");
if (gr.get(incidentGuid)) {
    query += '^company=' + gr.company;
}

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', query);
action.setRedirectURL(uri.toString('sys_m2m_template.do'));

Thank you very much for the important and useful solution.

 

I have used this code and it is working ang creating Filter condition on "sys_m2m_template.do" form.

But this filter condition is editable for end users.

I want to make these Filter condition as  "Read Only".

 

How to achieve it ?

 

Thank you,