- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 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
4 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
4 weeks ago
I must also note that much of these fields are dropdown fields.
Which is why the user wants to be able to edit them once clicking the UI Action (i.e. make a draft of the conversion before inserting it into Table B). Which is why i didnt simply go for a gr.initialize() as I am reliant on the custom view.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
you can set the fields you want on Table B new record from the UI action itself.
why to have onLoad client script for this
Something like this in server side
(function() {
// pass the actual field names and the values you want to set
var targetURL = '/my_table_B.do?sys_id=-1&sysparm_query=short_description=' + 'my test' + '&description=' + 'my description';
action.setRedirectURL(targetURL);
})();
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
4 weeks ago
Hi @Ankur Bawiskar , the end goal is for the user to be able to make a "draft" of the conversion before the record is submitted. Which is why I did not programmatically set values of certain fields via passing in URL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
yes the approach I shared will just set the field values and won't submit automatically.
it's a new record as you can see in the URL I have given sys_id=-1
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