Can't create record from workspace UI-action

Hugo Viertotak
Tera Contributor

Hey!
I am currently working on a UI-action for the workspace of a custom app that we are building. The purpose is via a case-record, create a task record without actually leaving the case-record. I decided to use g_modal for this purpose, but I can't seem to get it to work. It executes all info-messages except number 8. No gs.info is shown in the system logs. Anyone that can identify what's wrong?

 

Workspace UI-action

function onClick(g_form) {
    var fields = [{
            type: 'textarea',
            name: 'short_description',
            label: getMessage('Short description'),
            mandatory: true
        },
        {
            type: 'textarea',
            name: 'description',
            label: getMessage('Description'),
            mandatory: true
        },
        {
            type: 'textarea',
            name: 'notes',
            label: getMessage('Notes'),
        },
        { //grupper med skapa/editera roller?
            type: 'reference',
            name: 'assignment_group',
            label: getMessage('Assignment group'),
            reference: 'sys_user_group',
            referringTable: 'x_resk_disclosure_errand',
            referringRecordId: g_form.getUniqueValue()
        },
        { //grupper med skapa/editera roller?
            type: 'reference',
            name: 'assigned_to',
            label: getMessage('Assigned to'),
            reference: 'sys_user',
            referringTable: 'x_resk_disclosure_errand',
            referringRecordId: g_form.getUniqueValue()
        },
        {
            type: 'boolean',
            name: 'secrecy_assessment',
            label: getMessage('Secrecy assessment'),
        }

    ];

    g_modal.showFields({
        title: "Create disclosure task",
        fields: fields,
        size: 'lg',
        cancelTitle: getMessage('Cancel'), // changing the label of cancel button
        confirmTitle: getMessage('Create') // changing the label of Ok button
    }).then(function(fieldValues) {
        var ga = new GlideAjax('x_resk_disclosure.rsDisclosureUtils');
        ga.addParam('sysparm_name', 'createDisclosureTask');
        g_form.addInfoMessage('1');
        ga.addParam('disclosure_errand', g_form.getUniqueValue());
        g_form.addInfoMessage('2');
        ga.addParam('document_type', g_form.getValue('document_type'));
        g_form.addInfoMessage('3');
        ga.addParam('short_description', fieldValues.updatedFields[0].value);
        g_form.addInfoMessage('4');
        ga.addParam('description', fieldValues.updatedFields[1].value);
        g_form.addInfoMessage('5');
        ga.addParam('folder_link', g_form.getValue('folder_link'));
        ga.addParam('notes', g_form.getValue('notes'));
        ga.addParam('masking_required', g_form.getValue('masking_required'));
        ga.addParam('assignment_group', fieldValues.updatedFields[2].value);
        ga.addParam('assigned_to', fieldValues.updatedFields[3].value);
        ga.addParam('secrecy_assessment', fieldValues.updatedFields[4].value);
        g_form.addInfoMessage('6');
        ga.getXMLAnswer(getResponse);
        g_form.addInfoMessage('7');


        function getResponse(response) {
            g_form.addInfoMessage('8');
            action.setRedirectURL(current); //bygg URL
        }
    });

}

 

Script include

HugoViertotak_0-1672136530782.png

 

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

createDisclosureTask: function(disclosure_errand, document_type, short_description, description, folder_link, notes, masking_required, assignment_group, assigned_to, secrecy_assessment) {

        gs.info('H.V - 0');

        disclosure_errand = (disclosure_errand) ? disclosure_errand : this.getParameter('disclosure_errand');
        document_type = (document_type) ? document_type : this.getParameter('document_type');
        short_description = (short_description) ? short_description : this.getParameter('short_description');
        description = (description) ? description : this.getParameter('description');
        folder_link = (folder_link) ? folder_link : this.getParameter('folder_link');
        notes = (notes) ? notes : this.getParameter('notes');
        masking_required = (masking_required) ? masking_required : this.getParameter('masking_required');
        assignment_group = (assignment_group) ? assignment_group : this.getParameter('assignment_group');
        assigned_to = (assigned_to) ? assigned_to : this.getParameter('assigned_to');
        secrecy_assessment = (secrecy_assessment) ? secrecy_assessment : this.getParameter('secrecy_assessment');

        gs.info('H.V - 1');

        var task = new GlideRecord('x_resk_disclosure_task');
        task.initialize();
        task.setValue('disclosure_errand', disclosure_errand);
        task.setValue('document_type', document_type);
        task.setValue('short_description', short_description);
        task.setValue('description', description);
        task.setValue('folder_link', folder_link);
        task.setValue('notes', notes);
        task.setValue('masking_required', masking_required);
        task.setValue('assignment_group', assignment_group);
        task.setValue('assigned_to', assigned_to);
        task.setValue('secrecy_assessment', secrecy_assessment);

        var task_sys_id = task.insert();

        gs.info('H.V - Körs');
        return task_sys_id;
    },

    type: 'rsDisclosureUtils'
});

 

3 REPLIES 3

Taha Habib
Tera Guru

Hello Hugo,

Have you checked the client callable option on the script include?

 


Also, In the script include you are using "this.getparameter", so you can remove arguments from the function, as it is optional.

 

createDisclosureTask: function() {
}

 

 

Hey, thank you for the answer!
Unfortunately, the problem persisted, but I managed to solve it by changing the value of"Accessible From" from "This application scope only"  to "All application scopes". One might think that I was in the same application scope, but it seems that ServiceNow does not share that opinion 🙂 

If you got an answer to why this is the way it is, I would appreciate an explanation.

Hello Hugo,

I am glad to hear that your problem is solved. Frankly, I have seen ServiceNow acting weird at various occasions, so I believe this might be one of them, :-).