How to get the view name of the form by using script

mdsannavulla
Kilo Guru

Hi All,

For change table we are having two different views.So I want to get the view name by using script.

32 REPLIES 32

There should be a feild in either of the views that is not being used in another view and is mandatory in one view.



If you have a field say 'IPv4' for view = default and is mandatory => all record created from this view(default) will have some value.


Similarly, you have a feild name 'IPv6'   for the other view which is mandatory and only used in this view.



Considering the above two factors are correct, you can add a filter in the module saying:


IPv4 IS NOT EMPTY (this will be for default)


IPv6 IS NOT EMPTY (this will be for the other view)



You dont need to do any scripting.


If I understand your requirement correctly, all you should be be doing is prefixing your filter with '&sysparm_fixed_query' in the arguments field in the module record.


For module1:   &sysparm_fixed_query=u_change_type=itcc


For module2 : &sysparm_fixed_query=u_change_type=Infrastructure


Yes your right...but i don,t want to show that filter on list view


try something like this .....




    var transaction = GlideTransaction.get();


  var page = transaction.getPageName();


  gs.log("Page is ====>" + page);


//page = view_name


  if (page == "itcc"){


    current.addQuery("u_change_type", "itcc");


}




if (page == "default"){




current.addQuery("u_change_type", "Infrastructure");




}


kris10
Giga Contributor

getPageName() is just telling what kind of view it is like for example incident_list etc . But to capture the actual View name then use the below .....




var transaction = GlideTransaction.get();


var ViewNameIs = transaction.getRequestParameter("sysparm_view");


gs.log(ViewNameIs);



Now based on the View name you can update your query