Can anyone explain about gs.getproperty() function?

Arsh1
Tera Contributor

So basically I have used gr.addEncodedQuery for getting the sys_id for a catalog item from sc_cat_item table.
GR.addEncodedQuery('cat_item=5ef6781b53131300afffddeeff7b1277');

Now there is an error from TPP instance certification test that says that you have to use gs.getproperty().

 

This is the error:

Avoid using hard-coded URLs in scripts. Instead, create a property and retrieve the value with gs.getProperty() as described <a title="" href="https://developer.servicenow.com/app.do#!/document/content/app_store_doc_technical_best_practices_ki... target="_blank" rel="noopener noreferrer nofollow.
 
If anyone can help it would be really appreciated.
 
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

That's correct it is not best practice to use hard-coded sys_id

1) Create system property of type string and store the sys_id

2) then use it in your script

GR.addEncodedQuery('cat_item=' + gs.getProperty('my_sysId'));

1) Visit sys_properties.list

2) then create new

3) give name

4) give value

Add a system property

find_real_file.png

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

That's correct it is not best practice to use hard-coded sys_id

1) Create system property of type string and store the sys_id

2) then use it in your script

GR.addEncodedQuery('cat_item=' + gs.getProperty('my_sysId'));

1) Visit sys_properties.list

2) then create new

3) give name

4) give value

Add a system property

find_real_file.png

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

aysheechatto
Tera Contributor

@Ankur Bawiskar I also have a similar requirement and trying with the below script:

var CenterCategoryIds = gs.getProperty("my.catalog.items");
var gp = new GlideRecord('sysapproval_approver');
//gp.addEncodedQuery('sysapproval=083619c787604690a29a2f0d8bbb35c9^u_approval_type=Line Manager^u_requested_items.cat_item=' + '87d0c77adb810898541a62eb0b961972');
gp.addEncodedQuery('sysapproval=083619c787604690a29a2f0d8bbb35c9^u_approval_type=Line Manager^u_requested_items.cat_item=' + CenterCategoryIds);
gp.query();

while (gp.next())
{
gs.print('HELLO WORLD');

}

 

However, the moment I replace the sys id with the system property, my script is failing.

Can you please help me on this.

 

Thank you,

Ayshee Chattopadhyay