Limiting Client script to Service Operations workspace

Abhishek Chava1
Tera Contributor

I am working on a requirement to add a message 'VIP user' to the caller field if the user selected in the reference field is VIP. I have achieved this simple configuration, but I am unable to configure it in such a way that it is limited to the Service Operations Workspace view.

 

AbhishekChava1_1-1681211024678.png

 

 

If I check the global view option, then the script works as expected in all views. But I want to limit the operation to Service Operations Workspace only.

2 ACCEPTED SOLUTIONS

Kristen Ankeny
Kilo Sage

"workspace" is the legacy agent workspace view. There is another view used by Service Operations Workspace called "sow".

View solution in original post

DUGGI
Giga Guru

To limit the application of the script to the Service Operations Workspace view only, you can add a condition to check the current view before running the script.

Here's an example of how you can modify your script to achieve this:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
  // Check if the current view is the Service Operations Workspace
  if (g_view_name != 'sn_sops') {
    return;
  }

  // Check if the user selected in the reference field is VIP
  var user = g_form.getReference('caller', function(reference) {
    if (reference.vip == true) {
      g_form.setValue('caller', reference.display_value + ' [VIP user]');
    }
  });
}

In this modified script, we added a check for the current view using the g_view_name global variable.

If the current view is not the Service Operations Workspace (sn_sops), the script will simply return without executing further.

If the current view is the Service Operations Workspace, the script will continue to check if the user selected in the reference field is VIP, and add the 'VIP user' message to the caller field if necessary.

View solution in original post

4 REPLIES 4

Kristen Ankeny
Kilo Sage

"workspace" is the legacy agent workspace view. There is another view used by Service Operations Workspace called "sow".

DUGGI
Giga Guru

To limit the application of the script to the Service Operations Workspace view only, you can add a condition to check the current view before running the script.

Here's an example of how you can modify your script to achieve this:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
  // Check if the current view is the Service Operations Workspace
  if (g_view_name != 'sn_sops') {
    return;
  }

  // Check if the user selected in the reference field is VIP
  var user = g_form.getReference('caller', function(reference) {
    if (reference.vip == true) {
      g_form.setValue('caller', reference.display_value + ' [VIP user]');
    }
  });
}

In this modified script, we added a check for the current view using the g_view_name global variable.

If the current view is not the Service Operations Workspace (sn_sops), the script will simply return without executing further.

If the current view is the Service Operations Workspace, the script will continue to check if the user selected in the reference field is VIP, and add the 'VIP user' message to the caller field if necessary.

Timothy Bevilac
Tera Contributor

I couldn't refernce the global varaible g_view_name

But
 I did find a function that always errors in the NextUI, which while annoying is also useful 😉

var view = ''; //Sting to capture the view 
try {
                view = getView(); // only works in Classic UI
 } catch (error) {
                view = 'nextUI';
            }

Badrinarayan
Tera Guru

Hi @Abhishek Chava1 , 

 

By Using getReference Method  is not the Best Practise to Limit in ''sow'' View and doesn't work on Service Operations Workspace , Use GlideAjax Method and get the Value then in Client Script Form, Uncheck the Global Field and in the View Field enter as ''sow'' view  
Thanks
Badrinarayan