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

Hi,

From where your script include is getting called?

 

from UI action

If these are standard change templates, fields are getting mandatory from client script 'Check Template Values'. Its onsubmit client script. Find a part of script which is making mandatory.

function isMandatoryFieldsSet(q) {
var unfilledValues = ' ';

var mandatory = sncStdChg.mandatory;

/*From Here add your customization.

if(location.href.toString.indexOf('value')>=0)

{

mandatory.push('Your field');

}* /


if (mandatory) {
for (var i = 0; i < mandatory.length; i++) {
var m = mandatory[i];
if (q) {
var idx = q.names.indexOf(m.name);
if (idx === -1 || q.vals[idx] === '')
unfilledValues = unfilledValues + m.label + ', ';
} else {
unfilledValues = unfilledValues + m.label + ', ';
}
}
}

No need to make changes to the script include.

Hi maheshn,

It doesnt seems to be working as it is custom table.

can you tell how to check url in script include?

 

Hi,

Are you determining fields to be set as mandatory from the script include?

Can you explain the process what you are doing?

top.location won't work in script include code

Regards
Ankur

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