The CreatorCon Call for Content is officially open! Get started here.

Widget help - populate HTML from variable returned in Server Script

benrollins
Kilo Expert

I'm trying to provide a download link to a template file in the Service Portal, and would like to adjust the file the user receives without recoding the widget from time to time.

I have no problem with creating a "Download Template" link hardcoded to a particular attachment using the below Body HTML template in my widget:

    <div>
    <a target="_blank" href="/sys_attachment.do?sys_id=04135499dba82410ac588d6d1396198b">Download Template</a>
    </div>

I've created a system property with the sys_id of the attachment, and would like to use the Server script section of the widget to call this property, and then insert the value into the HTML.
I was thinking I could just define a variable in the server script, execute a line similar to: 

var attachment = gs.getProperty('config.attachment.sysid');

and then place the 'attachment' var into the HTML instead of the hardcoded sys_id.

I'm not certain how to accomplish this, hoping someone has done something similar to this and could give me a pointer.

1 ACCEPTED SOLUTION

Josh Virelli
Tera Guru

Hey Ben,

That's a great idea. So to make values available from the Server Script to the HTML or Client Controller we use the data object.

Server Script

data.attachmentLink = "/sys_attachment.do?sys_id=" + gs.getProperty('config.attachment.sysid');

And then to access it, we use the Angular version of the HTML attributes, i.e. ng-href instead of href. In there we can access the data object by using double-curly braces. You can put two colons before it to save on performance because we don't need to keep it bound to the Server Script.

HTML

  <div>
    <a target="_blank" ng-href="{{::data.attachmentLink}}">Download Template</a>
    </div>

 

If my answer helped you, or solved your question, please mark it as 'Helpful' or 'Correct'

Thanks,

Josh

View solution in original post

2 REPLIES 2

Josh Virelli
Tera Guru

Hey Ben,

That's a great idea. So to make values available from the Server Script to the HTML or Client Controller we use the data object.

Server Script

data.attachmentLink = "/sys_attachment.do?sys_id=" + gs.getProperty('config.attachment.sysid');

And then to access it, we use the Angular version of the HTML attributes, i.e. ng-href instead of href. In there we can access the data object by using double-curly braces. You can put two colons before it to save on performance because we don't need to keep it bound to the Server Script.

HTML

  <div>
    <a target="_blank" ng-href="{{::data.attachmentLink}}">Download Template</a>
    </div>

 

If my answer helped you, or solved your question, please mark it as 'Helpful' or 'Correct'

Thanks,

Josh

Thank you Josh, this worked perfectly!

I appreciate the help, I'm decent with javascript, but not so strong with html.