Workspace UI Actions with Popup Dialogs for Parent Record Field Mapping in Child Record Creation

Sandhya Gurram
Tera Expert

Introduction:

In ServiceNow, creating child records often involves manual data entry, which can be time-consuming and prone to errors. However, by leveraging Workspace UI Actions with Popup Dialogs, we can streamline this process by mapping parent record fields to child records efficiently. In this article, we'll explore how to implement this functionality, improving productivity and accuracy within the ServiceNow platform.

UI Action:

Client : true

Onclick: 

Script:

// Code that runs without 'onclick'

// Ensure call to server-side function with no browser errors

if (typeof window == 'undefined')

    createLog();

// Server-side function

function createLog() {

    var ChangeGr = new GlideRecord('change_request');

    ChangeGr.initialize();

    ChangeGr.short_description = current.short_description;

    ChangeGr.description = current.description;

    ChangeGr.parent = current.sys_id;

    ChangeGr.cmdb_ci = current.cmdb_ci;

    ChangeGr.u_software = current.u_software_pkg;

    ChangeGr.start_date = current.sys_created_on;

// Map the required fields

    ChangeGr.insert();

    action.openGlideRecord(ChangeGr);

}

Workspace Form Button: true

Format for Configurable workspace : true

Workspace Client Script:

function onClick(g_form) {

    var fields = [{

        type: 'reference',

        name: 'u_software_pkg',

        label: getMessage('Please select the Software and Version'),

        mandatory: true,

        reference: 'cmdb_ci_spkg',

        referringTable: 'incident',

        referringRecordId: g_form.getUniqueValue(),

        value: g_form.getValue('u_software_pkg'),

        displayValue: g_form.getDisplayValue('u_software_pkg')

    }];

 

    g_modal.showFields({

        title: "Software",

        instruction: getMessage('Please choose "Generic CI" from the dropdown menu if this does not qualify as a software change log.'),

        fields: fields,

        size: 'lg'

    }).then(function(fieldValues) {

        g_form.setValue('u_software_pkg', fieldValues.updatedFields[0].value);

        g_form.submit('create_log');

        g_form.save();

    });

 

}

SandhyaGurram_0-1711007972085.png 

SandhyaGurram_1-1711007972091.png

 

 

SandhyaGurram_2-1711007972096.png

 

By following these steps and customising the code to fit your specific requirements, you can empower users to create child records seamlessly while ensuring data consistency and reliability within your ServiceNow environment.

 

5 REPLIES 5

saichary
Tera Contributor

Thanks @Sandhya Gurram Very Helpful

SK Chand Basha
Giga Sage

Very Helpful article 

Nithin Sai
Tera Contributor

Very Helpful!!!

Vedhavrath_Kond
Tera Guru

Thanks @Sandhya Gurram , it really helps