Ui action for problem form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2022 10:37 PM
We have a requirement that, we need to add one Ui action to the related list of outages in problem form.
When we clicked on that button, it should open a list view of outages.
Can any one help me with the script.
Any help will be appreciated.
Thank you,
Shiva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2022 06:26 AM
Hello
Can you please tell me what should i do exactly. To solve the issue.
I am not getting what should i do to resolve this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2022 06:41 AM
Hello
This is what i have done till now. working as expected. but one thing is missing is when we selected any record from outages and clicked on the add selected button the outage is not adding into related list.
How could i do that?
Ui action script :
function openOutageList(){
var gajax = new GlideAjax("BulkAddOutages");
gajax.addParam("sysparm_name","getURL");
gajax.addParam("sysparm_sys_id", g_form.getUniqueValue());
gajax.addParam("sysparm_parent_table", g_form.getTableName());
gajax.getXMLAnswer(openListModalIncident);
}
function openListModalOutage(url){
//render the modal
var incModal = new GlideModal('incident_add_records');
incModal.setTitle(getMessage("Add Outages"));
incModal.setWidth(1200);
incModal.setAutoFullHeight(true);
incModal.on('beforeclose', function(){
refreshRelatedIncidents();
});
ScriptLoader.getScripts('/scripts/incident/glide_modal_accessibility.js', function() {
incModal.template = glideModalTemplate;
incModal.renderIframe(url, function(event) {
glideModalKeyDownHandler(event, incModal.getID());
});
});
var link = document.createElement('link');
link.rel = 'stylesheet';
link.href = 'styles/incident_glide_modal.css';
document.head.appendChild(link);
}
function refreshRelatedIncidents() {
GlideList2.get(g_form.getTableName() + '.' + g_list.getRelated()).setFilterAndRefresh('');
}
Script include script :
var BulkAddOutages = Class.create();
BulkAddOutages.prototype = Object.extendsObject(AbstractAjaxProcessor, {
PARAMS: {
SYSID: "sysparm_sys_id",
PARENTTABLE: "sysparm_parent_table",
TABLE: "sysparm_table",
VIEW: "sysparm_view",
NOSTACK: "sysparm_nostack",
QUERY: "sysparm_query",
PARENTCOLUMN: "sysparm_parent_column",
FIXEDQUERY: "sysparm_fixed_query",
JS: "sysparm_js",
JSTYPE: "sysparm_js_type",
SELECTEDTASKS: "sysparm_selected_tasks",
TYPE: "sysparm_type"
},
CONSTANTS: {
TASK_TABLE: "task",
CLASS_NAME: "sys_class_name"
},
getFixedQuery: function(parentTable, parentColumn) {
var eps = new GlideScriptedExtensionPoint().getExtensions("BulkAddOutagesFilter");
for (var i = 0; i < eps.length; i++) {
var query = eps[i].getFixedQuery(parentTable, parentColumn);
if (typeof query === "undefined")
continue;
return query;
}
return "active=true^" + parentColumn + "ISEMPTY";
},
canRelateIncidents: function(parentTable, relatedRecordGr, parentColumn) {
var eps = new GlideScriptedExtensionPoint().getExtensions("BulkAddOutagesFilter");
for (var i = 0; i < eps.length; i++) {
var check = eps[i].canRelateIncidents(parentTable, relatedRecordGr, parentColumn);
if (typeof check === "undefined")
continue;
return check;
}
return (relatedRecordGr.canWrite() && relatedRecordGr.getElement(parentColumn).canWrite());
},
getURL: function() {
var sysId = this.getParameter(this.PARAMS.SYSID);
var pTable = this.getParameter(this.PARAMS.PARENTTABLE);
var url = new GlideURL("incident_add_records.do");
var parentColumn = gs.getProperty('com.snc.incident.link_to_task.' + pTable);
var fixedQuery = this.getFixedQuery(pTable, parentColumn);
url.set(this.PARAMS.SYSID, sysId);
url.set(this.PARAMS.VIEW, "default");
url.set(this.PARAMS.NOSTACK, "true");
url.set(this.PARAMS.QUERY, "ORDERBYDESCsys_created_on");
url.set(this.PARAMS.TABLE, "cmdb_ci_outage");
url.set(this.PARAMS.PARENTCOLUMN, parentColumn);
url.set(this.PARAMS.FIXEDQUERY, fixedQuery);
url.set(this.PARAMS.JS, "incident_link_task.js");
url.set(this.PARAMS.JSTYPE, "file_system");
return url;
},
linkTasks: function() {
var taskSysId = this.getParameter(this.PARAMS.SYSID);
var table = this.getParameter(this.PARAMS.TABLE);
var selectedRecords = this.getParameter(this.PARAMS.SELECTEDTASKS);
gs.addInfoMessage("selectedRecords=" + selectedRecords);
var query = this.getParameter(this.PARAMS.QUERY);
gs.addInfoMessage("query=" + query);
var parentColumn = this.getParameter(this.PARAMS.PARENTCOLUMN);
gs.addInfoMessage("parentColumn=" + parentColumn);
var type = this.getParameter(this.PARAMS.TYPE);
gs.addInfoMessage("type=" + type);
if (!taskSysId) {
gs.error("[BulkAddOutages] Invalid Parameter - sysparm_sys_id is empty or null");
return;
}
if (!table) {
gs.error("[BulkAddOutages] Invalid Parameter - sysparm_table is empty or null");
return;
}
if (!parentColumn) {
gs.error("[BulkAddOutages] Invalid Parameter - sysparm_parent_column is empty or null");
return;
}
var grTask = new GlideRecord(this.CONSTANTS.TASK_TABLE);
if (!grTask.get(taskSysId))
return;
var pTable = grTask.getValue(this.CONSTANTS.CLASS_NAME);
var relatedRecordGr = new GlideRecord('cmdb_ci_outage');
if (relatedRecordGr.isValid()) {
relatedRecordGr.addQuery(parentColumn, 'null');
// if (type == 'add_selected')
relatedRecordGr.addQuery('sys_id', 'IN', selectedRecords);
// else
// relatedRecordGr.addEncodedQuery(query);
relatedRecordGr.query();
while (relatedRecordGr.next()) {
if (this.canRelateIncidents(pTable, relatedRecordGr, parentColumn)) {
gs.info("parentColumn=" + parentColumn + " taskSysId= " + taskSysId);
relatedRecordGr.setValue(parentColumn, taskSysId);
relatedRecordGr.update();
}
}
}
return;
},
canShowAddButton: function(parent, current) {
var field = gs.getProperty('com.snc.outage.link_to_task.problem' + parent.sys_class_name);
return parent.active == true && current.isValidField(field);
},
type: 'BulkAddOutages'
});