Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Need to show pop up with Ok or Cancel button , when user click on Ok the feedback task should create

Rekha20
Tera Contributor

Hi All,

Need to show pop up with Ok or Cancel button on HR case form when state is awaiting acceptance, when user click on Ok the feedback task should create.

 

Any suggestion to achieve it?

 

I created a UI page and called it in onChange client script, it is working in native view but not in workspace.

 

Thanks,

3 REPLIES 3

Philippe Casidy
Tera Guru

Hi,

 

I think you can do something similar to when making "Complete" and update-set batch.

Are you trying to get something similar to this in a form?

PhilippeCasidy_0-1762925401653.png

 


Look at this Client script in your instance:
/nav_to.do?uri=sys_script_client.do?sys_id=c3a34c7b47232200a03a19fbac9a711e

 

Let me know how it works for you.

Regards,
Philippe

Hi @Philippe Casidy 

 

I tried with below script include and client script:

 

script include: 

var CreateKnowledgeFeedbackAJAX = Class.create();
CreateKnowledgeFeedbackAJAX.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

    createFeedbackTask: function() {
        var caseId = this.getParameter('sysparm_case_id');
        if (!caseId) return false;

        try {
            // Retrieve the HR case
            var caseRec = new GlideRecord('sn_hr_core_case');
            if (caseRec.get(caseId)) {

                // Create a new Knowledge Feedback Task
                var task = new GlideRecord('kb_feedback_task');
                task.initialize();
                task.parent = caseRec.getUniqueValue();

                // Insert the task
                task.insert();

                return true;
            }
        } catch (e) {
            gs.error('Error creating Knowledge Feedback Task: ' + e.message);
        }

        return false;
    }

});    
 
 
client script: 
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    // Prevent triggering on load
    if (isLoading || newValue === oldValue) return;

    // Replace this with your real "Awaiting Acceptance" value
    var AWAITING_ACCEPTANCE = '20';

    if (newValue != AWAITING_ACCEPTANCE) return;

    // Show GlideModal confirmation
    var dialog = new GlideModal('glide_modal_confirm', true, 300);
    dialog.setTitle(new GwtMessage().getMessage('Knowledge Gap Feedback'));
    dialog.setPreference(
        'body',
        new GwtMessage().format(
            "Could this case have been solved by the employee had there been a relevant knowledge article on the portal?"
        )
    );
    dialog.setPreference('focusTrap', true);
    dialog.setPreference('onPromptComplete', doConfirm);
    dialog.setPreference('onPromptCancel', doCancel);
    dialog.render();

    // --- Handlers ---
    function doConfirm() {
        // Agent clicked OK
        g_form.addInfoMessage('Creating Knowledge Feedback Task...');

        var ga = new GlideAjax('CreateKnowledgeFeedbackAJAX');
        ga.addParam('sysparm_name', 'createFeedbackTask');
        ga.addParam('sysparm_case_id', g_form.getUniqueValue());
        ga.getXMLAnswer(function(response) {
            if (response === 'true') {
                g_form.addInfoMessage('Knowledge Feedback Task created successfully.');
                g_form.setValue('state', AWAITING_ACCEPTANCE);
                g_form.save(); // commit change
            } else {
                g_form.addErrorMessage('Failed to create Knowledge Feedback Task.');
                g_form.setValue('state', oldValue);
            }
        });
    }

    function doCancel() {
        // Agent clicked Cancel
        g_form.addInfoMessage('No feedback task created.');
        g_form.setValue('state', oldValue);
    }
}  this is wokringh in native view not in workspace. Please advise.

Hi,

 

Sorry I missed the point you were mentioning about it not working Workspace in your OP.

Because nobody else seems to have suggestion, I searched and found this

https://www.servicenow.com/docs/csh?topicname=g_modalClientAPI.html&version=latest

 

But I have no experience and I cannot test it right now.

Please let us know!

 

Thanks
Philippe