Transfer Case functionality is creating transferred case with new number

Jyoti Mehta
Tera Contributor

Hi Everyone,

we have one issue related to HRSD Transfer case custom functionality.

Out of the Box there was “Transfer Case” functionality in which HR Case gets created on New HR Service and old HR Case gets cancelled.

However, in our custom functionality we have renamed the UI Action to “Recategorize”.

On clicking on “Recategorize” UI Action/Button,

  • The Case gets created for New HR Service.
  • Newly created HR Case has the same number as previous HR Case.
  • Attachment gets copy over.
  • Work Notes also gets copied from previous HR Case.
  • Old HR Case gets deleted.

we have UI page i.e; OOB transfer case and one business rule to populate same number on Transferred HR case and delete the old record.

Issue: when we recategorize a case from one HR Service to another then it is creating a new case number and sometimes it does not copied work notes as well. If anyone has any idea about this issue then please help us. 

Thanks in advance!!

Regards,

Jyoti 

 

9 REPLIES 9

Willem
Giga Sage
Giga Sage

Hi Jyoti,

It is best to not use business rule, but take the steps provided here:

https://docs.servicenow.com/bundle/paris-hr-service-delivery/page/product/human-resources/concept/re...

 

In short, you create a new Transfer Case Configuration.

You can use existing Script Includes to assist you in this.

 

That way you do not have issues in timing, what might be the cause of your problem now. As well as issues on upgrading your instance.

Hi Willem,

Thanks for your reply!!

i don't think so there is any issue due to upgrade as we had the same issue before upgrade also. will check the link which has been shared by you and get back to you ( if any help needed)

Thanks,

Jyoti 

 

Hi Willem,

Hope you are doing good !!

we have tried the steps shared by you but it did not work for us. 

Following are the steps which we have tried:

1. Set Reclassify as default

2. Disable Standard

3. Go to HR Case Management > All > HR Cases

Note: Out of the Box there was “Transfer Case” functionality in which HR Case gets created on New HR Service and old HR Case gets cancelled.

However, in our custom functionality we have renamed the UI Action to “Recategorize”.

4. when we Re-categorize the case, case number changed after re-categorization and work notes was also not copied.

can you suggest something to resolve this issue. 

Thanks,

Jyoti 

Hi Jyoti,

 

How important is it to Delete the old HR Case? If it is OK to give it a different number and cancel the OOTB Reclassify option suits all other requirements. If you still want to customize:

The steps you describe do not match the steps that servicenow describes in the docs link I shared with you.

You should not replace the UI Action or use Business rule.

 

The part to look for:

If you are creating a transfer case configuration, you must also create a script include to implement the sn_hr_core HR case transfer extension point.

Refer to the existing script includes as examples:
  • hr_TransferCase
  • ReclassifyCaseTransfer
  • StandardCaseTransfer

 

You should create your own Script Include based on ReclassifyCaseTransfer. Your script include needs to be named as your Transfer Case Configuration name. If that is called Recategorize the Script include name needs to be RecategorizeCaseTransfer. The scripting in there is:

var ReclassifyCaseTransfer = Class.create();
ReclassifyCaseTransfer.prototype = {
    initialize: function() {
    },
	
	/*
	 * Returns the sys_id of configuration record used for enablement and visibility
	 *	
	 * @returns {string} The sys_id of the the corresponding 'sn_hr_core_transfer_case_config' record
	 */
	getConfigurationId: function() {
		return '8885c7bf3b0033003585802b13efc4fc';
	},
	
	/*
	 * Determines whether this transfer method should be selectable for a specific HR Case record.
	 * Keep default value (return true) will not add any case-specific filtering.
	 * 
	 * @param {GlideRecord} grCase - the record of the case to transfer from
	 *
	 * @returns {boolean} Whether or not this transfer method should apply for a specific HR Case record. 
	 */		
	isCaseEligibleForMethod: function(grCase) {
		return true;
	},
	
	/*
	 * Performs the HR Case transfer using this transfer method and provided input data
	 *
	 * @param {GlideRecord} grCase - the record of the case to transfer from
	 * @param {JSON Object} input - Contains properties for specified details required to complete the transfer (e.g. the sys_id of the destination HR Service)
	 *
	 * @returns newRecord {GlideRecord} for the newly created record. 
	 */
	transferCase: function(grCase, inputs) {
		var selectedService = inputs["selected_service"];
		var transferUtils = new hr_TransferCase();
		
		var service = new GlideRecord("sn_hr_core_service");
		if (!service.get(selectedService)) {
			gs.addErrorMessage(gs.getMessage("Could not find selected service"));
			return;
		}

		// Create new case
		var newRecord = transferUtils._createCaseFromService(service);
		var newRecordSysId = newRecord.getUniqueValue();
		var originalRecordSysId = grCase.getUniqueValue();

		// Copy work notes and comments to the new record. Not necessary when a new case number is assigned because
		// old case is still accessible and any new comments will be copied forward into the new case
		transferUtils._copyWorkNotes(grCase, newRecord);
		
		// Copy fields from original case
		transferUtils._copyFields(grCase, newRecord);
		newRecord.hr_service = selectedService;

		if (service.template.toString())
			new sn_hr_core.hr_TemplateUtils().applyBefore(service.template.toString(), newRecord, true);

		if (!newRecord.insert()) {
			gs.addErrorMessage(gs.getMessage("Failed to insert a new case"));
			return;
		}

		var newSysId = newRecord.getUniqueValue();
		newRecord = new GlideRecord(newRecord.getRecordClassName());
		newRecord.get(newSysId);
		
		transferUtils._copyAttachments(grCase, newRecord);
		transferUtils.swapNumber(grCase, newRecord);
		
		// Copy transfer-specific fields
		newRecord.transferred_from = originalRecordSysId;
		grCase.deleteRecord();
		
		// Copy original creation date
		newRecord.sys_created_on = grCase.sys_created_on;
		newRecord.update();
		
		// Copy interaction_related_record(s)
		transferUtils.copyInteractionRelatedRecords(grCase, newRecord);
		
		return newRecord;
	},

    type: 'ReclassifyCaseTransfer'
};