Often times you will have users who open an Incident that does not fit the criteria for an Incident. Rather, their Incident should actually be a Request, a Problem, or some other type of task. Developers then face the task of opening a new record of the correct type, moving the information over from the Incident, and closing the Incident along with any other process required as per the workflow. If you have to do this manually multiple times a day, it can get cumbersome fairly quickly.
ServiceNow offers a host of APIs that can assist in manipulating data. We can use a few of these to create a simple one-click process to make incident-conversion a simple job.
First off, we must identify how this process will be used:
1. You identify an incident that should be converted (we'll use Request as the target conversion type, but you can adapt this process to fit your needs)
2. You click a button on the form that will start the conversion process
3. You're taken to the newly converted record
* DISCLAIMER: This is a customization that is not available out of box. Therefore, it is the implementers responsibility to fix any issues that may occur. ServiceNow Support cannot assist in fixing any issues with this process as they are considered out of scope. Please conduct thorough testing in a test instance before moving to a live production environment.
In total, this process will consist of one UI Action and one Client Script. You can obviously add more if you require.
For the UI Action, this will be on the Incident table. I will set it to be a Form button, visible on existing records, and have it run on the server ('Client' is not checked)
For the UI Action script, you just have to provide the URL for the 'new' record form you are converting to (Request in this case) and redirect the user to that form. Pass along a new custom parameter as well with the sys_id of the Incident.
Save the UI Action. Go to an existing Incident (anyone is fine, we have not specified that the record should be closed yet). On the Form header, your new UI Action should be displayed. Click it and you should be redirected to the 'new' Request form. You should also see the custom parameter in the URL along with the sys_id for the Incident. Make sure this is working before moving on to the client script.
Now for the 'conversion' process. This really is nothing more than moving each field value from the Incident into the new record, one by one. We'll use the GlideRecord and GlideForm APIs to accomplish this. You can find link to the documentation for both below in the Additional Information section.
Create a new Client Script on the Request table (sc_request). Set the 'UI Type' to Desktop and 'Type' to onLoad.
Below is the script. Read through the code (along with the comments) to better understand the process.
You will notice that the code does not close the old Incident. This is intentionally left out as it is very possible that the conversion process could've been started on accident (say you clicked the button on accident). The incident should only be closed once the new Request has been looked over and confirmed to be correct. Then once it is submitted, the old Incident should be closed (maybe also leave a work note saying it's been converted to a Request, along with the request number).
*Note: Incident to Request is not a like-for-like conversion. There are certain fields OOB for Incident that do not have an equivalent on Request. You will need to evaluate what to do with this data so that you have all the required information on the new Request record.
That should do it. Save the client script and go back to an Incident. Click the Convert button on the form header and you should be redirected to a new Request form that will populate the fields with information from the Incident you're converting from.