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
08-02-2024 04:28 AM
Hi @Tai Vu ,
Any suggestions on how to capture the newly created CHG on u_demand_task table ,u_change field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2024 01:21 AM
Hi @Naveen87
Try this:
function createChange() {
// Create a new GlideRecord for the 'change_request' table
var changeGR = new GlideRecord('change_request');
changeGR.initialize();
// Get the current record's sys_id from the form
var demandTaskId = g_form.getUniqueValue();
// Fetch the demand task record
var demandTaskGR = new GlideRecord('u_demand_task');
if (demandTaskGR.get(demandTaskId)) {
// Copy fields from the demand task to the new change request
changeGR.requested_by = demandTaskGR.requested_by;
changeGR.requested_date = demandTaskGR.requested_date;
changeGR.short_description = demandTaskGR.short_description;
changeGR.description = demandTaskGR.description;
changeGR.insert(); // Insert the new change request
// Update the variable on the form with the new change number
g_form.setValue('change_number_variable', changeGR.number);
} else {
gs.addErrorMessage('Failed to create Change Request: Demand Task record not found.');
}
// Optionally, you can display a dialog with the new change request
var dialog = new GlideDialogWindow('change_request');
dialog.setTitle('Change Request Created');
dialog.setPreference('sys_id', changeGR.sys_id);
dialog.render();
}
// Optionally, you can redirect the user to the newly created change record
action.setRedirectURL(changeGR);
…………………………………………........................................................................................
Mark it helpful 👍and Accept Solution ✅!! If this helps you to understand.
…………………………………………........................................................................................
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2024 03:12 AM
Hi @Satishkumar B ,
Thanks for ur response.
I used your script but nothing is happening.
When UI button is clicked it re-routes to next page(Kind of happen when update button is clicked on incident form).
Do we need script include here?
Is this UI action client callable?
Maybe these are something which are missing.
Please suggest
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2024 11:42 PM
Developers,
Any suggestions on below.
How do I paste the newly created CHG number on Demand task form u_change field?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2024 04:28 AM
Hello Developers,
I'm still trying to get few variable information from Demand table & paste on CHG via DSTASK table.
I have wrote below script but fields which does not present on DSTASK (Present at Demand) are not getting copied at Change.
Also created CHG number is not stored at u_change field on DTASK record post creation.
Any suggestions would be helpful.
function createChange() {
var data = g_form.getReference('parent', popChange);
function popChange(data) {
g_form.setValue('u_origin_of_change', popChange.u_demand_type);
g_form.setValue('requested_by_date', popChange.u_expected_delivery);
// CHG field value == DTASK field value
var encodedQuery = 'short_description=' + g_form.getValue('short_description') +
'^description=' + g_form.getValue('description') +
'^u_service=' + g_form.getValue('u_service') + // Service Offering - CHG :: DTASK values
'^u_supporting_service=' + g_form.getValue('u_task_support') + // Support Offering - CHG :: DTASK values
'^cmdb_ci=' + g_form.getValue('cmdb_ci') +
'^requested_by=' + g_form.getValue('opened_by'); //+
//'^requested_by_date=' + g_form.getValue('u_expected_delivery') +
//'^u_origin_of_change=' + g_form.getValue('u_demand_type');
var dialog = new GlideDialogForm('Create Change', 'change_request');
dialog.addParm('sysparm_query', encodedQuery); //use this line to set value
dialog.render();
}
}