The Zurich release has arrived! Interested in new features and functionalities? Click here for more

ng-click scoped function passing value

xiaix
Tera Guru

Well this seems a bit odd...

HTML Template (the important info)

<tr ng-repeat="emergency in data.emergencies" id="{{::emergency.locationSysID}}">

      <td ng-if="::data.userLocation == emergency.locationSysID">

              <a ng-click="openSiteInfo('{{::data.userLocation}}', '{{emergency.locationSysID}}')">Test Link</a>

      </td>

</tr>

Client Script (the important info)

function($scope)

{

      $scope.openSiteInfo = function(val, userLocationSysID)

      {

              console.debug("val: " + val);

              console.debug("userLocationSysID: " + userLocationSysID);

      };

}

The debug log:

find_real_file.png

The inspected element:

find_real_file.png

So what am I missing that the passed values show up perfectly when I inspect the page, but the values debugged are string literals??

1 ACCEPTED SOLUTION

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi David,



You should just write those as JS like:



ng-click="openSiteInfo(data.userLocation, emergency.locationSysID)"


View solution in original post

6 REPLIES 6

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi David,



You should just write those as JS like:



ng-click="openSiteInfo(data.userLocation, emergency.locationSysID)"


find_real_file.png



Getting correct values now, but also get this error


Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi David,



Could you post the full html, client script and server portion so we can debug?


Sure thing, thanks for asking:



HTML Template:


<div ng-if="::data.bcpEmergency">


  <table id="bcp_news_gadget" cellspacing="0" cellpadding="0" align="center" style="border: none; width: 700px; padding-bottom: 10px;">


      <tr>


          <td class="emergencyBorder" colspan="2" style="text-align:center; color:white; float:center;   width:700px; ">


              <span>


                  <strong>* Site Emergency Information *</strong>


              </span>


          </td>


      </tr>


      <tr ng-repeat="emergency in data.emergencies" id="{{::emergency.locationSysID}}">


          <td>


              <table style="margin: auto;">


                  <tr class="locationsBorder">


                      <td ng-if="::data.userLocation != emergency.locationSysID">


                          [{{::emergency.location}}]


                      </td>


                      <td ng-if="::data.userLocation == emergency.locationSysID">


                          <a ng-click="openSiteInfo(data.userLocation, emergency.locationSysID)">[{{::emergency.location}}]</a>


                      </td>


                      <td ng-if="::emergency.checkinRequired == '1'">


                          <button ng-if="::data.userLocation == emergency.locationSysID">


                              Check In


                          </button>


                      </td>


                      <td style="width:70%; text-align:justify;padding-left:5px;">


                          {{::emergency.alertMessage}}


                      </td>


                  </tr>


              </table>


          </td>


  </table>


</div>



Client Script:


function($scope)


{


      $scope.openSiteInfo = function(val, userLocationSysID)


      {


              console.debug("val: " + val);


              console.debug("userLocationSysID: " + userLocationSysID);


             


              if (val != userLocationSysID)


              {


                      alert("You can only view BCP information for your own site.");


              }


              else


              {


                      var URL = data.Instance_URL;


                      window.location.assign(URL + "checkin");


              }


      };


}



Server Script:


(function() {




      var userID = gs.getUserID();


      var userLocation = gs.getUser().getLocation();


      var Instance_URL = gs.getProperty('glide.servlet.uri');


     


      data.bcpEmergency = false;


      data.emergencies = [];


      data.userLocation = userLocation;


      data.userID = userID;


      data.Instance_URL = Instance_URL;




      var bcp = new GlideRecord('u_bcp_site_emergencies');


      bcp.addNotNullQuery('u_alert_message');


      bcp.addQuery('u_active', true);


      bcp.query();




      while (bcp.next())


      {


              data.bcpEmergency = true;


             


              var listData = {};


              listData.location = bcp.getDisplayValue('u_location').toString().trim();


              listData.locationSysID = bcp.getValue('u_location').toString().trim();


              listData.checkinRequired = bcp.getValue('u_employee_checkin_required').toString().toLowerCase();


              listData.alertMessage = bcp.getValue('u_alert_message').toString().trim();


             


              data.emergencies.push(listData);


      }


})();