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.

How to use window.location.href.contains() in script include?

Thousif S N2
Tera Contributor

I need to push field as mandatory based on the ui view . So i want to make the validation based on URL using  window.location.href.contains(). So if the url belongs to second UI page then make field as mandatory? But i am trying its not working ! so can any expert help

Thanks in advance

1 ACCEPTED SOLUTION

@Thousif S N 

Would you mind marking my response as correct & helpful if I am able to resolve your query?

Regards
Ankur

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

26 REPLIES 26

Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi,
Can you try below code to fetch it. I am just pasting one example.

var gUrl = new GlideURL();
gUrl.setFromCurrent();
var comments = gUrl.getParam("sysparm_comments");

OR

https://www.servicenowguru.com/scripting/client-scripts-scripting/parse-url-parameters-client-script...

Thanks,
Ashutosh

should i use this code in BR?CS?SI?

HI,

Client script.


Thanks,
Ashutosh

Gowrisankar Sat
Tera Guru

Can you try this as well:

 

if (window.location.href.indexOf("franky") > -1) {
      alert("your url contains the name franky");
    }