- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2023 08:50 PM
Hello All,
We have a requirement :
Requirement >> When a Ui action is clicked on sn_si_task (security task)it opens sn_ti_observable (observable table) table form in glide window , once the record is submitted that record is added to the related list sn_ti_m2m_task_observable (m2m related list) on sn_si_incident (security inicdent)table.
I have written a UI action glide window call, created a custom field on observable table to capture the sysid from sn_si_task table and a Script include to capture the sysid of new record and task record.
ISSUE : my logic of adding the record to related list is not working.
My code below :
UI action :
function openForm() {
var tableName = 'sn_ti_observable';
var sysID = -1;
var incSysid = g_form.getUniqueValue();
alert(incSysid);
//Create and open the dialog form
var dialog = new GlideDialogForm('Open Form', tableName, dothis); //Provide dialog title and table name
dialog.setSysID(sysID); //Pass in sys_id to edit existing record, -1 to create new record
dialog.addParm('sysparm_view', 'default'); //Specify a form view
dialog.addParm('sn_ti_observable', 'true'); //Add or remove related lists
dialog.setLoadCallback(function(iframeDoc) {
// To get the iframe: document.defaultView in non-IE, document.parentWindow in IE
var dialogFrame = 'defaultView' in iframeDoc ? iframeDoc.defaultView : iframeDoc.parentWindow;
dialogFrame.g_form.setValue('u_sit_id', incSysid); //custom field on observable table
dialogFrame = null;
});
dialog.render(); //Open the dialog
}
function dothis(action, sys_id, table, displayValue) {
//g_form.setValue('caller_id', sys_id);
var observeId = sys_id;
var incSysid2 = g_form.getUniqueValue();
var createRel = new GlideAjax('sn_si.Createrelationships');
createRel.addParam('sysparm_name', 'createRelObservables');
createRel.addParam('sysparm_secid', incSysid2);
createRel.addParam('sysparm_obsid', observeId);
createRel.getXML(callbackFunc);
function callbackFunc(response)
{
var ans = response.responseXML.documentElement.getAttribute("answer")
alert("answer is " + ans );
}
alert(observeId + " " + incSysid2);
// gs.getSession().putClientData('submittedid', observeId);
// gsftSubmit(null, g_form.getFormElement(), "open_form");
}
SCRIPT INCLUDE :
var Createrelationships = Class.create();
Createrelationships.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
createRelObservables: function(){
var secID = this.getParameter('sysparm_secid');
var obsid = this.getParameter('sysparm_obsid');
gs.info('ids are ' + secID + "::" + obsid);
//return secID;
var gr = new GlideRecord ("sn_ti_m2m_task_observable");
gr.initialize();
gr.observable=obsid;
gr.task=secID;
//gr.setValue("observable",obsid);
//gr.setValue("task",secID);
gr.insert();
return secID;
},
type: 'Createrelationships'
});
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 11:53 AM
you do not need a custom field on the new record form.
you would need to get parent record sys id and created record sys id.
get it through a callback function.:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2023 09:57 PM
Hi @Servicenow lear ,
The ID's which you are Getting in 'ids are' are valid?
Thanks and Regards,
Rahul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2023 05:15 AM
Yes.
I am logging those ids as well through UI action.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 11:53 AM
you do not need a custom field on the new record form.
you would need to get parent record sys id and created record sys id.
get it through a callback function.: