Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Use getProperty in URL (from Arguments) not working

angel_jimenez
Mega Expert

Currently we have a module linking to our catalog home page, using URL (from arguments) type and the following argument code: catalog_home.do?sysparm_catalog=5a281eaa1b736740ba4eea0f6e4bcbb3

This is working fine, but I would like to replace the hardcoded sys_id in the URL and use getProperty function. With this purpose, I've first created a system property called default.catalog to store the catalog sys_id.

Then I've created a very simple script include:

find_real_file.png

Finally I've replaced module URL argument code: /catalog_home.do?sysparm_catalog=javascript:getDefaultCatalogID().getid()

But this is not working, as when I click on the module it takes me to following URL:

find_real_file.png

What I'm missing here? Any idea?

Thanks in advance!!

 

 

2 REPLIES 2

Harsh Vardhan
Giga Patron

create classes script include . 

 

sample steps :

url :

sys_user_list.do?sysparm_query=user_name=javascript:getDupUsers()


classless script include.


function getDupUsers() {
var usernames = [];
var grUser1 = new GlideRecord('sys_user');
grUser1.addActiveQuery();
grUser1.addNotNullQuery('user_name');
grUser1.query();
while (grUser1.next()) {
var username = grUser1.user_name.toString();
var grUser2 = new GlideRecord('sys_user');
grUser2.addActiveQuery();
grUser2.addNotNullQuery('user_name');
grUser2.addQuery('user_name', '=', grUser1.user_name);
grUser2.query();
var len = grUser2.getRowCount();
if (len > 1) {
usernames.push(username);
}
}
return usernames;
}


Note: same way you can design it for your requirement. hope sample code will help you. 

Hi Harshvardhan,

I've used your sample code to compose mine as follows:

function getDefaultCatalogID() {
var sys_id = gs.getProperty('default.catalog');
return sys_id;
}

Then call it from the URL Module argument field like this:

/catalog_home.do?sysparm_catalog=javascript:getDefaultCatalogID()

But it didn't work 😞