Redirect and populate value in to a specific field

Spaceballs
Kilo Sage

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

Spaceballs_0-1676469137124.png

 

Spaceballs_1-1676469155396.png

 

 

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

Spaceballs_2-1676469202833.png

it bring me to a new record page in the workspace and I want this string field to populate a value.

Spaceballs_3-1676469324259.png

I have tried sysparam_query but it only works on the form but not the workspace form.

 

Any suggestion?

 

 

 

7 REPLIES 7

Sure, you can follow these steps:

 

  1. Right click the field and click Configure Dictionary
  2. Navigate to the Default Value tab
  3. Set the default value to some, e.g. standard
  4. Save

Spaceballs_0-1676472777472.png

 

The thing is there will be a two buttons. How do I set the default to differentiate when either of the button is clicked?

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