
- 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-09-2024 07:34 AM
Hi Cirrus,
You're mixing and matching how you assign values to your gliderecord which is why it's not working.
change.parent = current.number; isn't correct, you need to assign the sys_id, not the number.
//ChangeRequest is an OOB Script Include that provides APIs
//for creating changes in conformity to the different change models available
var changeRequest = ChangeRequest.newNormal();
changeRequest.setValue("short_description", current.getValue('short_description'));
changeRequest.setValue("description", current.getValue('u_details'));
changeRequest.setValue("cmdb_ci", current.getValue('u_service'));
if (changeRequest.hasValidChoice('priority', current.getValue('priority')))
changeRequest.setValue("priority", current.getValue('priority'));
changeRequest.setValue("requested_by", current.getValue('caller_id'));
action.setReturnURL(current); //We're not inserted the gliderecord yet, so this prevents accidental UI action clicks causing record creation
action.openGlideRecord(changeRequest.getGlideRecord())
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-08-2024 07:18 AM - edited ‎05-08-2024 07:43 AM
Yes, you can prepopulate your new change using the URL parameters. Just follow this syntax:
sysparm_query=<field to be prepopulated>=<values> and it will be easier to achieve what you need as you already have it working on 80%
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-08-2024 07:39 AM - edited ‎05-08-2024 07:41 AM
You can try with adding more fields in the sysparm_query parameter passed to the URL. Add ^ for every extra field. I just tested it to be sure its still working that way and using /incident.do%3Fsys_id%3D-1%26sysparm_query%3Ddescription%3DMYDESCRIPTION%5Eshort_description%3DSHORTDESC was working just fine.
url.set("sysparm_query" , "^parent=" + current.sys_id + "^description=" + current.description);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-08-2024 07:53 AM
Sorry, I replied before seeing this. That does exactly what we need it to do. Thankyou

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-08-2024 07:49 AM
Thanks Joro, are you able to exemplify please. If I insert in line 4 it does populate the short description, but it stops populating the Parent with the sc_task number
url.set("sysparm_query" , "^short_description=" + current.short_description);
action.setRedirectURL(url.toString()+"");