gs.getProperty + script include + navigator application Menu Module

poyntzj
Kilo Sage

The client has an application in the navigator to show their tickets.

One of these runs from a database view linking tasks to SLA's and so on.

I reworked it a little while ago to use a script include instead of a number of filters and it runs happily

For some new features, I need to be able to do a few more advanced queries based on a function which then determines what values i look for in a field and indeed what tables get queries.

So instead of having to rewrite this each time, i am a fan of trying to read data from a table or the sys properties so the code remains and the results can be extended or tweaked by adding / modifying data (and therefore no Change Requests)

so, my code is running fine when I run it as a backgroun script

gs.log(new myWorld().mine())

and in this case it is limited to returning me some CHG records

*** Script: myWorld mine : e89170136fe2ca40e87f715dbb3ee4c2 : true : true : it : IT : change_request

*** Script: CHG0036974,CHG0036908,

In the script, the user Id is obtained by gs.getUserID()

the groups are obtained by a gs.getUser().getMyGroups() call

and in the above I am using gs.getProperty to read some values from the sys_properties table

Now, if I run it from the navigator application module, it is not perform any ANY of the gs.getProperty calls

I can tell this as if I leave it to run, I see no records.

If I put some values in it then returns data

I also tried to query directly against the sys_properties table and it still seems to return no values

So why can it get the userId and groups, but not these properties ?

also I am struggling to do any debug on it as when it runs as a background script the gs.log line prints and adds to the script log, but when called from the app menu it does not.

any ideas anyone ?

1 ACCEPTED SOLUTION

poyntzj
Kilo Sage

In the end I have created a new table to do this


propertyname                   value



Running a gliderecord query against that works


no idea why gs.getProperty fails.


View solution in original post

9 REPLIES 9

Hi Julian,



Can you provide the (client-side) script you are using to call this SI?   My guess is once again that GlideSystem (gs) is not defined or available client-side, and you'd need to write it as an AJAX utility and call as such to get your value client-side using 'gs.getProperty(...)'.



However, since you're just looking for one value... you could use a client-side GlideRecord on the [sys_properties] table and use "gr.addQuery('name', 'instance_name');" to find your value.



e.g.,     Using a client GlideRecord in-place of a gs.getProperty() call:



var getPropertySI = Class.create();  


getPropertySI.prototype = {  


      doit: function() {  


var gr = new GlideRecord('sys_properties');


gr.addQuery('name', 'instance_name');


gr.query();


if(gr.next()){


              var strReturn = gr.value;  


return 'fred ' + strReturn;          


      },  


      type: 'getPropertySI'  


};  






Thanks,


-Brian


I know I tried looking at sys_properties before and it failed, but had another go this morning and for this it is working.


I had a look at the other script include - on of the versions and I can see that had the option of looking for a gs.getproperty and then reverting to sys_properties if it failed and that completely failed.


hey ho, this bit works now


Generally, when there's an error your code stops executing at that point... unless you've   somehow compensated with some error handling to tell it to continue.   When it hits the gs client-side it fails, and stops there even if the following code is valid.




-Brian


wiltonr
Giga Contributor

Julian,


Can you explain what you did to be able to get a property in a module filter?   I have the same issue (and it must have worked in the past).   We have several modules that are table list views that have a where Fiscal Year/Is/javascript:gs.getProperty('xxx.fiscal.year') and they all return undefined.   I just noticed them not working but I have to believe at some time in the past they did work (I did not create them but they've been there for some time).



I don't quite understand what you did when you say you created a new table to do this - propertyname     value.  



Thanks,


Rhonda


Hi Rhonda


What I did was to create a table (or as in my current client's scenario use a generic lookup table)


Add a key field or two and then a value field.


Instead of using a gs.getProperty you can query this table


If you are using a single field for the ID, you can use a


var grLUT = new GlideRecord('u_lookup_table');


grLUT.get('u_key_id',<some value>);


var myProperty = grLUT.u_value



if it is multiple fields for your lookup


var grLUT = new GlideRecord('u_lookup_table');


grLUT.addQuery('u_key_id',<some value>);


grLUT.addQuery('u_secondary_key_id',<some value>);


grLUT.query();


if(grLUT.next())


var myProperty = grLUT.u_value