- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2014 09:45 AM
Hello All,
I've been put to the task of trying to create a Many-to-many relationship on the Change Request table. We sort of have it working but not to our liking. We created another table to associate the changes with each other. but if you go on one change request and show the related list for the Change Request table it will show the related change requests like it should. However, you click on one of the related change requests to view it and it shows the relation on the other table we created not the Change Request table.
We want it to be consistent on one table not two. The attached link shows the related lists on two different Change Requests. Notice that the table names are different.
Any help would be appreciated.
Thanks,
Nathan G.
Solved! Go to Solution.
- Labels:
-
Change Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-07-2015 05:39 PM
Hello,
I ended up creating a list type field on the change table. From there I created a relationship(System Definition>Relationships) From the Change Req table to the Change Req table with the following query:
current.addQuery('sys_idIN' + parent.u_related_changes);
Then I overwrote the save and update functions for when they edited the list to query the change table and add the current change to the associated changes added or updated. as well as removed them with this code:
var gr = new GlideRecord('change_request');
gr.addQuery('sys_id','IN' , current.u_related_changes);
gr.query();
/*
gs.addInfoMessage('Current Sys ID: ' + current.sys_id);
gs.addInfoMessage('selected Sys ID: ' + current.u_related_changes);*/
while(gr.next()){
if(gr.u_related_changes == ''){
// gs.addInfoMessage('No Recored so the parent Child is entered1');
gr.u_related_changes = current.sys_id;
}else if(gr.u_related_changes.indexOf(current.sys_id) == -1){
// gs.addInfoMessage('No Recored so the parent Child is entered2');
gr.u_related_changes = gr.u_related_changes + ',' + current.sys_id;
}
gr.update();
}
action.setRedirectURL(current);
current.update();
Hope this helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-07-2015 11:17 AM
Nathan, do you recall what you ended up doing here?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-07-2015 05:39 PM
Hello,
I ended up creating a list type field on the change table. From there I created a relationship(System Definition>Relationships) From the Change Req table to the Change Req table with the following query:
current.addQuery('sys_idIN' + parent.u_related_changes);
Then I overwrote the save and update functions for when they edited the list to query the change table and add the current change to the associated changes added or updated. as well as removed them with this code:
var gr = new GlideRecord('change_request');
gr.addQuery('sys_id','IN' , current.u_related_changes);
gr.query();
/*
gs.addInfoMessage('Current Sys ID: ' + current.sys_id);
gs.addInfoMessage('selected Sys ID: ' + current.u_related_changes);*/
while(gr.next()){
if(gr.u_related_changes == ''){
// gs.addInfoMessage('No Recored so the parent Child is entered1');
gr.u_related_changes = current.sys_id;
}else if(gr.u_related_changes.indexOf(current.sys_id) == -1){
// gs.addInfoMessage('No Recored so the parent Child is entered2');
gr.u_related_changes = gr.u_related_changes + ',' + current.sys_id;
}
gr.update();
}
action.setRedirectURL(current);
current.update();
Hope this helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2017 10:02 PM
Hey Nathan, I have a similar requirement - to display a few field values from the related m2m table on one of the 2 m2m tables. Any idea on how to do that ? I have written this below BR on that m2m table and 'Incident' & 'Train Delay' are the 2 tables that are related via many to many.
This script isn't working....:(
(function executeRule(current, previous /*null when async*/) {
var gr1 = new GlideRecord('u_train_delay');
gr1.addQuery('sys_id',current.u_train_delay);
gr1.query();
if(gr1.next()) {
var inc = new GlideRecord('incident');
inc.addQuery('sys_id',current.u_incident);
inc.query();
if (inc.next()) {
//var state = current.state.getDisplayValue();
//var group = current.assignment_group.getDisplayValue();
gr1.u_incident_state = inc.state.getDisplayValue();
gr1.u_incident_assignment_group = inc.assignment_group.getDisplayValue();
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2017 07:35 AM
Sorry I haven't logged into the Community in a couple months. Your code looks like you need to add gr1.update(); on line 19. Let me know if you need any extra help.
~Nate
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-15-2020 06:11 AM
Your suggestion was very good, because it made me change from many to many to relationship one to many, meeting the client's need for the relationship between the same table.
However, a single problem that it does not give an alternative to the EDIT button to select more than one record to be linked to the one we are dealing with.