- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2024 07:14 AM
On the Change Request form when I click on the Copy Change button the attachment should be copied over to the new CR form only up to the Review state
When I click the same Copy Change button in the Closed or Cancelled state the attachment should be copied to the new CR
Thanks,
Venkat
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2024 02:37 AM
Hi @Venkat03 ,
This can be achieved, but the most important thing to be mindful is this will be a customization. Going forward you would need to maintain it being a de-merit when we customize things.
To achieve above, please follow the steps below:
1. OOTB there is a method named "copyChangeAttachments" within the script include "ChangeUtilsSNC" which is responsible for copying attachments when Copy Change is being used.
2. To modify this, you would need to override this method as the above one is read only.
3. Navigate to the Script Include named "ChangeUtils" using the below link :
Replace "instance name" with your instance name in above URL
4. Now update this Script include using the script shared below and as shown in screenshot below:
var ChangeUtils = Class.create();
ChangeUtils.prototype = Object.extendsObject(ChangeUtilsSNC, {
initialize: function(request, responseXML, gc) {
ChangeUtilsSNC.prototype.initialize.call(this, request, responseXML, gc);
},
/***************************
*
*Add customer changes below
*
****************************/
copyChangeAttachments: function( /*String*/ srcSysId, /*String*/ targetSysId) {
var isCopyEnabled = gs.getProperty(this.PROP_CHANGE_ATTACH_COPY_ENABLED, 'true') == 'true';
if (isCopyEnabled) {
var gr = new GlideRecordSecure(this.CHANGE_REQUEST);
gr.addQuery('sys_id', srcSysId);
gr.addQuery('state', '!=', 3);
gr.query()
if (gr.next()) {
return this._copyAttachments(gr, targetSysId);
} else {
this.logErr('copyChangeAttachments: Provided Change Request does not exist - ' + srcSysId);
}
}
},
_copyAttachments: function(srcGr, targetSysId) {
var res = [];
if (srcGr.hasAttachments() && this.hasReadWriteAccess()) {
var table = srcGr.getTableName();
res = j2js(GlideSysAttachment.copy(table, srcGr.getUniqueValue(), table, targetSysId));
}
return res;
},
hasReadWriteAccess: function() {
var tableDesc = GlideTableDescriptor.get(this.CHANGE_REQUEST);
return tableDesc.canRead() && tableDesc.canWrite();
},
type: 'ChangeUtils'
});
/********************************************************************
*The function below is written in this way to provide access via the
*signature ChangeUtils.isCopyChangeEnabled() from UI Action -
*'Copy Change' > Condition.
*
*Customers are suggested to override methods inside the body of
*ChangeUtils' object definition.
********************************************************************/
ChangeUtils.isCopyChangeEnabled = function(current) {
var changeUtils = new ChangeUtils();
if (changeUtils.isCopyFlagValid() && changeUtils.isCopyRulesValid(current)) {
return true;
} else {
return false;
}
};
5. Once you have made the changes, for closed state attachments will not get copied using copy change UI Action.
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 11:08 PM