- 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 11:56 AM
HI Bernollis,
Update your UI action script to :
This wil show you logs message
Ui action :
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();
}
Script Inlcude :
var MyCustomUtils = Class.create();
MyCustomUtils.prototype = Object.extendsObject(AbstractAjaxProcessor,{
//---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
//Reset home coordinates
ResetHome : function() {
var ci = 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");
gr.get('sys_id', ci);
gr.u_home_lat = '';
gr.u_home_long = '';
gr.update();'
gs.log("BR: ResetHome has finished");'
},
//---------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------
type: 'MyCustomUtils'
});
Can you provide more details as in what you need to do with the Ui action s
Thanks,
CB

- 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:26 PM
Elijah you have a very good point, I just need it to clear some values and move on, I don't need to return anything for further processing.
Just for fun I tried adding ga.getXML() and it still wasn't executing the function in my script include.
I'll still need to figure out why that is at some point, as I need to get better at client callable scripts.
However your suggestion of just executing it as a server side function worked right away with no problems.
Thank you!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2020 12:29 PM
Glad it worked out for you!