workspace modal window

pratapdalai
Tera Contributor

On selection of CI on incident form within the workspace, a modal(UI Builder modal component) window should be opened. anybody has worked on such requirement.

5 REPLIES 5

Abhay Kumar1
Giga Sage

@pratapdalai To open a modal window on selecting a Configuration Item (CI) in the incident form within ServiceNow’s workspace, you can use a Client Script or UI Action with an onChange event or an event handler in the workspace to trigger the modal.

Can you please explain "UI Action with an onChange event "  ,Could you please  tell me what event to be used here

@pratapdalai Use an onChange Client Script on the cmdb_ci Field, 

in ServiceNow Workspace, you can use an onChange Client Script to detect when the CI field is updated.

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

// Ensure the script only runs in Workspace
if (typeof g_form.isServiceWorkspace !== 'undefined' && g_form.isServiceWorkspace()) {
// Use a Workspace modal API to open the modal window
openCIModal(newValue); // have to define in workspace
}
}

Define the openCIModal Function for Workspace

Create the openCIModal function to handle the modal in Workspace:

 

function openCIModal(ciSysId) {

    const modalOptions = {

        title: 'CI Details',

        size: 'lg', // Options: 'sm', 'md', 'lg', 'xl'

        sysId: ciSysId,

        table: 'cmdb_ci', // Table to load the CI record details

        recordView: 'workspace-modal' // Ensure you have a view configured for the modal if needed

    };

 

    // Workspace uses the action modal, this function opens a record in a modal window

    const modalAPI = window.top.GlideModalHandler.getModalWindowInstance('snRecordPreview', modalOptions);

    modalAPI.open();

}

 

Just one note: ServiceNow Workspace's GlideModalHandler API, which is a Workspace-specific API for handling modals. And provided solution also depends on what version of workspace you are.

Hope this will help you.

 

 

Tried your code above and in SOW it shows "normal flow" as the alert

Roger11_0-1730941621520.png