URL

La Maga
Tera Contributor

Hi All, I have a requirement to create a UI action that inserts a new record, then opens that new record in a new tab. In workspace  'action.setRedirectURL(recordGR);' works perferctly, but not on the backend.

In the client side script I followed an article I have found here and created an ajax call to insert the record, then open it in a new tab with 'g_navigation.open(url, "_blank");'.

However for some reason the record that gets open in the new tab is not the record inserted, but a different, new record. The URL opened is correct and contains the sys_id of the record inserted, but the actual sys_id of the form opened is different, and it does not have the fields populated that I populated in the ajax method. 
Here is my client callable script include: 
 

 

createTask: function() {
        var taskGR = new GlideRecord('sn_customerservice_task');
        taskGR.initialize();
        taskGR.short_description = 'XYZ';
        taskGR.parent = this.getParameter('sysparm_current_sys_id');
        taskGR.insert();

        var taskGR2 = new GlideRecord('sn_customerservice_task');
        taskGR2.addQuery('sys_id', taskGR.sys_id);
        taskGR2.addQuery('short_description', 'XYZ');
        taskGR2.addQuery('parent', this.getParameter('sysparm_current_sys_id'));
        taskGR2.query();
        if (taskGR2.next()) {
            return taskGR2.sys_id;
        }


    },​

 

Pretty simple, and I even made sure, that the record properly inserted to the database.

Then here is the client side UI Action: 

 

//Client-side 'onclick' function
function openNewTask() {
    //Ajax call to create new task
    var ga = new GlideAjax('SI_NAME');
    ga.addParam('sysparm_name', 'createTask');
    ga.addParam('sysparm_current_sys_id', g_form.getUniqueValue());
    //Open the newly created task in a new tab
    ga.getXMLAnswer(function(answer) {
        alert(answer);
        g_navigation.open("/now/nav/ui/classic/params/target/sn_customerservice_task.do?sys_id=" + answer, "_blank");
    });

}

 

I appreciate any help, thank you.

0 REPLIES 0