Corrent ActionName is not populating for Close Complete in Workspace

jitusingh
Tera Contributor

Hi All,


When I am trying to execute onSubmit Client script using actionName="closeComplete" Condition, but everytime actionName is coming as "sysverb_ws_save" , and client script is not running. 

I am trying to execute glidemodal pop up when actionName='closeComplete'.
Workspace = HR Agent Workspace

Any solution will be highly appreciated.

Here is my onSubmit Client Script code:

function onSubmit() {
 
var action_name = g_form.getActionName();
alert('Jitu Action = '+action_name);
 
         if(action_name == 'closeComplete') {
alert('enter glide modal');
var messages = [
        'Close notes', 'Closed Reason', 'Reason',
        'Provide a reason for closing the case as complete.'
    ];
 
    var reasons = [{
        "displayValue": "Cancellation Requested",
        "value": "Cancellation Requested"
    }, {
        "displayValue": "Incorrect Case Record Type",
        "value": "Incorrect Case Record Type"
    }, {
        "displayValue": "Missing Information",
        "value": "Missing Information"
    }, {
        "displayValue": "Redirected",
        "value": "Redirected"
    }, {
        "displayValue": "Resolution Provided",
        "value": "Resolution Provided"
    }, {
        "displayValue": "Knowledge – based Resolution: Article Fully Resolved Case",
        "value": "Knowledge – based Resolution: Article Fully Resolved Case"
    }, {
        "displayValue": "Knowledge – based Resolution: Article Used with Agent Support",
        "value": "Knowledge – based Resolution: Article Used with Agent Support"
    }, {
        "displayValue": "Knowledge – based Resolution: Article Inaccurate or Incomplete",
        "value": "Knowledge – based Resolution: Article Inaccurate or Incomplete"
    }, {
        "displayValue": "Knowledge – based Resolution: No Article Available",
        "value": "Knowledge – based Resolution: No Article Available"
    }, {
        "displayValue": "Service Processing - Transaction",
        "value": "Service Processing - Transaction"
    }, {
        "displayValue": "Duplicate Case",
        "value": "Duplicate Case"
    }, {
        "displayValue": "Resolution Provided by Vendor",
        "value": "Resolution Provided by Vendor"
    }];
 
    getMessages(messages, function() {
        var fields = [{
                type: 'choice',
                name: 'reason',
                label: getMessage('Reason'),
                value: (reasons && reasons.length > 0) ? reasons[0].value : '',
                choices: reasons
            },
 
 
            {
                type: 'textarea',
                name: 'work_notes',
                label: getMessage('Close notes'),
mandatory: true
            }
        ];
 
        var sysId = g_form.getUniqueValue();
        var tblName = g_form.getTableName();
 
        g_modal.showFields({
            title: getMessage('Closed Reason'),
            fields: fields,
            instruction: getMessage('Provide a reason for closing the case as complete.'),
            size: 'md'
        }).then(function(fieldValues) {
            //get the work note entered
            var newReason = fieldValues.updatedFields[0].value;
            var newWorkNote = fieldValues.updatedFields[1].value;
 
            //Call the Ajax function that handles adding worknotes and state
            var s = new GlideAjax("sn_hr_core.ConnectMeHRUtils");
            s.addParam("sysparm_name", "closedCaseAction");
            s.addParam("sysparm_obj_id", sysId);
            s.addParam("sysparm_table_name", tblName);
            s.addParam("sysparm_work_note", newWorkNote);
            s.addParam("sysparm_suspend_reason", newReason);
            s.getXML(addWorkNotes);
 
            function addWorkNotes(response) {
                g_form.save();
            }
        });
    });
 
}
 
 
}
4 REPLIES 4

pr8172510
Mega Guru

Hi jitusingh,

This is expected behavior in Workspace 


1. Root cause

  • In Workspace, g_form.getActionName()
     Always returns sysverb_ws_save

 It does NOT return UI Action names like closeComplete


2. Why your script is not working

  • Workspace uses Declarative Actions, not classic UI Actions
  • So your condition:     

    action_name == 'closeComplete'                 

    Will never be true


    3. Recommended fix

     Don’t use getActionName() in Workspace

    Instead:

     Move logic to Workspace Action (Declarative Action)

    • Configure:
      • Action = Close Complete
      • Add client script / modal logic there

    4. Alternative 

    If you must use Client Script:

    • Check field/state change instead of action name

     

    if (g_form.getValue('state') == 'closed_complete') {
    // trigger modal
    }



if (g_form.getValue('state') == 'closed_complete') {
// trigger modal
}

if I use this , the form will be saved first and then popup will appear but  if i cancel the popup the form will be already saved to Close complete.

Ankur Bawiskar
Tera Patron

@jitusingh 

This is a known behavior, you will not get that action name

since you want your code to run for close complete button better to add the workspace code in Workspace client script and use g_modal there

Something like this

function onClick(g_form) {
    var reasons = [{
        displayValue: "Cancellation Requested",
        value: "Cancellation Requested"
    }, {
        displayValue: "Incorrect Case Record Type",
        value: "Incorrect Case Record Type"
    }, {
        displayValue: "Missing Information",
        value: "Missing Information"
    }, {
        displayValue: "Redirected",
        value: "Redirected"
    }, {
        displayValue: "Resolution Provided",
        value: "Resolution Provided"
    }, {
        displayValue: "Knowledge – based Resolution: Article Fully Resolved Case",
        value: "Knowledge – based Resolution: Article Fully Resolved Case"
    }, {
        displayValue: "Knowledge – based Resolution: Article Used with Agent Support",
        value: "Knowledge – based Resolution: Article Used with Agent Support"
    }, {
        displayValue: "Knowledge – based Resolution: Article Inaccurate or Incomplete",
        value: "Knowledge – based Resolution: Article Inaccurate or Incomplete"
    }, {
        displayValue: "Knowledge – based Resolution: No Article Available",
        value: "Knowledge – based Resolution: No Article Available"
    }, {
        displayValue: "Service Processing - Transaction",
        value: "Service Processing - Transaction"
    }, {
        displayValue: "Duplicate Case",
        value: "Duplicate Case"
    }, {
        displayValue: "Resolution Provided by Vendor",
        value: "Resolution Provided by Vendor"
    }];

    var fields = [{
        type: 'choice',
        name: 'reason',
        label: getMessage('Reason'),
        value: reasons[0].value,
        choices: reasons,
        mandatory: true
    }, {
        type: 'textarea',
        name: 'work_notes',
        label: getMessage('Close notes'),
        mandatory: true
    }];

    g_modal.showFields({
        title: getMessage('Closed Reason'),
        instruction: getMessage('Provide a reason for closing the case as complete.'),
        fields: fields,
        size: 'md'
    }).then(function(result) {
        var updatedFields = result.updatedFields || [];
        var reason = updatedFields[0] ? updatedFields[0].value : '';
        var workNotes = updatedFields[1] ? updatedFields[1].value : '';

        var ga = new GlideAjax('sn_hr_core.ConnectMeHRUtils');
        ga.addParam('sysparm_name', 'closedCaseAction');
        ga.addParam('sysparm_obj_id', g_form.getUniqueValue());
        ga.addParam('sysparm_table_name', g_form.getTableName());
        ga.addParam('sysparm_work_note', workNotes);
        ga.addParam('sysparm_suspend_reason', reason);
        ga.getXMLAnswer(function() {
            g_form.submit('closeComplete');
        });
    });
}

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

I have put the above code in Workspace client script inside Close Complete UI action , But the popup is not coming also the form is getting saved to close_complete.

This is not working.