Create UI action on Demand Task table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2024 12:51 AM
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2024 01:16 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2024 03:23 AM - edited 07-31-2024 03:30 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2024 09:37 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2024 03:18 AM