UI Action for Agent Workspace - executing both Client and Server Side code in one UI action

gkbhandare003
Kilo Guru

Hi All,

Edit: This works in Platform UI as expected( when I put code in script section), but in Workspace UI I am able to run only Server Side script and client side script is skipped.

I am creating One UI action which should execute following actions when clicked from Agent Workspace Incident form:

1. Create and Interaction

2. Open a teams chat using deep link.

I am able to run these two scripts separately with two UI actions, but when I try to combine both of them in one UI action, I am not able to do it..

Not sure how exactly can I put this together, I tried it this way but when I run the action from Workspace, I get error as 'Failed to execute UI action, please contact your system administrator'

Please find my Ui action details and code below:

UI action name: start_chat

Active: true

client: true

Onclick: runClientSideCode();

Workspace Form button: true

Workspace Client Script: //I have wrote the script here as I was not able to execute in on workspace when written in Script section too

 

if(typeof window == 'undefined')
{
runServerSideCode();
}

function runClientSideCode()//added this function in onClick field of Ui action
{

//script to open Teams chat
var prefix = 'https://teams.microsoft.com/l/chat/0/0?users=';
var ref = g_form.getReference('caller_id', getEmail);
var inc_number=g_form.getValue('number'); 
var inc_Sd= g_form.getValue('short_description'); 

function getEmail(ref)
{//Callback function
var email = ref.getValue('email');
var firstname=ref.getValue('first_name'); 
var subject = '&message=Hi '+ firstname + ','+' this is regarding your Incident ' + inc_number + ' : '+inc_Sd; 
var url = prefix + email + subject; 
top.window.open(url); 
}
gsftSubmit(null, g_form.getFormElement(), "start_chat"); //this is my UI action name
}

function runServerSideCode()
{

//Script to create interaction
var incGr = new GlideRecord('interaction');
incGr.newRecord();
incGr.setValue('opened_for', current.getValue('caller_id'));
incGr.setValue('short_description', current.short_description);
incGr.setValue('direction', 'Outbound');
incGr.insert();
action.openGlideRecord(incGr);
}

 

Kindly suggest on how can we get this working.

 

Thanks in advance.

 

Ganesh

1 ACCEPTED SOLUTION

gkbhandare003
Kilo Guru

This is working now.

Initially I was using the gsftsubmit to call UI action but was getting error in workspace while executing UI action 

now I have Script to create Interaction in 'Script' field of UI action and script to open teams chat in Workspace Client script field , from where I am calling the UI action using g_from.submit();

 

View solution in original post

4 REPLIES 4

Frank Tate
Giga Guru
Giga Guru

1. Please use the insert/edit code sample function in the editor when you need to add code to a question.

2. You need to actually call the function runClientSideCode(). You define the function, but you never invoke it. You should have something like the following (inserted using the  icon:

if (typeof window == 'undefined') {
    runServerSideCode();
} else {
    runClientSideCode();
}
...

Frank

Please mark this answer as helpful.

vkachineni
Kilo Sage
Kilo Sage

Make sure the Isolate script check box is 'off' on the script. Also re-order the script in the following way.

 Submit the form after getting the email in the reference.

function runClientSideCode() //added this function in onClick field of Ui action
{

    //script to open Teams chat
    var prefix = 'https://teams.microsoft.com/l/chat/0/0?users=';
    var ref = g_form.getReference('caller_id', getEmail);
    var inc_number = g_form.getValue('number');
    var inc_Sd = g_form.getValue('short_description');

    function getEmail(ref) { //Callback function
        var email = ref.getValue('email');
        var firstname = ref.getValue('first_name');
        var subject = '&message=Hi ' + firstname + ',' + ' this is regarding your Incident ' + inc_number + ' : ' + inc_Sd;
        var url = prefix + email + subject;
        top.window.open(url);
		gsftSubmit(null, g_form.getFormElement(), "start_chat"); //this is my UI action name. Submit the form after getting the email and opening a window.
    }
    
}

if (typeof window == 'undefined') {
    runServerSideCode();
}

function runServerSideCode() {

    //Script to create interaction
    var incGr = new GlideRecord('interaction');
    incGr.newRecord();
    incGr.setValue('opened_for', current.getValue('caller_id'));
    incGr.setValue('short_description', current.short_description);
    incGr.setValue('direction', 'Outbound');
    incGr.insert();
    action.openGlideRecord(incGr);
}
Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

gkbhandare003
Kilo Guru

This is working now.

Initially I was using the gsftsubmit to call UI action but was getting error in workspace while executing UI action 

now I have Script to create Interaction in 'Script' field of UI action and script to open teams chat in Workspace Client script field , from where I am calling the UI action using g_from.submit();

 

Vinicius Olivei
Tera Contributor

Just came across this and the solution had helped me, but i had to do a few tests to get it to work, which is basically as follows:

 

1 - Once your UI Action client side code execution is completed, it has to run the UI Action again. For that to happen you must add at the end of your client side function:

 

 

g_form.submit(actionName); // actionName = the value in the "Action name" field in the UI Action.

 

2 - For that to work in the service operations workspace, the client side code must be in the "Workspace Client Script" field.
3 - In the normal "Script" field, you will only place your server-side code, which will get executed once the UI Action is triggered again at the end of the client-side code.
4 - The following code must be added to the beginning of your UI action server-side code, so that it knows when to trigger your server-side function:

 

if (typeof window == 'undefined'){
        runServerSide();
}

function runServerSide(){
        // your code here...
}