Client Script applying only on 2 views?

sarfraz3
Mega Expert

Hi,

I want to apply one of my client script only on two views-- default and text_search view.

For default i understand giving blank it works and for text search its name. But i have to do for both the views. Is there any way we can do that?

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Sarfraz,



Get the view name in the client script and execute your client script code based on the view on which you want it to run



var viewName = getView(); // returns the view name


// for default view this returns as empty


if(viewName == 'text_search' || viewName == '')


{



}


Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


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

Hi ankur,



i tried this, but since we are using onSubmit, if we change view then it is taking the new selected view.that is the error we are getting basically, while changing the view.


SO, my question is how can we give it by unchecking the global and defining view name in the client script


Mihir1
Tera Contributor

did you try creating a view rule?

Swapnil Soni1
Giga Guru

Hi Sarfraz,

 

Please check this link below

https://www.servicenowguru.com/scripting/client-scripts-scripting/change-form-view-client-script/

 

if this helps please mark correct or helpful.

Thanks

Swapnil