The CreatorCon Call for Content is officially open! Get started here.

gs.getproperty not working

Venkat122
Kilo Guru

Hi All,

I am using script include in report for some complex query. To make this dynamic i am taking some values from sys_properties table using gs.getProperty() method. But when i use it in script include it is not working. same script is working when i checked by running in background. Is this an expected behavior? How we can overcome this problem?

script include:

name: getIncidents

client callable: true

script:

function getIncidents()

{

var arr = [];

var query = gs.getProperty('Custom.incident.query');

var gr = new GlideRecord('incident');

gr.addEncodedQuery(query.toString());

gr.query();

while(gr.next())

{

arr.push(gr.sys_id+'');

}

return arr.toString();

}

Form list view, i am calling it as

sys id --is one of-- javascript:getIncidents()

Build version: isthanbul

Thanks and regards

Swamy

21 REPLIES 21

khadija3
Tera Guru

Hello @Venkat

Once you check the script include as client callable and you call it from a filter it means that it will be executed on client side 

this is why gs.getProperty is not working and gs.log will not work also.

What you can do is a GlideRecord on sys properties tables to get your value

 

Regards

gs.getProperty() is faster than doing a query on sys_properties because the properties are cached for performance reasons.

But gs.getProperty is not working in this case there is no other solution

He also said gs.log() wasn't working which makes me think there is a broader issue happening here.

 

I made a few tweaks to his script and it works fine with the following setup. There were a couple things around the array management that could have been improved (notably getValue() and join())

find_real_file.png

find_real_file.png

 

function getIncidents() {

	var arr = [];
	var query = gs.getProperty('Custom.incident.query');

	var gr = new GlideRecord('incident');

	gr.addEncodedQuery(query);
	gr.query();
	gs.info(gr.getRowCount() + ' records found');

	while(gr.next()) {
		arr.push(gr.getValue('sys_id'));
	}

	return arr.join(',');
}

iwai
Giga Sage

Hello @Chuck Tomasi 

I tried several methods and found a successful alternative.
Alternative.
1. Execute the subflow by the system user.
2. Change the referenced value to user preference.

Cases of failure.
1. Refer to the system properties.
2. Use GlideRecord to refer to system properties.
3. Impersonate and refer to system properties.
Some users may not have read permission for these.
find_real_file.png

function TestQueryString() {
    // Subflow: gs.getProperty('glide.installation.name') by System user 
    var subflowOutput = sn_fd.FlowAPI.executeSubflow('global.Test_Simple_Subflow');

    var gr = new GlideRecord("sys_properties");
    gr.get("name", "glide.installation.name");

    var output = 'UserName ' + gs.getUserName() + ' >> Subflow ' + subflowOutput.output + ' >> getProperty ' + gs.getProperty('glide.installation.name') + ' >> GlideRecord ' + gr.getValue('value') + ' >> User Preference ' + gs.getUser().getPreference('sp.portal');

    //UserName itil >> Subflow Demo Server(system) >> getProperty undefined >> GlideRecord null >> User Preference sp
    return output;
}