- 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2015 05:46 PM
I forgot I added this onChange client script to remove the change from other if it was removed from the list field:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
var old = oldValue;
var val = newValue;
var seperate = old.split(',');
var filterString = '';
for(var i = 0; i < seperate.length; i++){
if(val.indexOf(seperate[i]) == -1){
if(filterString == '')
filterString = filterString + seperate[i];
else
filterString = filterString + ',' + seperate[i];
//alert('this was removed: ' + seperate[i]);
}
}
//alert(filterString);
if(filterString != ''){
var ga = new GlideAjax('RemoveChangeM2M');
ga.addParam('sysparm_name','removeChangeM2M');
ga.addParam('sysparm_filter',filterString);
ga.addParam('sysparm_number',g_form.getValue('number'));
ga.getXML(HelloWorldParse);
}
alert('Be sure to always save or update after changing this field');
}
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
// alert(answer);
}
and it references this script include:
var RemoveChangeM2M = Class.create();
RemoveChangeM2M.prototype = Object.extendsObject(AbstractAjaxProcessor, {
removeChangeM2M: function() {
var filterString = this.getParameter('sysparm_filter');
var number = this.getParameter('sysparm_number');
var test = '';
var test2 = '';
var hold = '';
try{
var record = new GlideRecord('change_request');
record.addQuery('number', number);
record.query();
if(record.next())
test = record.sys_id;
var gr = new GlideRecord('change_request');
gr.addQuery('sys_idIN' + filterString);
gr.query();
while(gr.next()){
hold = gr.u_related_changes;
if(hold.indexOf(','+test) != -1){
gr.u_related_changes = hold.replace(','+test, "");
hold = hold.replace(','+test, "");
test2 = 'with comma';
}else if(hold.indexOf(test) != -1){
gr.u_related_changes = hold.replace(test, "");
test2 = 'no comma';
}
gr.update();
}
}catch(e){}
return test2;
},
_privateFunction: function() { // this function is not client callable
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2017 11:52 PM
Hi Nathan,
did you manage to add the Edit Button in a customized relationship?
Thanks