avoid hardcoded instance name in the UI action

MR1
Tera Contributor

Hi,

I created a UI action and it's calling the instance name in the url. Since name of the instance is hardcoded. It is working as expected.

We need generic UI action so that no need to update the instance name when UI action is moved to different instance

var url = 'https://"instancename".service-now.com/"tableName"_list.do?sysparm_query=id%3D' + current.user_id.toString() ;

Thanks

1 ACCEPTED SOLUTION

shloke04
Kilo Patron

Hi,

You just need to update your URL as below:

var url = '/tableName_list.do?sysparm_query=id%3D' + current.user_id.toString();

This will automatically take the instance name dynamically, let me know if you have a query here.

I just tested it in my PDI and it works fine. Make sure to include the below line as well:

var url = '/tableName_list.do?sysparm_query=id%3D' + current.user_id.toString();
action.setRedirectURL(url);

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

4 REPLIES 4

bammar
Kilo Sage
Kilo Sage

There is a property in every instance with the name:make a variable that grabs this- gs.getProperty('instance_name');

More details here

https://servicenowguru.com/scripting/business-rules-scripting/finding-instance-name-via-script/

 

This also works in many areas like when creating  URL in notifications and will save you time when you clone down and links dont work in test- using this method to build urls is the best

MR1
Tera Contributor

Thank for reaching out.

I was aware of that property however I wasn't able to bring it on UI action

FYI - that property is missing from our instance

If you are referring to 'gs.getProperty('glide.servlet.uri');'
Then it is available in your instance for server side scripts, even if not visible as a system property.

You can access this property client side via an ajax call, an example from Harshvardhan
https://community.servicenow.com/community?id=community_question&sys_id=ae72fed5dbfb88d41cd8a345ca9619d1

Or this may be another option, from Jace Benson
https://community.servicenow.com/community?id=community_question&sys_id=0276cfe1db1cdbc01dcaf3231f9619fd

shloke04
Kilo Patron

Hi,

You just need to update your URL as below:

var url = '/tableName_list.do?sysparm_query=id%3D' + current.user_id.toString();

This will automatically take the instance name dynamically, let me know if you have a query here.

I just tested it in my PDI and it works fine. Make sure to include the below line as well:

var url = '/tableName_list.do?sysparm_query=id%3D' + current.user_id.toString();
action.setRedirectURL(url);

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke