Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Pass Data Variable from Server Script to HTML <a href="xxxx"> in Widget

Community Alums
Not applicable
Need Some Help:
I'm trying to pull a specific record that is on the User table and place it in a <a href="xxxx"> on the Service Portal.
 
Below is the code that I have already and where I'm looking to place it. Unfortunately, It's not populating anything.
 
• When I run the Server Script in the Background Scripts and print the record, it displays correctly.
 
• This leads me to believe that I don't have the correct code for the Binding Markup. 
 
Server Script:
function() {
	
data.ucsc = ucscLink;

//Get the UCSC URL
	
	var currentUser = gs.getUserID();

	var ucscGR = new GlideRecord('sys_user');
	ucscGR.addQuery('sys_id', currentUser);
    ucscGR.query();

    if (ucscGR.next()){
        
        var ucscLink = ucscGR.company.u_custom_field;
	
    } 
		

}



 

 

HTML:

<div>
<div class="dropdown" align="center">
    <button class="btn-lg btn-danger" type="button" data-toggle="dropdown"><i class="m-b fa fa-cogs fa-4x" style="color:white"></i><br><STRONG>CONTROL</STRONG>
 </button>
<ul class="dropdown-menu" align="center">
      <li><a href="#">Link 1</a></li>
    <li class="divider"></li>
    <li><a href="#">Link 2</a></li>
    <li><a href="{{data.ucsc}}">UC Self-Care</a></li>

  </ul>

  </div>

</div>

 

 
2 REPLIES 2

Stijn Verhulst1
ServiceNow Employee
ServiceNow Employee

Hi Jonathan,

what if you try the following?

function() {

    //Get the UCSC URL
    var currentUser = gs.getUserID();

    var ucscGR = new GlideRecord('sys_user');
    ucscGR.addQuery('sys_id', currentUser);
    ucscGR.query();

    if (ucscGR.next()){
        
        var ucscLink = ucscGR.company.u_custom_field;
	
    } 
		
    data.ucsc = ucscLink;

}

 

Then replace Link 1 in your HTML with data.ucscLink and wrapped in double curly brackets.

For some reason the syntaxt breaks here in the posts on the community...hence I mention the double curly brackets seperately.

Does it now display the link?

Warm regards,

Stijn

Where is data.ucsc in HTML ? We have to add it in curly brackets in HTML