- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Hi everyone, I’m in a bit of a pickle and could use some guidance.
As the topic suggests, I’m trying to implement a record conversion via a UI Action. Specifically, creating a record in Table B based on an existing record in Table A.
Table B has some custom logic that populates certain fields automatically when a record is inserted or updated. To support this, I’ve created a special view that includes only the necessary fields for this conversion process.
The UI Action is designed to redirect the user to the new record form in Table B, using this specific view.
An onLoad client script with the condition
if (g_form.getViewName() === 'mySpecialView') {
//popuiate fields here
}
then pulls the description from the Table A record and sets it in the new Table B record. It also sets default values for other fields to trigger the custom logic.
The problem is, no matter what I try to script into the UI Action, it does not change the View of the "new record" page (thereby making the onLoad script moot).
(function() {
var targetURL = '/my_table_B.do?sysparm_new=true' +
'&sysparm_view=mySpecialView' +
'&sysparm_view_forced=true' +
'&sysparm_mode=form';
action.setRedirectURL(targetURL);
})();
Has anyone else tackled something similar? I'm beginning to wonder if my approach is too roundabout.
Thanks in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
so on click of that UI action you want special view to be shown and only show limited fields in that?
If yes then you can use onLoad client script and check in URL what's the view and based on that only show your fields which you want and hide the other fields.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Sorry if it wasnt clear from my original post, but the requirement was that certain fields be present in a certain layout (hence the creation of a View). My main problem is that no matter the method I use to create a new record, I cant change the View of the [table].do/new record page (whether forcefully changing it via UI action or through the header menu)
(function() {
var url = '/sn_si_request.do?sys_id=-1' +
'&sysparm_view=mySpecialView' +
// '&sysparm_view_forced=true' +
'&sysparm_mode=form';
action.setRedirectURL(url);
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
so on click of that UI action you want special view to be shown and only show limited fields in that?
If yes then you can use onLoad client script and check in URL what's the view and based on that only show your fields which you want and hide the other fields.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Yep! Thanks for confirming that my initial approach makes sense.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
While I marked this as solved, Just one more thing:
I do plan to follow the approach that was mentioned. However, one minor blocker I’m facing is that the process relies on a special view. ServiceNow has a behavior where, if a user has previously changed their view via a list or form, it tends to persist that view even when using URLs like:
/table_name.do?sys_id=-1&sysparm_view=SpecialView&sysparm_view_forced=true
Despite using sysparm_view_forced=true, the form sometimes still loads with the user's last-used view instead of the one specified in the URL. The obvious workaround is that an end-user must switch views in Table B before performing the UI Action in Table A
((they cannot switch views via the new record page opened with
/sn_si_request.do?sys_id=-1' + '&sysparm_view=mySpecialView' +
))
but that feels inelegant. I've been trying to wrap my head around how else a user can just seamlessly use the UI Action but unless anyone else has some insight, I might just end up having the end user switch views manually in the Table itself.