"You do not have permission to read the created record" error when Creating a HR CaseDescriptionDue to a race condition and missing validation when submitting HR Cases sometimes HR cases are created with empty case numbers. A user might also see the following error in HR Agent Workspace "You do not have permission to read the created record" Steps to Reproduce Happens intermittently due to a race condition. The best way to reproduce it quickly submit HR Case form in HR Agent Workspace.1) Open Create New -> HR Case via HR Agent Workspace.2) Select an HR service and click create case.3) Notice the error and the case gets created with an empty case number.WorkaroundThe workaround requires editing the script include : hr_CaseCreation (sys_id: 687d7d8deb6f3200a9e7e26ac106fee0). Also, an optional fix script is attached that will update any HR Cases with null numbers by generating new case numbers. Replace the function createTask with the following code (if there are customizations to this function then integrate them and always test on a subprod instance before applying to prod): /** Create a task for given table and fields * @param table String Name of task table to create (can be overwritten by hr_service field) * @param fields Object Map of field objects, eg { 'hr_service': { value: 'SYS_ID' } } * @return Object Object representing created task (empty if didn't create), e.g. { 'table': 'TABLE_NAME', 'sys_id': 'SYS_ID', 'can_read': false } */ createTask: function(table, fields, includeErrors) { var errors = []; var msg = {}; var addError = gs.addErrorMessage; if (includeErrors) { addError = function(msg) { errors.push(msg); }; msg = {errors: errors}; } var template = ''; // Replace @param table with HR Service COE if (fields.hasOwnProperty('hr_service')) { if (fields.hasOwnProperty('opened_for') && fields.opened_for.mandatory && !fields.opened_for.value) { addError(gs.getMessage('Failed to insert record. Opened for value is empty.')); return msg; } var serviceGr = new GlideRecord('sn_hr_core_service'); if (!serviceGr.isValid() || !serviceGr.get(fields['hr_service'].value)) { addError(gs.getMessage( 'Failed to retrieve service. HR Service does not exist for ' + fields['hr_service'].value)); return msg; } table = serviceGr.getElement('topic_detail.topic_category.coe').toString(); template = serviceGr.getElement('template').toString(); } // Create task record from input payload var newTaskGr = new GlideRecordSecure(table); newTaskGr.newRecord(); // Configurable HR workspace uses form in case creation page and it initializes a temp sysId, passing that sysId instead of using a new sysId. The attachments added in rich text field are carried over because the created record and the attachment's table sysId remain same. This field is not present when case is created from UI16 or classic HR workspace if (fields.hasOwnProperty('sys_id')) { var sid = (typeof fields.sys_id === 'object' && 'value' in fields.sys_id) ? String(fields.sys_id.value) : String(fields.sys_id); sid = sid ? sid.trim() : ''; if (sid && sid !== '-1' && /^[0-9a-f]{32}$/i.test(sid)) newTaskGr.setNewGuidValue(sid); else gs.warn(this.type + '[HR createTask] Ignoring invalid sys_id "' + sid + '". Letting insert generate one.'); delete fields.sys_id; } this.setInitialCaseFields(newTaskGr); if (!newTaskGr.isValid() || !newTaskGr.canCreate()) { addError(gs.getMessage('Failed to insert record. {0}', newTaskGr.getLastErrorMessage())); return msg; } // Call applyBefore now so that fields with default values are overwritten by template, but user changes // overwrite template still if (template) new sn_hr_core.hr_TemplateUtils().applyBefore(template, newTaskGr, true); // Set all input fields for (var key in fields) { var ele = newTaskGr.getElement(key); if (newTaskGr.isValidField(key) && ele != null && ele.canRead() && ele.canCreate()) { if (fields[key].setAsDisplayValue) newTaskGr[key].setDisplayValue(fields[key].value); else { newTaskGr.setValue(key, fields[key].value); // Duration fields are not set by setting the element if(ele.getED().getInternalType() != 'glide_date_time') //Adding the particular check to avoid the 'glide_date_time' fields to be set as display value. newTaskGr[key] = fields[key].value; // Journal fields are not set using GlideRecord.setValue } } } // Set priority if VIP and priority not on form if (!fields.hasOwnProperty('priority')) { var userArray = []; if (fields.hasOwnProperty('opened_for') && fields['opened_for'].value) userArray.push(fields['opened_for'].value); if (fields.hasOwnProperty('subject_person') && fields['subject_person'].value) userArray.push(fields['subject_person'].value); if (this.containsVipUser(userArray)) newTaskGr.setValue('priority', String(gs.getProperty('sn_hr_core.hr_vip_default_priority', hr.DEFAULT_HIGH_PRIORITY) || '2')); } if (newTaskGr.assigned_to != '' && newTaskGr.assignment_group != '' && !(new hr_CoreUtils()).hasValidAssignee(newTaskGr)) { addError(gs.getMessage('The assignee is not a member of the assignment group')); return msg; } var sysId = newTaskGr.insert(); if (sysId) { if (!newTaskGr.get(sysId) || !newTaskGr.canRead()) { gs.addInfoMessage(gs.getMessage( 'You do not have permission to read the created record. {0}', newTaskGr.getLastErrorMessage())); return { can_read: false }; } return { table: newTaskGr.getTableName(), sys_id: sysId }; } addError(gs.getMessage('Failed to insert record. {0}', newTaskGr.getLastErrorMessage())); return msg; },Related Problem: PRB1943958