How can i restrict user to update only perticular Field in a table from data source or load data?

Ankit Kumar6
Tera Contributor

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

 

5 REPLIES 5

Tabassum22
Tera Guru

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

 

Hi @Ankit Kumar6 

 

If the above issue is solved. Please accept the solution to help the community members.

 

Thanks & Regards,

Tabassum Sultana 

 

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?

AnkitKumar6_0-1716548781093.png

 

 

Thanks 

Ankit

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);