Access property from client script

astickler
Kilo Explorer

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

1 ACCEPTED SOLUTION

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:


*


View solution in original post

19 REPLIES 19

joe_leser
Giga Contributor

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


Hi Joe - that function will not work in a client script.


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.


You then could work with an GlideAjax call:


http://wiki.servicenow.com/index.php?title=GlideAjax


randrews
Tera Guru

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        



    }



});