Ui Action Button on Service operation workspace view

pujitha K
Tera Contributor

Hi Team,

 

I have requirement to show UI action button on Service operation workspace view which has been achieved and could see in SOW view but the functionality on the button is not achievable.

 

We have the requirement to create Risk assessments separate section when Risk questions are selected and when user clicks on Calculate risk button Risk will get calculated, for this i have created new Calculate risk button and written code in the script section.

 

PFB code which is working as expected.

 

 

function calculateRisk() {
    if(g_form.getValue('u_will_the_change_affect_any_business_critical_application_service_critical_site') == '' || g_form.getValue('u_how_many_users_could_be_impacted_during_the_implementation_of_the_change') == '' || g_form.getValue('u_how_difficult_it_is_to_roll_back_the_change_to_its_original_state') == '' || g_form.getValue('u_which_regions_are_impacted') == '' || g_form.getValue('u_has_testing_been_completed_for_this_change') == '' || g_form.getValue('u_is_downtime_required') == '' || g_form.getValue('u_in_which_environment_will_this_change_be_implemented') == '' || g_form.getValue('u_has_this_type_of_change_been_deployed_before_without_any_impact') == ''){
        g_form.addInfoMessage('Please Fill All Risk Assesment Fields To calculate the Risk');
        return false;
    }
    var total = 0;

    var impactBusiness = g_form.getValue('u_will_the_change_affect_any_business_critical_application_service_critical_site');
    var usersImpacted = g_form.getValue('u_how_many_users_could_be_impacted_during_the_implementation_of_the_change');
    var rollBackToOriginal = g_form.getValue('u_how_difficult_it_is_to_roll_back_the_change_to_its_original_state');
    var regionsImpacted = g_form.getValue('u_which_regions_are_impacted');
    var testingCompleted = g_form.getValue('u_has_testing_been_completed_for_this_change');
    var downTimeRequired = g_form.getValue('u_is_downtime_required');
    var envImplemented = g_form.getValue('u_in_which_environment_will_this_change_be_implemented');
    var woImpact = g_form.getValue('u_has_this_type_of_change_been_deployed_before_without_any_impact');

    // Scoring
    if (impactBusiness === 'yes') total += 5;
    if (impactBusiness === 'no') total += 0;

    if (usersImpacted === 'none') total += 0;
    if (usersImpacted === '10_50') total += 1;
    if (usersImpacted === '50_100') total += 3;
    if (usersImpacted === '100_plus') total += 5;

    if (rollBackToOriginal === 'hard') total += 4;
    if (rollBackToOriginal === 'easy') total += 1;
    if (rollBackToOriginal === 'medium') total += 2;
    if (rollBackToOriginal === 'rollback') total += 5;

    if (regionsImpacted === 'no_impact') total += 0;
    if (regionsImpacted === 'local') total += 1;
    if (regionsImpacted === 'regional') total += 3;
    if (regionsImpacted === 'global') total += 5;

    if (testingCompleted === 'tested_nonprod') total += 3;
    if (testingCompleted === 'testing_not_required') total += 2;
    if (testingCompleted === 'no_testing_possible') total += 0;
    if (testingCompleted === 'Production_Change') total += 4;

    if (downTimeRequired === 'none') total += 2;
    if (downTimeRequired === 'downtime_no_user') total += 4;
    if (downTimeRequired === 'downtime_user') total += 0;

    if (envImplemented === 'nonprod') total += 2;
    if (envImplemented === 'prod') total += 5;

    if (woImpact === 'yes_prior_success') total += 0;
    if (woImpact === 'no_prior_success') total += 5;

    // Risk mapping
    if (total >= 3 && total <= 12) {
        g_form.setValue('risk', '4'); // low
        g_form.addInfoMessage('Risk Score is set to Low');
    } else if (total >= 13 && total <= 24) {
        g_form.setValue('risk', '3'); // moderate
        g_form.addInfoMessage('Risk Score is set to Moderate');
    } else if (total >= 25 && total <= 38) {
        g_form.setValue('risk', '2'); // high
        g_form.addInfoMessage('Risk Score is set to High');
    } else {
        g_form.addInfoMessage('Risk Score could not be determined from the current values (total=' + total + ').');
    }
   
      gsftSubmit(null, g_form.getFormElement(), 'calculate_risk');

}
if (typeof window == 'undefined')
   setRedirect();

function setRedirect() {
    //g_scratchpad.isRiskCalculated = true;
    current.u_risk_calculated = true;
    current.update();
    action.setRedirectURL(current);
}
 
 
Now the requirement is same operation should perform on SOW view also above script works both server side and client side but whenever i am selecting 
Workspace Form Button and Format for Configurable Workspace as below, it is asking for only client-side script 
pujithaK_0-1767619107318.png

 

 

