Aborting message through UI Action

abirakundu23
Mega Sage

Hi All/ @Sandeep Rajput ,

Actually, want to show abort message when click on "UI Action".

We have called script include from server side, so that we have put condition in UI action condition.

As per script logs are executed but taking wrong record value.

Script include:

var Test = Class.create();
Test.prototype = {
    initialize: function() {
    },
    validation:function(){
var checkstatus = false;
gs.info("Checking issue >>> Line6");
var caserecord = new GlideRecord('sn_hr_core_case');
caserecord.addEncodedQuery('u_test=Yes^active=true');
gs.info("Checking issue >>> Line9");
caserecord.query();
gs.info('Checking the issue case record');
if(caserecord.next())
{
    //var taskrecord = new GlideRecord('sn_hr_core_task');
    //taskrecord.addQuery('parent',current.parent.sys_id);
    gs.info('Checking the validation issue case record');
    var count = 0;
    var case_record=caserecord.sys_id;
    gs.info('case record:' +case_record);
    var task_table = new GlideAggregate('sn_hr_core_task');
    var temp = gs.getProperty('sn_hr_core.ValidationTask');
    task_table.addEncodedQuery('template='+ temp +'^parent=' + case_record);
    task_table.addAggregate('COUNT');
    task_table.query();
    while (task_table.next()) {
        count = task_table.getAggregate('COUNT');
    }
    gs.info('Count is'+count);
    while (task_table.next()) {
    if((count == 0 )|| (count !=0 && task_table.state != '3'))
    {
        gs.info("Checking issue");
        current.setAbortAction(true);
        gs.addErrorMessage('Testing info');
    }
    else if(count !=0 && task_table.state == '3'){
    current.setAbortAction(false);
    }
}
       
}

},

    type: 'Validationrestrict'
};
 
This log message throws wrong record id :gs.info('case record:' +case_record);
Could you please suggest?

 

 

6 REPLIES 6

Community Alums
Not applicable

Hi @abirakundu23 ,

I checked your code you mention 

gs.info('case record:' +case_record); giving wrong value, may be reason is in your code you are doing  addEncodedQuery like caserecord.addEncodedQuery('u_test=Yes^active=true'); make sure that it is returning only one record, if it is providing multiple record than it will give the sys_id of latest record. So may be you can check in backend that Test is yes and Active is True how many record are present. You can provide more specific filter condition in that case.
 
Please mark my answer correct and helpful if this works for you
Thanks and Regards 
Sarthak

Sandeep Rajput
Tera Patron
Tera Patron

@abirakundu23 Please see if the following works.

 

var Test = Class.create();
Test.prototype = {
    initialize: function() {
    },
    validation:function(){
var checkstatus = false;
gs.info("Checking issue >>> Line6");
var caserecord = new GlideRecord('sn_hr_core_case');
caserecord.addEncodedQuery('u_test=Yes^active=true');
caserecord.addQuery('sys_id',current.getValue('sys_id'));
gs.info("Checking issue >>> Line9");
caserecord.query();
gs.info('Checking the issue case record');
if(caserecord.next())
{
    //var taskrecord = new GlideRecord('sn_hr_core_task');
    //taskrecord.addQuery('parent',current.parent.sys_id);
    gs.info('Checking the validation issue case record');
    var count = 0;
    var case_record=caserecord.sys_id;
    gs.info('case record:' +case_record);
    var task_table = new GlideAggregate('sn_hr_core_task');
    var temp = gs.getProperty('sn_hr_core.ValidationTask');
    task_table.addEncodedQuery('template='+ temp +'^parent=' + case_record);
    task_table.addAggregate('COUNT');
    task_table.query();
    while (task_table.next()) {
        count = task_table.getAggregate('COUNT');
    }
    gs.info('Count is'+count);
    while (task_table.next()) {
    if((count == 0 )|| (count !=0 && task_table.state != '3'))
    {
        gs.info("Checking issue");
        current.setAbortAction(true);
        gs.addErrorMessage('Testing info');
    }
    else if(count !=0 && task_table.state == '3'){
    current.setAbortAction(false);
    }
}
       
}

},

    type: 'Validationrestrict'
};

abirakundu23
Mega Sage

Hi @Sandeep Rajput ,

I have checked , its not working from this line.

if (task_table.next()) {
    if((count == 0 )|| (count !=0 && task_table.state != '3'))
    {
        gs.info("Checking ttion issuehe valida");
        current.setAbortAction(true);
        gs.addErrorMessage('You cannot transfer HR Case as Validation Required is "Yes" and there is no Validation Task created. OR Please Closed complete Validation task before Transfer OR Change Validation Required Field to NO');
    }
    else if(count !=0 && task_table.state == '3'){
    current.setAbortAction(false);
    }
}

