We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Retrieve URL from user Session for creating user criteria

SKCH
Tera Contributor
Hi, I have a requirement to set up a user criteria that will work according to the user's URL, when there is a suffix that is in the URL then the criteria user will be activated, are there options to implement such a requirement through a user criteria?
Thanks

 

2 REPLIES 2

Ivan Betev
Mega Sage

Hi @SKCH ,

 

I presume you can try it like this...

/** Scripted User Criteria is not cached, and evaluated everytime, so performance is dependent on the script.
* Populate `answer` with true/false or evaluate to true/false
* The script is evaluated in the scope the user criteria is defined
* Don't use `current` in the script or populate the variable
* Don't use `gs.getUser()` or  `gs.getUserID()`, 
* instead use `user_id` which contains the user sys_id against whom the evaluation is happening.
*/

/* Call the function */
answer = checkCondition();

/* Declare the function that checks the divisional belonging */
function checkCondition(divisionId, userId) {
	var debug = true;
	var currentUrl = gs.getProperty("glide.servlet.uri") + gs.action.getGlideURI();
	var suffix = 'user_criteria_diagnostics';

	if (debug) { gs.info('DEBUG >>> User URL: {0}', currentUrl); }

	return currentUrl.indexOf(suffix) != -1;
}

 

Regards, Ivan

SKCH
Tera Contributor

Hi Ivan,

Thanks for you answer, but it didnt work.