We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

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

Sure it does. In our instance there is a hidden element in the form html:



<input id="sysparm_view" value="" type="HIDDEN" name="sysparm_view"></input>




and there is a hidden element in the list view html:




<input type="hidden" value="" name="sysparm_view"></input>




So if we're looking at the Mobile list view, for example, we get:




<input type="hidden" value="Mobile" name="sysparm_view"></input>




And on form view:




<input id="sysparm_view" value="Mobile" type="HIDDEN" name="sysparm_view"></input>


hi I have created an UI action in approver form..." UPDATE RITM",



function displayRITMRecord() {


        var dialog = new GlideDialogForm('Review & Update ', 'sc_req_item');


        dialog.setSysID(g_form.getValue('document_id'));


        dialog.addParm('sysparm_view','Approver');     ---- it works only for ITIL users and not for ESS users. So, used the below global business rule.


        dialog.addParm('sysparm_form_only','true');


        dialog.render();


}



created a global business rule as below to show the APPROVER view( in RITM )   to ESS approver when clicks on UPDATE RITM.




// populate the default value for the caller


function sc_req_itemGetViewName() {


      if (gs.hasRole("itil"))


  {return;}


  if (view.startsWith("approver"))


      {return;}


  if (view == "sys_ref_list")


      {return;}


  answer = "approver";


}


function sc_req_item_listGetViewName() {


sc_req_itemGetViewName();


}



I dont see any luck in getting my APPROVER view shown to the end user through UI Action. Kindly help


blaine2
Tera Contributor

More directly and without DOM dependencies:

g_form.getViewName()

or

GlideList2.get(yourListName).getView()