Get Instance URL via UI Builder

BriTaylor
Kilo Sage

Hello All,

 

I am trying to retrieve our instance URL in the UI Builder and am I have been unable to accomplish this.

 

The reason why I am trying to do this is we have a button on our workspace home page that links to our service portal, however this needs to be updated manually when we push any changes up through test then production. 

 

I have tried to do this via a script but the traditional methods that I know about have not worked.

 

Any suggestions would be greatly appreciated.

1 ACCEPTED SOLUTION

Hi @BriTaylor,

Go to table sys_ux_data_broker_transform, create a new one.

Add the below script.

function transform(input){return gs.getProperty('instance_name');}

Now come back to UI Builder, refresh the page. Now add the new data resource created and make sure you create the execute ACL for the data broker otherwise you'll get error for the same.

Now create a page script.. add the below script.

const instanceName = api.data.get_instance_name_1.output;//replace get_instance_name_1 with your data resource id.
console.log(instanceName);//output will be "devXXXXX" for PDIs

Now go to events section of the created data resource and click on Add event mapping & add the page script under Data fetch Succeeded event.

.Screenshot 2023-11-17 at 7.28.47 PM.png

 

 

View solution in original post

7 REPLIES 7

Hi @BriTaylor,

Go to table sys_ux_data_broker_transform, create a new one.

Add the below script.

function transform(input){return gs.getProperty('instance_name');}

Now come back to UI Builder, refresh the page. Now add the new data resource created and make sure you create the execute ACL for the data broker otherwise you'll get error for the same.

Now create a page script.. add the below script.

const instanceName = api.data.get_instance_name_1.output;//replace get_instance_name_1 with your data resource id.
console.log(instanceName);//output will be "devXXXXX" for PDIs

Now go to events section of the created data resource and click on Add event mapping & add the page script under Data fetch Succeeded event.

.Screenshot 2023-11-17 at 7.28.47 PM.png

 

 

Hasan6
ServiceNow Employee
ServiceNow Employee

Hi,

One solution will be, albeit I hope we can come up with a simpler one,
Create a data broker(sys_ux_data_broker_transform)

Add script:

function transform(input) {
	return (gs.getProperty('instance_name'));
}

Add an ACL with the sys_id for that databroker you just created, something like this:

Hasan6_0-1700227949970.png

 

Call this data broker in your ui builder.

 

Hope this helps.

Marc Mouries
ServiceNow Employee
ServiceNow Employee

FYI, in the Washington release, we now have an out of the box data resource "Look Up Properties"

 

MarcMouries_0-1727211388022.png