How to create Copy Change button in Agent Workspace

Rekha Tiwari
Kilo Guru

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,

1 ACCEPTED SOLUTION

@Rekha Tiwari 

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

26 REPLIES 26

Hi,

did you add alert and check if workspace client script itself is showing alert or not?

If that works then your normal GlideAjax should work fine just like any onChange client script.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar 

Yes alert is coming n workspace-

 

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 (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();
}

});
}

 

but not giving the required result. Please help what is going wrong.

 

Thanks,

Hi,

I have already mentioned to only use GlideAjax so your script should look like this

no need of GlideURL

check if the script include function is creating the CHG or not

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 (queryParam) {

 

});
}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar 

Updated as but not working

 

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 (queryParam) {

 

//what should be here???

});
}

 

But what should be here where I have commented out as= //what should be here???

Hi,

nothing as the new CHG will be created inside that script include.

you can return that new CHG sys_id or number and show message to user or don't write anything there

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader