Skip to content
TheChatArchiveThe Chat Archive
Mistralmistral-medium· Mistral AIHugging Face Arena Human Preference 55K

write a servicenow business rule in javascript that aborts an update to the sys_user…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with gpt-3.5-turbo-1106’s answer.
  1. User

    write a servicenow business rule in javascript that aborts an update to the sys_user table if the email field is changed and is a duplicate of another record

  2. Mistral Assistant

    Here's an example of a ServiceNow Business Rule written in JavaScript that aborts an update to the sys_user table if the email field is changed and is a duplicate of another record:

    (function() {
    
        // Only run this business rule on update
        if (current.operation !== 'update') {
            return;
        }
    
        // Get the old and new values of the email field
        var oldEmail = current.getOldValue('email');
        var newEmail = current.email;
    
        // Check if the email field has changed
        if (oldEmail !== newEmail) {
    
            // Query the sys_user table for any records with the new email address
            var gr = new GlideRecord('sys_user');
            gr.addQuery('email', newEmail);
            gr.addQuery('sys_id', '!=', current.sys_id); // Exclude the current record
            gr.query();
    
            // If a duplicate record is found, abort the update and display an error message
            if (gr.next()) {
                current.setAbortAction(true);
                current.setWorkflow(false);
                gs.addInfoMessage('Error: The email address ' + newEmail + ' is already in use by another user. Please choose a different email address.');
            }
        }
    })();
    

    Note: This is just an example and may need to be modified to fit your specific use case. Additionally, this business rule should be added to the sys_user table and configured to run when a record is updated.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.