- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2018 02:54 AM
Hi All,
On our change form we current have a related list for Change Requests.
This however creates a parent child relationship. On change team do not use parent and child change requests, but they still want the ability to add changes to a related list so you can link from one change to another. If a change is added to the related list it needs to be visible in both the change records related list (currently the child records only show in the parent records related list).
Do I just need to create a new M2M table between change requests and change request?
Thanks
Sam
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2018 04:19 AM
Hi Sam,
it is possible to link the same table to itself, you just need to add in two business rules to keep the records in sync (two records need to exist for each entry to enable users to see the many to many link from both records)
Here is an example of a Change M2M
- Navigate to sys_m2m.list and create a new table Many to Many table, referencing Change <> Change but do not save straight away. On creation
- From Table: Change Request
- To Table: Change Request
- Many to Many: creates u_m2m_change_reque_change_reque but rename
- M2M from field: change_request
- M2M from label: Change Requests
- M2M to field: change_request
- M2M to Label: Change Requests
- Then amend the Many to Many table name to less characters and more meaningful and easy to remember e.g.
- Many to Many: u_m2m_change_change
- M2M from field: change
- M2M from label: Change
- M2M to field: linked_change
- M2M to Label: Linked Change
Then Save Record / create new m2m table
- Navigate to new table u_m2m_change_change.do
- Both fields are named 'Change Request', so right hand click on Label and determine which is u_change and which is u_linked_change and amend labels accordingly
- Create a Business rule to insert a corresponding record e.g. When a Change is added to the Related List e.g. CHG0000020 is added to CHG0000004 a record is created Linked Change = CHG0000004 and Change = CHG0000020, this rule creates a corresponding record where Linked Change = CHG0000020 and Change = CHG0000004, to the Link can be viewed from either record
- Example:
- Name: Sync Linked Changes on Insert
- Active: true
- Advanced: true
- When to run:
- When: after
- Order: 100
- Insert: true
- Update: false
- Delete: false
- Query: false
- Actions:-
- None
- Advanced:
- Condition: none
- Script:
(function executeRule(current, previous /*null when async*/) {
InsertLinkedChg();
function InsertLinkedChg() {
//Check for an opposite corresponding record
var gr = new GlideRecord('u_m2m_change_change');
//Where Linked Change = Change
gr.addQuery('u_linked_change', current.u_change);
//Where Change Linked Change
gr.addQuery('u_change', current.u_linked_change);
gr.query();
if(!gr.next()){
//gs.log("Change is "+ current.u_change.getDisplayValue());
//gs.log("Linked is "+ current.u_linked_change.getDisplayValue());
//If no record is found, then create a new record
gr.initialize();
gr.u_linked_change = current.u_change;
gr.u_change = current.u_linked_change;
gr.insert();
}
}
})(current, previous);
- Create a Business rule to delete the corresponding record
- Example
- Name: Sync Linked Changes on Delete
- Active: true
- Advanced: true
- When to run:
- When: before
- Order: 100
- Insert: false
- Update: false
- Delete: true
- Query: false
- Actions:-
- None
- Advanced:
- Condition: none
- Script:
(function executeRule(current, previous /*null when async*/) {
DeleteLinkedChg();
//Delete the corresponding record for the 'Linked Change' where the link to the 'Change' has been removed or vice versa
function DeleteLinkedChg() {
//Check for the corresponding record which should already exist in the m2m table
var gr = new GlideRecord('u_m2m_change_change');
//Existing record Change = Linked Change Number e.g.CHG4
gr.addQuery('u_change', current.u_linked_change);
//Existing record Linked Change = Change Number e.g.CH20
gr.addQuery('u_linked_change', current.change);
gr.query();
if(gr.next()){
//Record found, REMOVE corresponding record from the M2M table
//gs.log("deletion for Linked " + linked + " & Change " + chg);
gr.deleteRecord();
//Record not found, do nothing
} else {
}
}
})(current, previous);
- On the Change form, add the related list 'Linked" and Configure List Layout adding the fields required
- Configure the List Control and add
- Label 'Linked Changes' and changed 'Omit new button' from false to true
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2018 03:19 AM
Hi All,
I have just realised that it is not possible to create a M2M table with the to and from tables being the same.
In order to achieve what we need what would I need to do?
As mentioned we need to be able to see the linked change from both sides
Thanks
Sam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2018 03:51 AM
Hopefully the below screenshots might help to show the issue easier:
CDLC0033451 & CDLC0033452, however we don't use a parent child hierarchy. We just want to link them for reference purposes fro example one change is done in UAT, then the other is a repeat but in Live.
As it creates it as a parent child relationship in CDLC0033451 we can see CDLC0033452. But in CDLC0033452 we cannot see CDLC0033451.
Like in a M2M relationship we want the ability to be able to see the link from either record.
How would we achieve this?
Thanks
Sam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2018 04:19 AM
Hi Sam,
it is possible to link the same table to itself, you just need to add in two business rules to keep the records in sync (two records need to exist for each entry to enable users to see the many to many link from both records)
Here is an example of a Change M2M
- Navigate to sys_m2m.list and create a new table Many to Many table, referencing Change <> Change but do not save straight away. On creation
- From Table: Change Request
- To Table: Change Request
- Many to Many: creates u_m2m_change_reque_change_reque but rename
- M2M from field: change_request
- M2M from label: Change Requests
- M2M to field: change_request
- M2M to Label: Change Requests
- Then amend the Many to Many table name to less characters and more meaningful and easy to remember e.g.
- Many to Many: u_m2m_change_change
- M2M from field: change
- M2M from label: Change
- M2M to field: linked_change
- M2M to Label: Linked Change
Then Save Record / create new m2m table
- Navigate to new table u_m2m_change_change.do
- Both fields are named 'Change Request', so right hand click on Label and determine which is u_change and which is u_linked_change and amend labels accordingly
- Create a Business rule to insert a corresponding record e.g. When a Change is added to the Related List e.g. CHG0000020 is added to CHG0000004 a record is created Linked Change = CHG0000004 and Change = CHG0000020, this rule creates a corresponding record where Linked Change = CHG0000020 and Change = CHG0000004, to the Link can be viewed from either record
- Example:
- Name: Sync Linked Changes on Insert
- Active: true
- Advanced: true
- When to run:
- When: after
- Order: 100
- Insert: true
- Update: false
- Delete: false
- Query: false
- Actions:-
- None
- Advanced:
- Condition: none
- Script:
(function executeRule(current, previous /*null when async*/) {
InsertLinkedChg();
function InsertLinkedChg() {
//Check for an opposite corresponding record
var gr = new GlideRecord('u_m2m_change_change');
//Where Linked Change = Change
gr.addQuery('u_linked_change', current.u_change);
//Where Change Linked Change
gr.addQuery('u_change', current.u_linked_change);
gr.query();
if(!gr.next()){
//gs.log("Change is "+ current.u_change.getDisplayValue());
//gs.log("Linked is "+ current.u_linked_change.getDisplayValue());
//If no record is found, then create a new record
gr.initialize();
gr.u_linked_change = current.u_change;
gr.u_change = current.u_linked_change;
gr.insert();
}
}
})(current, previous);
- Create a Business rule to delete the corresponding record
- Example
- Name: Sync Linked Changes on Delete
- Active: true
- Advanced: true
- When to run:
- When: before
- Order: 100
- Insert: false
- Update: false
- Delete: true
- Query: false
- Actions:-
- None
- Advanced:
- Condition: none
- Script:
(function executeRule(current, previous /*null when async*/) {
DeleteLinkedChg();
//Delete the corresponding record for the 'Linked Change' where the link to the 'Change' has been removed or vice versa
function DeleteLinkedChg() {
//Check for the corresponding record which should already exist in the m2m table
var gr = new GlideRecord('u_m2m_change_change');
//Existing record Change = Linked Change Number e.g.CHG4
gr.addQuery('u_change', current.u_linked_change);
//Existing record Linked Change = Change Number e.g.CH20
gr.addQuery('u_linked_change', current.change);
gr.query();
if(gr.next()){
//Record found, REMOVE corresponding record from the M2M table
//gs.log("deletion for Linked " + linked + " & Change " + chg);
gr.deleteRecord();
//Record not found, do nothing
} else {
}
}
})(current, previous);
- On the Change form, add the related list 'Linked" and Configure List Layout adding the fields required
- Configure the List Control and add
- Label 'Linked Changes' and changed 'Omit new button' from false to true
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2018 06:54 AM
Hi Gaynor,
Thanks for the above. Almost all of it is working as I would expect which is great.
The issue I have found is if I link 2 changes it creates the 2 records on the table u_m2m_change_change.
When I then remove the related change it only deletes one of the 2 related records in u_m2m_change_change. E.G
I've linked CDLC00334363 to CDLC0033462 by adding CDLC0033462 to the related list in record CDLC00334363:
I can see the link in both logs:
and I can see it has created 2 entries in the u_m2m_change_change table:
If I then remove the link by removing CDLC0033462 from the related list in record CDLC00334363:
It has not removed the reverse link - view from record CDLC0033462
It has only deleted 1 record from u_m2m_change_change
I'm guessing that something is missing in the second business rule, but not sure what amendment I need to make?
Thanks
Sam