Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· OpenAIHugging 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-4-0314’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. Assistant

    Certainly! Here's an example of a ServiceNow business rule written in JavaScript that will abort an update to the sys_user table if the email field is changed and is a duplicate of another record:

    (function executeRule(current, previous /*, g*/) {
      // Check if email field is changed
      if (current.email.changes()) {
        // Query for other records with the same email
        var gr = new GlideRecord('sys_user');
        gr.addQuery('email', current.email);
        gr.query();
    
        // Abort update if duplicate email found
        if (gr.hasNext()) {
          gs.addErrorMessage('Email already exists in another record. Update aborted.');
          current.setAbortAction(true);
        }
      }
    })(current, previous);
    

    In this example, the business rule is triggered on the "update" operation for the sys_user table. It first checks if the email field is changed using the changes() method. If it is, a GlideRecord query is performed to find any other records with the same email. If a duplicate email is found, an error message is added using gs.addErrorMessage() and the update action is aborted by setting current.setAbortAction(true).

    Make sure to replace 'sys_user' with the actual table name if you are using a different table.

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