Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 10:30 AM
HI @lrossy31 ,
Hope you are doing great.
- Create a business rule that triggers on the insertion of the record.
- In the script, use JavaScript to split the string into first name and last name.
- Then, construct a query to find the corresponding user in the user table.
- Finally, set the reference field to the found user.
Reference script for same :
(function executeRule(current, previous) {
// Assuming 'name' is the string field and 'assigned_to' is the reference field.
var fullName = current.name; // Assuming the format is "Last Name First Name".
var nameParts = fullName.split(' '); // Splitting the full name.
var gr = new GlideRecord('sys_user'); // Creating a GlideRecord object for the user table.
gr.addQuery('first_name', nameParts[1]); // Assuming first name is at index 1.
gr.addQuery('last_name', nameParts[0]); // Assuming last name is at index 0.
gr.query(); // Executing the query.
if (gr.next()) {
current.assigned_to = gr.sys_id; // Assuming 'assigned_to' is the reference field.
}
})(current, previous);
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma
Regards,
Riya Verma