Map encrypted field value from Record producer

Akshay Jugran
Tera Expert

Guys - We have a encrypted field on case table and we need to map that field with Record producer variable.

After mapping end user is getting error "ErrorInvalid attempt. Encrypted data could not be saved".

 

Please help

Thanks

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@Akshay Jugran 

if the end user is not having the role for that encryption context then that error will come.

how are you mapping the field ? via map to field or using script?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Murtaza Saify
Tera Contributor

Steps to Resolve the Issue

1. Ensure the Record Producer Variable is Mapped Correctly

  • Verify that the Record Producer variable is mapped to the encrypted field on the Case table.

  • Go to the Record Producer configuration and check the Variable Mapping section to ensure the mapping is correct.


2. Check the Encryption Configuration

  • Navigate to System Definition > Tables and open the Case table.

  • Locate the encrypted field and check its Encryption Type:

    • If it uses Field Level Encryption, ensure the field is configured correctly.

    • If it uses Client-Side Encryption, ensure the Record Producer is configured to handle client-side encryption.


3. Validate the Data Format

  • Encrypted fields often require data in a specific format (e.g., Base64 encoded).

  • Ensure the data being passed from the Record Producer to the encrypted field is in the correct format.

  • If the field requires Base64 encoding, you may need to encode the data before saving it.


4. Use a Script to Handle Encryption

If the Record Producer cannot directly handle the encrypted field, you can use a Script to handle the encryption and mapping.

Option 1: Script in the Record Producer's "Script" Field
  1. Open the Record Producer and go to the Script field.

  2. Add the following script to handle the encryption and mapping:

    javascript
    Copy
    (function executeProducer(producer, variables) {
        // Get the value from the Record Producer variable
        var encryptedValue = variables.encrypted_field_variable;
    
        // Create a new Case record
        var caseGR = new GlideRecord('case');
        caseGR.initialize();
    
        // Set the encrypted field value
        caseGR.setEncryptedValue('encrypted_field', encryptedValue);
    
        // Set other fields as needed
        caseGR.short_description = variables.short_description;
        caseGR.description = variables.description;
    
        // Insert the Case record
        caseGR.insert();
    })(producer, variables);