Create new record with specific view on UI Action?

ericeger
Tera Guru

Hello all,

I have created a new table that is on a related list and when it comes to creating new records on the related list, I woulld like to be able to do it two ways.   One would be for a user to click on 'New' and go to the Default view.   Another would be to click on a UI Action and have it go to the form with another view.   I have tried creating the UI Action with a redirect to the table using 'action.setRedirectURL('table.do?sys_id=-1&sysparm_view=new_view') and it gives me an error of 'No records selected'.  

I've looked on the forums and found suggestions when it came to switching views on already created records, but this would be for going to a brand new record with a forced view.   Is there another way for me to do this? Thanks!

-Eric

10 REPLIES 10

As is mine (see "Math Events") on the screenshot above.



Another difference: Mine did not force it to a specific view. That wouldn't account for the 'record not found' (as far as I can tell.) Have you tried it without the view to see if it works?


Hey Chuck,



I have tried it without the view as well.   I have it so that it looks just like yours, except a different table name.


Hi Eric,



Thanks for the info. What version of ServiceNow are you using. That's the only remaining variable I can think of.


Hey Chuck,



I am using Geneva Patch 7 at the moment.



I think I may have found a solution though, thanks to a post from Michael Ritchie in this question linked below



Re: how to hide "No Records selected" alert on click of list button



He had said that if your UI Action name starts with sysverb, then the alert for 'No records selected' is suppressed, which I found pretty interesting.   Not sure why that works the way it does. Irregardless, I was also able to apply a forced view on my new record, along with carrying over a filtered value.   I'll post what I did in case it helps somebody else out.



var uri = action.getGlideURI();


var collectionID = uri.get('sysparm_collectionID');


action.setRedirectURL('table.do?sys_id=-1&sysparm_view=my_new_view&sysparm_query=incident%3D' + collectionID);



Thanks for helping me out!



-Eric


Interesting. My UI action did not include sysverb. I'll keep that in mind in the future.