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

Michael Jones -
Giga Sage

You can achieve this by combining both your client side code inside the UI action. 

This article has a good example: https://www.servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/

First you call your client-side validation and then pass to server side to execute. 

Hope this helps.

If this was helpful or correct, please be kind and click appropriately!

Michael Jones - Proud member of the CloudPires Team!

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

please use this and check in onload client script

function onLoad(){

// give here the value to search

if(top.location.href.indexOf('value to search') >= 0){

g_form.setMandatory('field', true); // give here the field name

}

}

Regards
Ankur

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

Thanks its working on client ....

 

Will it work in script include?

Hi,

If you require in script include then this should give you the URL in server side

I won't recommend this if something you can achieve just using client script.

var url = gs.action.getGlideURI().toString();

Regards
Ankur

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

Hi,

 

we have alreday a script include from where we are making a field as mandatory  .. so now i want push that based on the ui page