The CreatorCon Call for Content is officially open! Get started here.

How to open a new change form in a custom view, when opened using a related list on project

gay
Tera Contributor

Hi,

On project form, we have change request related list, which allows the user to create a new change request. My requirement is to make that new form open in a custom view when i try to create the change using new button as shown below.

find_real_file.png

I wrote a view rule on change request with below condition which opens the already created project related changes in the new view but I need the new form to be opened in the custom view when i try to create from the related list of project

find_real_file.png

I also tried using an on load client script as shown below but that applies to all changes. I need to restrict that client script to work on new forms that i try to create using related list on project which i am unable to because the record is not yet created and so unable to differentiate between the project change records and other changes.

find_real_file.png

Please let me know how this can be achieved as i have an immediate requirement

1 ACCEPTED SOLUTION

Hi Sreedhar,



Change of view tries to update the record that is why you are getting that error.



Use the below mentioned code in your onLoad client script. In the example I have assumend incident table to be the table available in the related list:-



if(window.location.search.indexOf('sys_is_related_list=true')>1 && g_form.isNewRecord()&& window.location.search.indexOf("sysparm_view=your_view_name")<1){



  window.location="https://your_instance.service-now.com/incident.do?sys_id=-1&sysparm_view=your_view_name"


}




Please mark Helpful if this solves your issue.



Thanks,


Kamlesh


View solution in original post

8 REPLIES 8

gay
Tera Contributor

Please let us know how the above can be achieved. Immediate help is much appreciated


kamlesh kjmar
Mega Sage

Hi Gayatri,



For this first of all you need to check if a form is being opened by clicking on the new button from related list. If you look closely the URL of new form opened using NEW button available in related list then you will see url contains parameter 'sys_is_related_list=true'.



Now to achieve your requirement write a onLoad client script check the URL for the presence of 'sys_is_related_list=true' and if found true then set the required view.



if(window.location.search.indexOf('sys_is_related_list=true')>1)





Please mark helpful if this solves your issue.


Hi Kamlesh,


I have a similar requirement but when I use switchview in my client script, the form reloads and gives me record not found error.


Please let me know how this can be avoided


Hi Sreedhar,



Change of view tries to update the record that is why you are getting that error.



Use the below mentioned code in your onLoad client script. In the example I have assumend incident table to be the table available in the related list:-



if(window.location.search.indexOf('sys_is_related_list=true')>1 && g_form.isNewRecord()&& window.location.search.indexOf("sysparm_view=your_view_name")<1){



  window.location="https://your_instance.service-now.com/incident.do?sys_id=-1&sysparm_view=your_view_name"


}




Please mark Helpful if this solves your issue.



Thanks,


Kamlesh