Create UI action on Demand Task table

Naveen87
Tera Guru

Hello Developers,

 

I want to create a UI action button 'create change' on a custom table called 'u_demand_task'.

It should be on same page with a pop-up dialog box. Change should fetch most of the details from Demand task record.

Details like, The following fields should automatically be copied from the Demand task ticket to the CR.
- Requested by, - Requested date, - Short description, - Description.

Once change is created, we stay on same page & change number gets updated on the variable available on the form.

 

Naveen87_0-1722411851275.png

 

function createChange(){

var dialog = new GlideDialogForm('Create Change', 'change_request');

var changeGR = new GlideRecord('change_request');
changeGR.initialize();
changeGR.short_description = // This should be copied from Demand task
changeGR.description = // This should be copied from Demand task
changeGR.insert();

dialog.render();
}

// Optionally, you can redirect the user to the newly created change record
action.setRedirectURL(changeGR);

 

I have wrote something. I don't think it's correct . Any Guidance & help is much appreciated.

Thank you.

9 REPLIES 9

Tai Vu
Kilo Patron
Kilo Patron

Hi @Naveen87 

To open the GlideDialogForm with pre-populated values, you can use the sysparm_query parameter.

Sample below.

function createChange() {
	var encodedQuery = 'short_description=' + g_form.getValue('short_description') + '^description=' + g_form.getValue('description');
    var dialog = new GlideDialogForm('Create Change', 'change_request');
	dialog.addParm('sysparm_query', encodedQuery); //use this line to set value
    dialog.render();
}

 

Cheers,

Tai Vu

Hi @Tai Vu ,

Thank you for the response.

This works. 

I need to fetch few more details but these are present on Demand table rather than Demand task.

Requested by/Opened by & Requested date/created.

Can you please guide me on this,

 

Change was created. I want to capture that on variable at form level.

Naveen87_0-1722421824725.png

 

 

 

Hi @Naveen87 

You can use getReference(String fieldName, Function callBack) to get the field value from a reference record.

Sample below.

function createChange() {
    g_form.getReference('demand', populateChange);

    function populateChange(demand) {
        var encodedQuery = 'short_description=' + g_form.getValue('short_description') + '^description=' + g_form.getValue('description');
        var requestedBy = demand.getValue('requested_by'); //get demand's field value
        //now you can set the encodedQuery and open the dialog.
        var dialog = new GlideDialogForm('Create Change', 'change_request');
        dialog.addParm('sysparm_query', encodedQuery); //use this line to set value
        dialog.render();
    }
}

 

There are also OOTB UI Action to create change request from a record such as Incident (refer to below URL), you can consider to mimic these ones.

URL: https://<instance_name>.service-now.com/sys_ui_action.do?sys_id=30c9566dc61122740030e173564c1c74

 

Cheers,

Tai Vu

Hi @Tai Vu ,

How do I paste the newly created CHG number on Demand task form?

Naveen87_0-1722507475945.png