Dynamic URL in iframe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2022 02:01 AM
I have to display an embeded application on employee center portal. Tyring to do this by using HTML widget, with below HTML code.
HTML Code:
<iframe width="760" height="315" src="https://YHESS_REIMBURSMENTS_SRNOW?userid=5798" frameborder="0" allowfullscreen></iframe>
This works fine when link is hardcoded.
However I want the SRC to take dynamic URL based on logged in user ids employee number and above link.
1. What script needs to be written on Server Side?
2. What script needs to be written on client side?
3. how to call that dynamic URL in HTML?
4. Is there any other way to embed an application on portal with dynamic URL?
Really appreciate your quick response on this.
I have looked for articles on community but couldn't find any.
#iframes
#html widgets
#employee center
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2022 03:31 AM
Please try the below simple code to build your dynamic URL from Server Side to replace it in iframe.
Thanks & Regards,
Vasanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2022 03:43 AM
@Bhavesh Bijagar Tried and tested solution. Please try below code
Server script:
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
data.url = "https://YHESS_REIMBURSMENTS_SRNOW?userid="+gs.getUserID();
})();
Client script:
api.controller=function($sce) {
/* widget controller */
var c = this;
c.getURL = function(){
return $sce.trustAsResourceUrl(c.data.url);
}
};
HTML:
<iframe width="760" height="315" ng-src="{{c.getURL()}}" frameborder="0" allowfullscreen></iframe>
Please mark as correct answer if this answers your question
ServiceNow Community Rising Star, Class of 2023