abirakundu23
Mega Sage

Hi All,

I am trying to send abort message from "Transfer Case" Workspace Client Script once agent click button.

We have a field called "u_test" is "Yes" & no task is there if click on "Transfer Case" then abort message will be displayed.

OOB UI action Workspace:

function onClick(g_form) {
    var messages = [
        'Transfer Type', 'New HR Service', 'Transfer Case',
        'Warning: Transferring a case closes all related child cases or tasks.'
    ];
    getMessages(messages, function() {
        var sysId = g_form.getUniqueValue();
        var table = g_form.getTableName();
        var gA = new GlideAjax("sn_hr_core.hr_CaseTransferAjax");
        gA.addParam('sysparm_name', 'getTransferFields');
        gA.addParam('sysparm_sys_id', sysId);
        gA.addParam('sysparm_table_name', table);
        gA.addParam('sysparm_subject_person', g_form.getValue('subject_person'));
        gA.getXMLAnswer(openModal);

        function openModal(answer) {
            answer = JSON.parse(answer) || {};
            var fields = [];
            var oneTransferMethod = (answer.transferMethods && answer.transferMethods.length == 1) ? true : false;
            if (answer.transferMethods && answer.transferMethods.length > 1) {
                fields.push({
                    type: 'choice',
                    name: 'reasonChoice',
                    label: getMessage('Transfer Type'),
                    value: (answer.transferMethods && answer.transferMethods.length > 0) ? answer.transferMethods[0].value : '',
                    choices: answer.transferMethods,
                    mandatory: true
                });
            }

            fields.push({
                type: 'choice',
                name: 'newService',
                label: getMessage('New HR Service'),
                choices: answer.services,
                mandatory: true
            });

            var warning = getMessage('Warning: Transferring a case closes all related child cases or tasks.');
            g_modal.showFields({
                title: getMessage('Transfer Case'),
                fields: fields,
                instruction: warning,
                size: 'md'
            }).then(function(response) {

                var transferMethod = (oneTransferMethod) ? answer.transferMethods[0].value : response.updatedFields[0].value;
                var hrService = (oneTransferMethod) ? response.updatedFields[0].value : response.updatedFields[1].value;
           
                var ga = new GlideAjax("sn_hr_core.hr_CaseTransferAjax");
                ga.addParam("sysparm_name", "transferCase");
                ga.addParam("sysparm_transfer_method", transferMethod);
                ga.addParam("sysparm_hr_service", hrService);
                ga.addParam("sysparm_sys_id", sysId);
                ga.getXMLAnswer(saveForm);

                function saveForm(result) {    
                    result = JSON.parse(result);
                    if (!result.error) {
                        g_aw.openRecord(result.table, result.id);
                    } else {
                        g_modal.alert(result.error);
                    }
                                   
                }
            });
        }
    });
}
 
Can someone please help on that? Where need to change in OOB Script to call Script include through Glide Ajax.
This is Script include: 
gs.info("Checking the issue");
var Validationrestrict = Class.create();
Validationrestrict.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    validation: function() {
        var checkstatus = false;
        var casesysid = this.getParameter('sysparm_sys_id');
        gs.info("Checking the validation issue >>> Line6");
        var caserecord = new GlideRecord('sn_hr_core_case');
        caserecord.addEncodedQuery('u_test=Yes^active=true');
        gs.info("Checking the validation issue >>> Line9");
        caserecord.addQuery('sys_id', casesysid);
        caserecord.query();
        gs.info('Checking the issue case record');
        if (caserecord.next()) {

            gs.info('Checking the validation issue case record');
            var count = 0;
            var case_record = caserecord.sys_id;
            gs.info('case record:' + case_record);
            var task_table = new GlideAggregate('sn_hr_core_task');
            var temp = gs.getProperty('sn_hr_core.ValidationTask');
            task_table.addEncodedQuery('template=' + temp + '^parent=' + case_record);
            task_table.addAggregate('COUNT');
            task_table.query();
            while (task_table.next()) {
                count = task_table.getAggregate('COUNT');
            }
            gs.info('Count is' + count);
            while (task_table.next()) {
                if (count == 0) {
                    gs.info("Checking the validation issue");
                   
                    checkstatus = false;
                } else
                    checkstatus = true;

            }

        }
        return checkstatus;
    },

    type: 'Validationrestrict'
});