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.

AngularJS on a UI Page - How to simply get the current "sysparm" of URL?

MG Casey
Mega Sage

I feel a bit lost when trying to solve a specific problem on a UI Page where there might be a "sysparm_recordid" parameter in the URL.

I've tried all sorts of variations, but no luck getting the value of my URL parameter into my scope.

var myApp = angular.module('voicemailSupport', []);
myApp.controller('voicemailData', function($scope, $location, $window, $timeout, $interval, $document) {

   $scope.recordID = $location.search().sysparm_recordid;

});

I don't need to do any updating of the URL - just want to grab the value of the parameter of the page that was loaded.

1 ACCEPTED SOLUTION

 

I think I have it figured it out after reading through your reply and some more examples out there:

 

var myApp = angular.module('voicemailSupport', [], function($locationProvider) {
	$locationProvider.html5Mode(true);
});

myApp.controller('voicemailData', function($scope, $location) {

   $scope.recordID = $location.search().sysparm_recordid;

});

 

This seems to work in all browsers I test, plus I don't have to utilize Jelly.

View solution in original post

6 REPLIES 6

Bryan Tay3
Mega Guru

hi there, 

you mentioned ui page and i presume u wanted to get the url params within "Processing Script" section?

have you try 

GlideSession

https://developer.servicenow.com/app.do#!/api_doc?v=kingston&id=c_GlideSessionScopedAPI

E.g.

var session = gs.getSession();
session.putClientData('test1', 'Harry');
var clientData = session.getClientData('test1');
gs.info(clientData);

Hope this helps.

I actually want to be able to use the URL parameters within the AngularJS code of the client script section, so I won't be using the UI Processing section.

hi there, 

have u try following object in client script? It contain the entire URL (including params).

window.parent.location.href

I just did a try with existing $pwd_change ui page by inserting the following at the 1st line in client script:

alert('Here = '+window.parent.location.href);

find_real_file.png

Hope this helps.

 

Getting the URL is not a problem (with $window.location in AngularJS) - I just can't seem to find a consistent way to parse out a specific parameter from the URL.