- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2024 06:09 PM - edited 09-05-2024 09:21 PM
-- Addendum--.
I would like to implement the Create Child incident feature in the context menu of the incident table in a custom table.
Below is a traced and created process associated with OOTB's Create Child incident. However, it does not work well.
--end of addendum--.
There is a table that extends the task table.
We would like to implement the CreateChildIncident function here, which is also found in the incident management.
I have mimicked the existing OOTB and changed the unique entries, but it does not work.
If anyone has any insight, I would appreciate it if you could tell me what it is.
●Client Script
function onLoad() {
NOW._createChildIncident = function(srcSysId){
var ga = new GlideAjax('ExtIncidentUtils2SNC');
ga.addParam('sysparm_name', 'getIncidentQueryParams');
ga.addParam('sysparm_src_sysid', srcSysId);
ga.addParam('sysparm_ui_action', "create_child_incident");
ga.setWantSessionMessages(true);
ga.getXMLAnswer(function(queryParam){
if (queryParam) {
var ck;
if (typeof g_ck != 'undefined' && g_ck != "")
ck = g_ck;
var gotoUrl = [];
gotoUrl.push('srcSysID=' + srcSysId);
gotoUrl.push('newSysID=$sys_id');
gotoUrl.push('sysparm_returned_action=$action');
if (ck)
gotoUrl.push('sysparm_ck=' + ck);
gotoUrl = 'CopyIncidentRelatedLists.do?' + gotoUrl.join('&');
var form = cel('form', document.body);
hide(form);
form.method = "POST";
form.action = "u_ext_task.do";
if (ck)
_addParam(form, 'sysparm_ck', g_ck);
_addParam(form, 'sys_id', '-1');
_addParam(form, 'sysparm_query', queryParam);
_addParam(form, 'sysparm_goto_url', gotoUrl);
form.submit();
}else{
g_form.addErrorMessage("Failed to create child incident");
}
});
};
function _addParam(form, name, val) {
var inp = cel('textarea', form);
inp.name = name;
inp.value = val;
}
}
Personally, I think the Client Script
I have a feeling that this part of the Client Script is wrong...
gotoUrl = 'CopyIncidentRelatedLists.do?' + gotoUrl.join('&');
●Script Include
var ExtIncidentUtils2SNC = Class.create();
ExtIncidentUtils2SNC.prototype = Object.extendsObject(ExtIncidentUtilsSNC, {
initialize: function(request, responseXML, gc) {
AbstractAjaxProcessor.prototype.initialize.call(this, request, responseXML, gc);
this.incidentUtils = new global.ExtIncidentUtilsSNC();
//this.log = new GSLog('com.snc.incident.copy.log', 'IncidentUtilsSNC');
},
ajaxFunction_getIncidentQueryParams: function() {
var srcSysId = this.getParameter('sysparm_src_sysid');
var uiActionType = this.getParameter('sysparm_ui_action');
var attributesList = this.incidentUtils._getAttributeList();
if (!attributesList)
return false;
var gr = new GlideRecord(this.incidentUtils.EXTINCIDENT);
if (gr.get(srcSysId))
return this.incidentUtils._getRecordValuesAsEncodedQuery(gr, attributesList, uiActionType);
else
this.log.logErr('Invalid source incident sysid provided = ' + srcSysId);
},
type: 'ExtIncidentUtils2SNC'
});
var ExtIncidentUtilsSNC = Class.create();
ExtIncidentUtilsSNC.prototype = {
EXTINCIDENT: 'u_ext_task',
ATTR_DOMAIN: 'sys_domain',
ATTR_PARENT_INCIDENT: 'u_parent_incident',
ATTR_WORK_NOTES: "work_notes",
ATTR_NUMBER: "number",
COPY_IF_ACTIVE_ATTRS: ['u_parent_incident'],
ALWAYS_IGNORE_ATTRS: ['active', 'additional_assignee_list', 'close_notes', 'closed_at', 'closed_by', 'knowledge', 'made_sla', 'number', 'opened_by', 'reassignment_count', 'sys_id', 'sys_domain', 'sys_mod_count', 'time_worked', 'watch_list', 'work_notes_list'],
PROP_INCIDENT_COPY_ATTRS: 'com.snc.extincident.copy.attributes',
INCIDENT_DEFAULT_ATTR_VALUE: 'assignment_group,business_service,category,caused_by,cmdb_ci,company,description,impact,location,parent_incident,problem_id,rfc,short_description,subcategory,urgency,priority,service_offering',
ACTION_TYPE: {
COPY_INCIDENT: "copy_incident",
CREATE_CHILD_INCIDENT: "create_child_incident"
},
initialize: function() {
this.arrayUtil = new ArrayUtil();
},
getCsvValue: function(val) {
val = val.trim().split(',');
for (var i = 0; i < val.length;) {
val[i] = val[i].trim();
if (!val[i]) {
val.splice(i, 1);
} else {
i++;
}
}
return val;
},
_getAttributeList: function() {
var fieldList = this._getCsvPropertyValue(this.PROP_INCIDENT_COPY_ATTRS, this.INCIDENT_DEFAULT_ATTR_VALUE);
return this.arrayUtil.diff(fieldList, this.ALWAYS_IGNORE_ATTRS);
},
_isCopyIncidentAction: function(action) {
return action == this.ACTION_TYPE.COPY_INCIDENT;
},
_isCreateChildIncidentAction: function(uiActionType) {
return uiActionType == this.ACTION_TYPE.CREATE_CHILD_INCIDENT;
},
_getRecordValuesAsEncodedQuery: function(record, attributesList, uiActionType) {
var table = record.getTableName();
var gr = new GlideRecord(table);
var activeAttrsToCopy = [];
for (var i = 0; i < attributesList.length; ++i) {
var name = attributesList[i];
if (record.isValidField(name)) {
if (record.getValue(name)) {
if (!gs.nil(record.getElement(name)) && !gs.nil(record.getElement(name).getED())) {
var ed = record.getElement(name).getED();
// We have to use the display value if it's a date based field for form filter
if (ed.getInternalType() == "glide_date_time" || ed.isEncrypted())
gr.addQuery(name, record.getDisplayValue(name));
else
gr.addQuery(name, record.getValue(name));
} else
gr.addQuery(name, record.getValue(name));
}
} else
this.log.logWarning("Invalid field '" + name + "' provided for table '" + table + "'.");
}
if (this._isCreateChildIncidentAction(uiActionType)) {
gr.addQuery(this.ATTR_PARENT_INCIDENT, record.getUniqueValue());
gr.addQuery(this.ATTR_DOMAIN, record.getValue(this.ATTR_DOMAIN));
}
return gr.getEncodedQuery();
},
_getCsvPropertyValue: function(ppty, defaultVal) {
var val = gs.getProperty(ppty, defaultVal);
return this.getCsvValue(val);
},
type: 'ExtIncidentUtilsSNC'
};
●System Proerty
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2024 12:10 PM
What is the purpose of making a child incident record from this custom table of yours? Is your requirements fulfilled by just making a regular incident against your custom records? How much information is coming from the custom record to the incident? It might make sense to strip out all of the OOB script functionality if you're simply creating a mostly-empty incident that is tied to your custom record. The OOB action contains checks and functions that may not apply at all to your specific needs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2024 07:05 PM
I appreciate your thoughtful follow up.
As you said, I should have considered the requirements and made a selection based on the requirements.
I apologize for not asking a coherent question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2024 02:22 AM
No problem! The community can be of much more help if your question is usually very specific. "My code is not working" is usually a slightly harder task to work on 😋.
Also, apologies if I'm making an incorrect assumption, but I may be able to help you out a little better if Japanese is your native language. If you'd like to message your question to me in Japanese, I'm pretty fluent and may be able to help you even for ServiceNow based questions 😊
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2024 10:10 PM - edited 09-09-2024 10:15 PM
How did you know I am Japanese?
I managed to solve (?) this case by implementing a process to create an empty child record in the UI Action. I am very grateful for your help.
I hope we will have a chance to meet again in this wide community.
I would like to express my deepest gratitude to Knaka for his kind consideration.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2024 09:22 PM
You are right, thanks for your comment, I will look into whether business rule or Flow designer can do the same.