Please provide me inputs to achieve this same script in both native and workspace view

 

Thanks,

Pujitha

1 REPLY 1

Itallo Brandão
Mega Guru

Hi Pujitha,

This is a common scenario when migrating to Service Operations Workspace (SOW).

The issue is that gsftSubmit is specific to the Classic (Native) UI and does not exist in the Workspace architecture. Additionally, when "Format for Configurable Workspace" is checked, server-side code like current.update() is not allowed directly in the client script.

Since your logic is purely reading form values and setting a field, you can convert this to a 100% Client-Side UI Action. This makes it compatible with both Native UI and Workspace without needing separate scripts.

Here is the updated script using g_form.save() instead of gsftSubmit:

UI Action Configuration:

  • Client: Checked (True)

  • OnClick: calculateRiskClientSide()

  • Workspace Form Button: Checked (True)

  • Format for Configurable Workspace: Unchecked (Leave this empty so the script below applies to both).

Script:

function calculateRiskClientSide() {
    // 1. Validation
    var fieldsToCheck = [
        'u_will_the_change_affect_any_business_critical_application_service_critical_site',
        'u_how_many_users_could_be_impacted_during_the_implementation_of_the_change',
        'u_how_difficult_it_is_to_roll_back_the_change_to_its_original_state',
        'u_which_regions_are_impacted',
        'u_has_testing_been_completed_for_this_change',
        'u_is_downtime_required',
        'u_in_which_environment_will_this_change_be_implemented',
        'u_has_this_type_of_change_been_deployed_before_without_any_impact'
    ];

    for (var i = 0; i < fieldsToCheck.length; i++) {
        if (g_form.getValue(fieldsToCheck[i]) == '') {
            g_form.addErrorMessage('Please Fill All Risk Assessment Fields To calculate the Risk');
            return false;
        }
    }

    var total = 0;

    // 2. Get Values
    var impactBusiness = g_form.getValue('u_will_the_change_affect_any_business_critical_application_service_critical_site');
    var usersImpacted = g_form.getValue('u_how_many_users_could_be_impacted_during_the_implementation_of_the_change');
    var rollBackToOriginal = g_form.getValue('u_how_difficult_it_is_to_roll_back_the_change_to_its_original_state');
    var regionsImpacted = g_form.getValue('u_which_regions_are_impacted');
    var testingCompleted = g_form.getValue('u_has_testing_been_completed_for_this_change');
    var downTimeRequired = g_form.getValue('u_is_downtime_required');
    var envImplemented = g_form.getValue('u_in_which_environment_will_this_change_be_implemented');
    var woImpact = g_form.getValue('u_has_this_type_of_change_been_deployed_before_without_any_impact');

    // 3. Scoring
    if (impactBusiness === 'yes') total += 5;

    if (usersImpacted === '10_50') total += 1;
    else if (usersImpacted === '50_100') total += 3;
    else if (usersImpacted === '100_plus') total += 5;

    if (rollBackToOriginal === 'hard') total += 4;
    else if (rollBackToOriginal === 'easy') total += 1;
    else if (rollBackToOriginal === 'medium') total += 2;
    else if (rollBackToOriginal === 'rollback') total += 5;

    if (regionsImpacted === 'local') total += 1;
    else if (regionsImpacted === 'regional') total += 3;
    else if (regionsImpacted === 'global') total += 5;

    if (testingCompleted === 'tested_nonprod') total += 3;
    else if (testingCompleted === 'testing_not_required') total += 2;
    else if (testingCompleted === 'Production_Change') total += 4;

    if (downTimeRequired === 'none') total += 2;
    else if (downTimeRequired === 'downtime_no_user') total += 4;

    if (envImplemented === 'nonprod') total += 2;
    else if (envImplemented === 'prod') total += 5;

    if (woImpact === 'no_prior_success') total += 5;

    // 4. Set Risk Value
    if (total >= 3 && total <= 12) {
        g_form.setValue('risk', '4'); // low
        g_form.addInfoMessage('Risk Score is set to Low (Score: ' + total + ')');
    } else if (total >= 13 && total <= 24) {
        g_form.setValue('risk', '3'); // moderate
        g_form.addInfoMessage('Risk Score is set to Moderate (Score: ' + total + ')');
    } else if (total >= 25 && total <= 38) {
        g_form.setValue('risk', '2'); // high
        g_form.addInfoMessage('Risk Score is set to High (Score: ' + total + ')');
    } else {
        g_form.addInfoMessage('Risk Score could not be determined (Total: ' + total + ').');
    }

    // 5. Update and Save (Client-Side)
    // This replaces gsftSubmit and works in both Workspace and Native UI
    g_form.setValue('u_risk_calculated', 'true');
    g_form.save();
}



Hope this helps!