I want to create a CreateChildIncident function in a custom table.

honamiUeo
Tera Contributor

-- Addendum--.
I would like to implement the Create Child incident feature in the context menu of the incident table in a custom table.

honamiUeo_0-1725596435930.png

 


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

honamiUeo_0-1725584935705.png

 

1 ACCEPTED SOLUTION

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.

View solution in original post

8 REPLIES 8

SanjivMeher
Kilo Patron
Kilo Patron

What you are doing here doesn't make sense to me?

At what condition, you want the child incident to be created. Why not use business rule or Flow designer for this?


Please mark this response as correct or helpful if it assisted you with your question.

I agree with Sanjiv on needing more information on what you're trying to do. The community may have a completely different response based on what you're trying to do if you describe what you are trying to accomplish in more detail.

honamiUeo
Tera Contributor

@Knaka 

Thank you for your comment. We apologize for the unkindness of the post, as you indicated.
I have edited and added the question. If you have any ideas, I would be happy to comment again.

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.