How to pass URL parameters in Service Portal

spinol611
Giga Contributor

Currently I have a widget that pulls data from an alerts table. When the user clicks on the window, they should be linked to the related record and view more information about the alert. Currently, I grab the record's sys_id with "task.sys_id". How can I pass this value into the HTML template or how can I do this via the Client?

Thanks!

1 REPLY 1

Manville
Mega Guru

Hello Stephen,



Not sure if you have already solved this, but here is how I would do it.



1. I would make the URL on the serverside script of the widget and pass it into the data object.


data.url="hello.service-now.com";//or whatever code you use to create the URL


data.recordnumber="inc100000";


data is a JSON object. So by declaring the data.url="hello.service-now.com", data gains that attribute. ServiceNow automatically passes the data object to the client side script where you can use it.



2. Access the   URL the data object which was passed to the Client side


function(){


        var c = this;


}



3. Embed the data in the html


<a href="{{c.data.url}}">{{c.data.recordnumber}}</a>




If you need to pass more than one link, you could add an array to data since its just a JSON object.



If you want to dynamically name the properties:


data[gr.number]=gr.getLink();



If you want to add an array:


while(gr.next()){


        data["urls"].push({gr.number:gr.getLink()});


}




Here is the server script documentation for widgets
Here is the client script documentation for widgets


Here is the html documentation for widgets