Adam,



Unfortunately this method will not work, because depending what column it is in will depict what table shows up, which means if the record is in both columns down the line they both show up still... I will have to revamp the whole structure and try to find a new way.



Thanks,



Nathan G


Nathan, do you recall what you ended up doing here?


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


View solution in original post

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);


Suhas Ram,



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