Copying a Request

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2012 06:33 AM
I am trying to copy a request record and its related request item as a new request and new related item, keeping all the variables and options from the earlier request only changing the requested for for the new person.
The problem I am running into is creating a unique request number. I tried to follow the code from SNC Guru where he details out how to copy a change request, Copy Change Part 2, but that is not working. When the script does execute, it keeps copying over the same request. I have isolated it down that it is not creating a unique request number.
Here is my code:
/* current is the sc_req_item record I am on. This script runs in the sc_req_item's workflow */
function copyREQ(termClientArray){
//GET USER INFORMATION
var reqFor = new GlideRecord('sys_user');
reqFor.get(termClientArray);
//PREPARE TO COPY THE REQUEST
var parentRequest = new GlideRecord('sc_request');
parentRequest.addQuery('sys_id', current.request);
parentRequest.query();
if(parentRequest.next()){
//COPY PARENT REQUEST TO CHILD REQUEST
var newRequest = parentRequest;
//GET A NEW REQUEST NUMBER
/* I have tried both this method which uses packages... */
newRequest.number = Packages.com.glide.db.NumberManager.getNumber('sc_request');
/* and this method, which is a business rule. */
//newRequest.number = parentRequest.getNextObjNumberPadded()
newRequest.requested_for = reqFor;
newRequest.requested_by = current.opened_by;
parentRequest.insert();
}
}
Any suggestions?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2014 11:16 AM
Check out this community article. Looks to be what you need.
https://community.servicenow.com/thread/155219