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

Hi Kamlesh,

I am releived to have found this post but I am unable to do the same for my requirement.

My requirement is that I have 2 custom views created for Change request, out of which one has been named 'default view' and it has been there since long.

Now our requirement is that we need to open our Standard Change Catalog items in OOTB view. So , I have created the OOTB view and named it 'standard_change'. 

Can you please help me how to open the standard change catalog items new Form in 'standard_view' View instead of the old default view and it should not affect the already existing default view when we use 'Create New' for creating a change request.

Thanks 
Joy

 

Hi @kamlesh kjmar 

 

I do have same requirement but. There see little. if already records are there in related list if we click on them then it should open in a custom view. how i can achieve this please help,,? 

Hi @Mannam Praveen  ,

 

Try removing the g_form.isNewRecord() from the if condition of onLoad client script. It should work then.

 

 

Please hit the helpful button if this helps.

 

Thanks,

Kamlesh

Deepak Negi
Mega Sage
Mega Sage

Hi gayatri




This is just an idea to modify the New button for related list of the table.
E.g I have modified the New button code which is visible on the related list.


I have done below:



1. When New Button clicked from Incident's normal list - it opens a default view for new form(OOB).


2. When New Button clicked from Related List of Incidenton other table   - it opens a custom view which we pass in the code.



Please follow below points before applying:


1. This might not be a robust code but it gives an idea where to make changes.


2. You can probably use uri.set effectively to complete this requirement



I have commented the OOB code and updated it as below:



Code:


var uri = action.getGlideURI();


  var path = uri.getFileFromPath() + '';


  path = path.substring(0, path.length - 5) + '.do';


      uri.set('sys_id', '-1');


  //uri.set('sysparm_view', 'Major+Incidents');




  path = checkWizard(uri, path);




  if (path)


  //     action.setRedirectURL(uri.toString(path));


  var query = 'incident.do?sys_id=b537cd07db5722001475d7a0cf96194b&sysparm_view=Major%20Incidents&sysparm_view=Major+Incidents&sysparm_domain=null&sysparm_domain_scope=null&sysparm_record_row=1&sysparm_record_rows=29&sysparm_record_list=active%3dtrue%5eORDERBYDESCnumber&sysparm_nostack=yes';


action.setRedirectURL(query)




Thanks


Deepak