- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2021 04:09 AM
Hi All,
I need to have Copy Change button on Agent Workspace same as we have on native view. We have OOB "Copy Change" UI action.
I have checked "Workspace form button" checkbox. I can see Copy Change button on Agent Workspace but not performing any action. Please help me with this.
Thanks,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2021 02:51 AM
it got created from script only
then just show some alert to user with the CHG number
Client Script:
function onClick(g_form) {
//alert('1');
// GlideAjax here send the current CHG sys_id so that you can copy the fields to new CHG
var srcSysId = g_form.getUniqueValue();
var ga = new GlideAjax('CustomChangeUtils');
ga.addParam('sysparm_name', 'getChangeDetails');
ga.addParam('sysparm_src_sysid', srcSysId);
ga.getXMLAnswer(function(answer) {
alert(answer);
});
}
Script Include:
var ChgSysID = this.getParameter("sysparm_src_sysid");
var gr = new GlideRecord("change_request");
gr.addQuery('sys_id', ChgSysID);
gr.query();
if(gr.next()){
var gr1 = new GlideRecord('change_request');
gr1.initialize();
gr1.category = gr.category;
gr1.business_service = gr.business_service;
gr1.cmdb_ci = gr.cmdb_ci;
gr1.insert();
return 'CHG created ' + gr1.number;
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2021 04:48 AM
Hi
I have created custom SI-
var CustomChangeUtils = Class.create();
CustomChangeUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getChangeDetails: function() {
var userSysID = this.getParameter("sysparm_user_name");
var gr = new GlideRecord("change_request");
gr.initialize();
var result = this.newItem("result");
result.setAttribute("category", gr.category);
result.setAttribute("businessService", gr.business_service);
result.setAttribute("ci", gr.cmdb_ci);
gr.insert();
},
type: 'CustomChangeUtils'
});
Copy Change UI action- Workspace form button script-
function onClick(g_form) {
// GlideAjax here send the current CHG sys_id so that you can copy the fields to new CHG
var srcSysId = g_form.getUniqueValue();
var ga = new GlideAjax('CustomChangeUtils');
ga.addParam('sysparm_name', 'getChangeDetails');
ga.addParam('sysparm_src_sysid', srcSysId);
ga.getXMLAnswer(function (queryParam) {
if (queryParam) {
var gotoURL = new GlideURL('CopyChangeRelatedLists.do');
gotoURL.setEncode(false);
gotoURL.addToken();
gotoURL.addParam('srcSysID', srcSysId);
gotoURL.addParam('newSysID', '$sys_id');
gotoURL.addParam('sysparm_returned_action', '$action');
var form = cel('form', document.body);
hide(form);
form.method = "POST";
form.action = g_form.getTableName() + ".do";
if (typeof g_ck != 'undefined' && g_ck != "")
addParam(form, 'sysparm_ck', g_ck);
addParam(form, 'sys_id', '-1');
addParam(form, 'sysparm_query', queryParam);
addParam(form, 'sysparm_goto_url', gotoURL.getURL());
form.submit();
}
});
}
Still not working. Please help me where I am going wrong.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2021 05:10 AM
Hi,
is the ajax call happening?
why to keep this script?
var gotoURL = new GlideURL('CopyChangeRelatedLists.do');
gotoURL.setEncode(false);
gotoURL.addToken();
gotoURL.addParam('srcSysID', srcSysId);
gotoURL.addParam('newSysID', '$sys_id');
gotoURL.addParam('sysparm_returned_action', '$action');
Just use normal GlideAjax and send the current form sys_id using g_form.getUniqueValue()
then create a copy of the record
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2021 05:46 AM
Okay, Can you please help me with the exact script as I am new to workspace side script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2021 05:50 AM
Hi,
it's the normal GlideAjax syntax only which you can do in workspace client script
same as normal client script
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2021 07:44 AM
Hi
Yeah I have created as below-
SI-
var CustomChangeUtils = Class.create();
CustomChangeUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getChangeDetails: function() {
gs.info("CheckingChnage");
var userSysID = this.getParameter("sysparm_user_name");
var gr = new GlideRecord("change_request");
gr.initialize();
var result = this.newItem("result");
result.setAttribute("category", gr.category);
result.setAttribute("businessService", gr.business_service);
result.setAttribute("ci", gr.cmdb_ci);
gr.insert();
},
type: 'CustomChangeUtils'
});
Client script-
function onClick(g_form) {
// GlideAjax here send the current CHG sys_id so that you can copy the fields to new CHG
var srcSysId = g_form.getUniqueValue();
var ga = new GlideAjax('CustomChangeUtils');
ga.addParam('sysparm_name', 'getChangeDetails');
ga.addParam('sysparm_src_sysid', srcSysId);
ga.addParam('sysparm_user_name', g_form.getValue("caller_id"));
ga.getXML(getDetails);
function getDetails(response) {
var result = response.responseXML.getElementsByTagName("result");
g_form.setValue('category', result[0].getAttribute('category'));
g_form.setValue('business_service',result[0].getAttribute('businessService'));
g_form.setValue('cmdb_ci',result[0].getAttribute('ci'));
}
}
I have tested, Glideajax is getting called but Copy Change button still not performing anything. PLease guide me.