How can i restrict user to update only perticular Field in a table from data source or load data?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-23-2024 01:11 AM - edited ā05-23-2024 02:30 AM
Hi Team,
In the current scenario, the user exports data from the servicenow table into an Excel spreadsheet, makes updates to the spreadsheet, and then loads it back into ServiceNow. The requirement is that when the user uploads the Excel file, only one field in servicenow (suppose field name is Approval )should be updated. If the user makes changes to other columns in the Excel spreadsheet, those changes should not be applied to the ServiceNow table.
How can i do this?please help
Thanks
Ankit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-23-2024 03:27 AM - edited ā05-23-2024 01:15 PM
Hi @Ankit Kumar6,
You can achieve this by the below
- Go to System Import Sets > Load Data in ServiceNow. Create the table or use existing.
- Ensure that the Approval field in your Excel file is mapped to a corresponding field in the import set table.
- Navigate to System Import Sets > Administration > Transform Maps.
- Map only the Approval field: Ensure that you only map the Approval field and not any other fields. This ensures that only the Approval field will be updated in the target table.
- Example: Import Set Table approval field -> Target Table Approval field.
- In the transform map, add a transform script to handle updates only to the Approval field.
// Check if the record already exists in the target table
var existingRecord = new GlideRecord('target_table');
existingRecord.get('sys_id', source.sys_id);
if (existingRecord.isValidRecord()) {
// Update only the Approval field
existingRecord.setValue('approval', source.approval);
existingRecord.update();
}
- Verify the results to ensure that only the Approval field has been updated in the target table.
Please mark it helpful and try to give it a thumbs up if the above helps. Please accept the solution.
Thanks & Regards
Tabassum Sultana
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-23-2024 02:35 PM
If the above issue is solved. Please accept the solution to help the community members.
Thanks & Regards,
Tabassum Sultana
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-24-2024 04:04 AM - edited ā05-24-2024 04:05 AM
Hi @Tabassum22
when i m using above script new record is inserted with empty field value only approval field is populated.
can you help me how can i fix this?
Thanks
Ankit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-25-2024 05:35 AM
Hi @Ankit Kumar6,
The below code will restrict if the new record.
(function runTransformScript(source, map, log, target) {
// Load the existing record from the target table using sys_id from the source (import set) table
var existingRecord = new GlideRecord('target_table');
// Check if the record exists in the target table
if (existingRecord.get(source.sys_id)) {
// Update only the Approval field from the import set
existingRecord.setValue('approval', source.approval);
// Save the changes to the existing record
existingRecord.update();
// Prevent insertion of a new record by setting an invalid value for sys_id in the target record
target.setAbortAction(true);
} else {
// If the record does not exist, log an error or handle accordingly
log.error('Record with sys_id ' + source.sys_id + ' not found in the target table.');
// Optionally, you can abort the insert action to prevent creating a new record
target.setAbortAction(true);
}
})(source, map, log, target);