
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2024 06:54 AM
Hi,
We would like to create a change from a catalog task, and can achieve this simply by using the following script in a ui action:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2024 08:12 AM
Yes, you need to add it on one set(). Like this:
var url = new GlideURL("change_request.do");
url.set("sys_id" , "-1");
//url.set("sysparm_query" , "^parent=" + current.sys_id);
url.set("sysparm_query" , "^short_description=" + current.short_description +^parent=" + current.sys_id);
action.setRedirectURL(url.toString()+"");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2024 06:59 AM - edited 05-08-2024 07:06 AM
Hi @Cirrus ,
Create a UI action on the catalog task table with below script :
(function createChangeRequest() {
var changeRequest = new GlideRecord('change_request');
changeRequest.initialize();
changeRequest.short_description = 'New Change Request';
changeRequest.description = 'Description of the change';
// Set other fields as needed
var sysId = changeRequest.insert();
if (sysId) {
gs.addinfoMessage('Change Request created successfully ');
action.setRedirectURL("/change_request_list.do?sys_id=sysId);
} else {
gs.addinfoMessage('Failed to create Change Request');
}
})();
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2024 07:23 AM
Thanks Sohail. The code is throwing up an error on the following line:
action.setRedirectURL("/change_request_list.do?sys_id=sysId);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2024 07:01 AM
Hey,
An easier method if you just want to direct the user to a pre-filled out record is to use action.openGlideRecord (example below). It's a more familiar syntax style as you effectively create a GlideRecord representation of what you want, without submitting it to the database

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2024 07:45 AM
Thanks Kieran, I tried the following as we arent using a template, but whilst it populated the short description as desired, it no longer populates the Parent with the SCTASK number