- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2014 02:38 AM
I have a client-side UI Action for the Configuration Item table that adds a button to the form header and a context menu item to the list. The script needs to access one of my application's properties but I cannot work out how to do this.
I have tried:
var gr = new GlideRecord('sys_properties');
gr1.get("name", "myCat.myProp");
but this returns 'undefined'.
I have created a Business Rule (also for Configuration Item) that pushes the property into g_scratchpad, and while this works when I click the form header button, the script debugger reports g_scratchpad as undefined when I use the list context menu (presumably because the Business Rule has not executed). I have tried setting the rule to execute 'before', 'after' and 'display' with no change.
Is there any better way for me to get the property?
Thanks,
Andrew
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2014 07:03 AM
Best would be to get both values with one AJAX call.
Here is an example how to transport multiple values from server to client using JSON:
/* How to return multiple values via XML:
*
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2014 01:23 PM
There is a much more convenient function available within GlideSystem to acquire a system property: gs.getProperty()
More specific information can be found on the Wiki at: http://wiki.servicenow.com/index.php?title=GlideSystem#getProperty.28String.2C_Object.29
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2014 08:19 AM
Hi Joe - that function will not work in a client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2014 09:37 AM
Yes, you are correct. GlideSystem is only available within server-side code. I was pointing that function out as an easier method of retrieving system properties. You would use the getProperty() function instead of constructing the GlideRecord lookup.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2014 06:46 AM
You then could work with an GlideAjax call:
http://wiki.servicenow.com/index.php?title=GlideAjax
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2015 05:48 AM
For those that need the code.. i had to create an ajax for this... from the client side call this function
function getURL(){
//alert('Calling the ajax');
var ajax = new GlideAjax('cs_getProperty');
ajax.addParam('sysparm_name','cs_getProperty');
ajax.addParam('sysparm_name_in',"fa.ra.add2kb_url");
ajax.getXMLWait();
var answer = ajax.getAnswer();
//alert('got an answer of ' + answer);
//alert(answer);
return answer;
}
_________________________________now create a script include named cs_getProperty make sure you check client callable--------------------
var cs_getProperty= Class.create();
cs_getProperty.prototype = Object.extendsObject(AbstractAjaxProcessor, {
cs_getProperty: function() {
//gs.log('cs_getProperty: in the get property script include');
var prop_name = this.getParameter('sysparm_name_in');
answer = gs.getProperty(prop_name);
//gs.log('cs_getProperty: retrieved prop_name of ' + prop_name);
//gs.log('cs_getProperty script answer is ' + answer);
gs.log('sc_getProoperty: input name is ' + prop_name + ' retrieved value of ' + answer);
return answer;
},
_privateFunction: function() { // this function is not client callable
}
});