Client Script doesn't work on Service Operation Workspace.

Community Alums
Not applicable
Hi All,
The client scripts which are working in normal default view of forms aren't working in Service Operation Workspace(UI).
Here, I am implementing an on Load client script - on change of multiple fields to set the short description every time any of the fields changes. by using get control.
 
For example - the below script is not working. 
 
function onLoad() {
    //Type appropriate comment here, and begin script below

    g_form.getControl('category').observe('change', function() {
        updateShortDescription();
    });

    g_form.getControl('subcategory').observe('change', function() {
        updateShortDescription();
    });
    g_form.getControl('u_item').observe('change', function() {
        updateShortDescription();
    });
    g_form.getControl('u_zone').observe('change', function() {
        updateShortDescription();
    });
    g_form.getControl('u_store_number').observe('change', function() {
        updateShortDescription();
    });
    g_form.getControl('u_city').observe('change', function() {
        updateShortDescription();
    });
    g_form.getControl('u_state').observe('change', function() {
        updateShortDescription();
    });
}

function updateShortDescription() {
    var category = g_form.getValue('category');
    var subcategory = g_form.getValue('subcategory');
    var item = g_form.getValue('u_item');
    var zone = g_form.getValue('u_zone');
    var store = g_form.getValue('u_store_number');
    var city = g_form.getValue('u_city');
    var state = g_form.getValue('u_state');
    var template = g_form.getValue('u_selected_template');
   
    var shortDescription = '';

    if (category) {
        shortDescription = 'BK'+ ' - ' + template + '- ' + zone + ' - ' + 'Store' + ' ' + store + ' - '+ '(' + city + ' , ' + state + ')';
        if (subcategory) {
            shortDescription = 'BK'+ ' - ' + template + '- ' + zone + ' - ' + 'Store' +' '+ store + ' - '+ '(' + city + ' , ' + state + ')' + ' - ' + subcategory;
            if (item) {
                shortDescription = 'BK'+ ' - ' + template + '- ' + zone + ' - ' + 'Store' + ' ' +store + ' - '+ '(' + city + ' , ' + state + ')' + ' - ' + subcategory +' - ' + item ;
            }
        }
    } else {
        shortDescription = 'AUTOMATICALLY SET WHEN ITEM IS MODIFIED';
    }

    g_form.setValue('short_description', shortDescription);
}
 

Does anyone have any idea why this would happen?

Thank you in advance!

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Sorry for not posting earlier. I forgot to post the answer at that time. below are the raw code - 

Thank You.

 

var load_data = {
 'u_reference_1': [{
'value': "" }],
 'company': [{
 'value': ""}],
 'u_city': [{
'value': ""}],
 'u_state_province': [{
 'value': ""}],
'category': [{
'value': "" }],
'subcategory': [{
'value': ""}],
 'u_item': [{
 'value': ""}],};

function onLoad() {
var unregister = g_form.onUserChangeValue(user_selected_field_value);
var short_description = g_form.getValue('short_description');
if (short_description != "") {
var split_short_description = short_description.split("-");
var sity_province = split_short_description[3].replace(/[()]/g, '').split(',');
load_data['u_reference_1'][0].value = split_short_description[0];
load_data['company'][0].value = split_short_description[1] + "-" + split_short_description[2];
 load_data['u_city'][0].value = sity_province[0];
load_data['u_state_province'][0].value = sity_province[1];
load_data['category'][0].value = split_short_description[4];
load_data['subcategory'][0].value = split_short_description[5];
 load_data['u_item'][0].value = split_short_description[6];}}

function user_selected_field_value(filedvalue, originalValue, newValue) {
if (filedvalue == "company") {
var run_after_company_selected = setTimeout(function() {
update_company_details(newValue);}, 1000);
 }
 if (filedvalue == "u_reference_1") {
 if (newValue) {
 g_form.setValue('company','');
 load_data['company'][0].value = " ";
var parentAccount = g_form.getReference('u_reference_1', parentAccount_fun);
} else {
 load_data['u_reference_1'][0].value = " ";
 concate_data(); }
} else { if (filedvalue != "company") {
if (load_data.hasOwnProperty(filedvalue)) {
load_data[filedvalue][0].value = newValue;
concate_data();}}}}

function parentAccount_fun(parentAccount) {
 load_data['u_reference_1'][0].value = parentAccount.name;
concate_data();}

function update_company_details(compeny_sysid) {
var script_include = new GlideAjax('global.incident_shortdescription_details');
 script_include.addParam('sysparm_name', 'getDetails');
 script_include.addParam('Account_sysid', compeny_sysid);
script_include.addParam('Paccount_sysid', g_form.getValue("u_reference_1"));
script_include.getXML(function(response) {
 var account = response.responseXML.documentElement.getAttribute("answer");
 var data = account.split(",");
load_data.company[0].value = data[0];
load_data.u_reference_1[0].value = data[1];
load_data.u_state_province[0].value = g_form.getValue('u_state_province');
 load_data.u_city[0].value = g_form.getValue('u_city');
concate_data();  });}

function concate_data() {
var category = load_data['category'][0].value;
var u_item = load_data['u_item'][0].value;
var u_city = load_data['u_city'][0].value;
var u_state_province = load_data['u_state_province'][0].value;
var company = load_data['company'][0].value;
 var u_parent_account = load_data['u_reference_1'][0].value;
 var subcategory = load_data['subcategory'][0].value;
var testmy = u_parent_account + " - " + company + " - (" + u_city + "," + u_state_province + ")" + " - " + category + " - " + subcategory + " - " + u_item;
 g_form.setValue('short_description', testmy);}

 

 

View solution in original post

11 REPLIES 11

Steve Wiseman
Tera Guru

Hi Aishwarya,

 

Have you tried this as an onChange script instead of onLoad?

 

Steve 

Community Alums
Not applicable

Yes, I tried to implement it using an 'on change' client script, but it's not working.

Maik Skoddow
Tera Patron
Tera Patron

HI @Community Alums 

the Workspaces are built with the new Next Experience UI Framework and here you are really restricted. For example, you cannot access anymore any HTML/DOM elements (g_form.getControl). So you have to comply to the official recommendations not to rely on DOM access/manipulation.

Maik

Community Alums
Not applicable

Ok, Thank you for the reply Maik.