To save value from deleted record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2023 08:32 AM
Hi Team,
We are working on Operational Resilience module, in that one we are creating Asset for Business services,
On Asset table we have added on custom field, which we are using to track some process.
But Asset records gets refreshed when scheduled job related to Compliance gets runs, in that all old records gets deleted which was created with Relationship with Business service/Process.
And that Relationship records gets created again by same scheduled job.
But here in old records we have custom field with value <true/false>, when new record with relationship gets create, we want to update same custom field value for new record.
How we can same old record data to again paste on new record.
Thanks,
Manisha I
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2023 10:27 AM
HI There,
we can follow the steps outlined below:
Identify the Custom Field:
- First, we need to identify the custom field on the Asset table that holds the value we want to preserve.
Create a Script to Copy Data:
- We will create a server-side script (Business Rule or Script Include) that runs when a new relationship record is created. This script will check if there are any corresponding old records with the same relationship. If found, it will copy the custom field value from the old record to the newly created record.
Attach the Script to Relationship Creation Event:
- We will configure the server-side script to run when a new relationship record is created, ensuring it performs the data copying process.
Here's a sample script (written in pseudo-code) to achieve this:
// Identify the custom field name
var customFieldName = 'your_custom_field';
// Business Rule or Script Include to run on relationship creation
function copyCustomFieldValueOnRelationshipCreation() {
var newRelationship = current; // Assuming 'current' holds the newly created relationship record
var businessService = newRelationship.business_service; // Assuming 'business_service' is the reference field to Business Service
var process = newRelationship.process; // Assuming 'process' is the reference field to Process
var oldValueToCopy;
// Check for old records with the same Business Service and Process
var oldAssetGR = new GlideRecord('asset');
oldAssetGR.addQuery('business_service', businessService);
oldAssetGR.addQuery('process', process);
oldAssetGR.query();
while (oldAssetGR.next()) {
oldValueToCopy = oldAssetGR.getValue(customFieldName);
break; // Assuming there will be only one matching old record
}
// Copy the custom field value to the newly created relationship record
if (oldValueToCopy !== null && oldValueToCopy !== '') {
newRelationship.setValue(customFieldName, oldValueToCopy);
}
}
// Attach the script to the relationship creation event
copyCustomFieldValueOnRelationshipCreation();
Regards,
Riya Verma