- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2020 11:52 AM
I'm having an issue with a UI Action which should call a function to make an update to the current record.
I'm obviously missing something. Appreciate another set of eyes to let me know where I'm going wrong:
UI Action is on an extended table of cmdb_ci, where I want to allow the user to reset two custom fields, containing Latitude and Longitude coordinates. Users should not be able to specify coordinates directly, only clear, so there is a UI Policy in place making the fields read-only.
I have checked the "client" box on the UI action, and confirmed that "Isolate script" is not checked.
Below is the client script, which I know at least starts due to the InfoMessage:
function Onclick() {
var ci = g_form.getUniqueValue();
g_form.addInfoMessage("CI sysID is " + ci);
var ga = new GlideAjax("MyCustomUtils");
ga.addParam("sysparm_name",'ResetHome');
ga.addParam("sysparm_ci", ci);
}
The script include and applicable function is below. I never see the log message so it doesn't seem like calling this function ever succeeds. I confirmed it is client callable. Any suggestions are extremely welcome.
var MyCustomUtils = Class.create();
MyCustomUtils.prototype = Object.extendsObject(AbstractAjaxProcessor,{
//---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
//Reset home coordinates
ResetHome : function(ci) {
gs.log("BR: ResetHome has started, variable passed is " + ci);
// Lookup CI and reset HOME coordinates
var gr = new GlideRecord("u_extended_cmdb_ci");
gr.get('sys_id', ci);
gr.u_home_lat = '';
gr.u_home_long = '';
gr.update();'
gs.log("BR: ResetHome has finished");'
},
//---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
type: 'MyCustomUtils'
});
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2020 11:59 AM
You're not executing the call. You need ga.getXML() still or some other method of calling.
Since you're not returning this it might be best to just use gsftSubmit and add an action name to your UI action.
//Client-side 'onclick' function
function runClientCode(){
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), '<button_action_name>'); //MUST call the 'Action name' set in this UI Action
}
//Ensure call to server-side function with no browser errors
if(typeof window == 'undefined')
runServerCode();
//Server-side function
function runBusRuleCode(){
new MyCustomUtils().ResetHome(current.sys_id)
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2020 12:06 PM
try this in client script
function Onclick() {
var ci = g_form.getUniqueValue();
g_form.addInfoMessage("CI sysID is " + ci);
var ga = new GlideAjax("MyCustomUtils");
ga.addParam("sysparm_name",'ResetHome');
ga.addParam("sysparm_ci", ci);
ga.getXML(myCallBack); //This is our callback function, which will process the response.
function myCallBack(response) {
// if you want to return data from script include, you will receive it here
// var data = response.responseXML.documentElement.getAttribute('answer'); ;
}
}
Script include
var MyCustomUtils = Class.create();
MyCustomUtils.prototype = Object.extendsObject(AbstractAjaxProcessor,{
//---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
//Reset home coordinates
ResetHome : function(ci) {
var ciData = this.getParameter('sysparm_ci');
gs.log("BR: ResetHome has started, variable passed is " + ci);
// Lookup CI and reset HOME coordinates
var gr = new GlideRecord("u_extended_cmdb_ci");
if(gr.get(ciData)){
gr.u_home_lat = '';
gr.u_home_long = '';
gr.update();'
gs.log("BR: ResetHome has finished");'
}
},
//---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
type: 'MyCustomUtils'
});
Muhammad