Redirect and populate value in to a specific field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2023 05:57 AM - edited 02-15-2023 06:16 AM
Hi,
I was able to find resource online to redirect to a specific page in the workspace but I am unable to configure where I need the category field to populate a value.
Here is the UI Action | Workspace Client Script
function onClick(g_form) {
var URL = "https://dev112200.service-now.com/x/964096/corp-audit/record/x_964096_my_test_1_control_master/-1/params/query/category=standard";
top.window.location = URL;
}
When the button is clicked
it bring me to a new record page in the workspace and I want this string field to populate a value.
I have tried sysparam_query but it only works on the form but not the workspace form.
Any suggestion?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2023 06:49 AM
Sure, you can follow these steps:
- Right click the field and click Configure Dictionary
- Navigate to the Default Value tab
- Set the default value to some, e.g. standard
- Save
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2023 06:52 AM - edited 02-15-2023 06:53 AM
The thing is there will be a two buttons. How do I set the default to differentiate when either of the button is clicked?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2023 07:02 AM
Ah i see, so it does need to be set conditionally, based on what is being clicked.
In that case, you should set up two views for the form, Standard and Non-Standard, both can be the same.
For the 'New Standard' UI Action use this code:
function onClick(g_form) {
var URL = "https://dev112200.service-now.com/x/964096/corp-audit/record/x_964096_my_test_1_control_master/-1&sysparm_view=my_new_view";
top.window.location = URL;
}
You are doing this in UIB though so you might need to mess around with the parameters you're passing on the form page, add an optional parameter for view and pass it through that URL
Once you're being redirected to the right view, use this onLoad client script:
function onLoad() {
var viewName = getView();
var categoryValue = g_form.getValue("category");
if(viewName == "Standard" && categoryValue == ''){
alert("Standard View");
g_form.setValue('category', 'standard');
}
}
Hope this helps