The CreatorCon Call for Content is officially open! Get started here.

David Neves
Kilo Guru

If you have 3 tables: 

  • Table A 
  • Table B 
  • Table C 

Table B has a reference to A and another to C. 

 

If you want to relate records from table A to C, making B behave like a m2m, you need to override the Edit that shows on the RL with the action name 'sysverb_edit_o2m' (on table A) 

 

The condition of the new Edit UI action will be: 

(new GlideRecord(current.getTableName())).canWrite() && RP.isRelatedList() && !RP.getListControl().isOmitEditButton()

And the script will look like this:

var uri = action.getGlideURI(); 

var path = uri.getFileFromPath(); 

uri.set('sysparm_m2m_ref', current.getTableName()); 

uri.set('sysparm_stack', 'no'); 

uri.set('sysparm_query', ''); 

  

uri.set('sysparm_collection_related_field', '[field on table B that references table C]'); 

uri.set('sysparm_collection_related_file', '[table C name]'); 

action.setRedirectURL(uri.toString('sys_m2m_template.do')); 

 

 

This way, when you click on Edit on the Related list for table B (from Table A form), table B will behave like a m2m table between A and C.

 

Please let me know if you have any comments,

 

David Neves

Comments
Daniel Baeta2
Kilo Explorer

Thank you very much for sharing.

Community Alums
Not applicable

Thank you

AbidM
ServiceNow Employee
ServiceNow Employee

This helped a lot, thanks a ton! 😃
Also, can you share if there is any reference to understand the parameters used here?

Version history
Last update:
‎03-08-2021 05:06 AM
Updated by: