Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Hmm, But no luck still.

I am wondering what is going wrong-

Below is the client callable 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'
});

Hi,

you are using incorrect parameter name

it should be this -> sysparm_src_sysid

your script should look like this to create new CHG

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

}

Regards
Ankur

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

Hi @Ankur Bawiskar 

 

Yeah Make sense. Thanks

Now SI-

 

var CustomChangeUtils = Class.create();
CustomChangeUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getChangeDetails: function() {
gs.info("CheckingChnage");
var ChgSysID = this.getParameter("sysparm_src_sysid");

var gr = new GlideRecord("change_request");
gr.addQuery('sys_id', ChgSysID);
gr.query();
if (gr.next()) {
gs.info("CheckingChnage " + "1");
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();

}

},
type: 'CustomChangeUtils'
});

 

Bot logs are coming.

 

 

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

});
}

 

Still copy change record not generated when clicking on Copy Change button, nothing is happening,

Hi,

so did you check in backend table of change_request if new CHG got created or not

Regards
Ankur

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

Hi @Ankur Bawiskar 

Yes, I just checked. Change got created but it does not seem as Copy Change button performed any action.

Any suggestion for this please?