Dynamic URL in iframe

Bhavesh Bijagar
Tera Guru

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

 

2 REPLIES 2

Vasantharajan N
Giga Sage
Giga Sage

Please try the below simple code to build your dynamic URL from Server Side to replace it in iframe. 

VasantharajanN_0-1669980712020.png

 


Thanks & Regards,
Vasanth

jaheerhattiwale
Mega Sage

@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

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023