Auto populate field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2024 10:47 AM
Hello,
I am currently working on an "issue management" I need "Scripting" for the business rule for the below User story:
When the "Assigned to" field is filled, the "issue manager" field should be auto-populated.
I've included for you below the Screenshot for reference.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2024 11:11 AM - edited 10-15-2024 11:13 AM
Hi @HemaV ,
We can achieve mentioned scenario via a onchange client script instead of Business rule . Please Create Onchange Client Script on Assigned to Field . Please check below Screenshot and Script
I hope you want to Populate Issue Manager with Selected Assigned to Manager
Script -
/**
* Client Script: onChange for "Assigned to" field
* This script populates the "Issue manager" field based on the selected "Assigned to" user.
*
* @param {GlideControl} control - The control that triggered the onChange event.
* @param {String} oldValue - The previous value of the "Assigned to" field.
* @param {String} newValue - The new value of the "Assigned to" field.
* @param {Boolean} isLoading - Indicates if the form is loading.
* @param {Boolean} isTemplate - Indicates if the form is a template.
*/
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
// Exit if the form is still loading or if the new value is empty
if (isLoading || newValue === '') {
return;
}
// If a new user is selected in the "Assigned to" field
if (newValue) {
// Retrieve the user record for the selected "Assigned to" user
g_form.getReference('assigned_to', populateIssueManager);
}
}
/**
* Callback function to populate the "Issue manager" field.
*
* @param {GlideRecord} assignedUser - The user record of the selected "Assigned to" user.
*/
function populateIssueManager(assignedUser) {
// Set the "Issue manager" field to the sys_id of the assigned user's manager
g_form.setValue('u_issue_manager', assignedUser.manager);
}
Result - Whenever some selects assigned to . issue manager will automatically populate with assigned to manager
If my reply helped with your issue please mark helpful 👍and correct ✔️if your issue is resolved.
By doing so you help other community members find resolved questions which may relate to an issue they're having
Thanks,
Astik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2024 11:23 AM
Thank you @Astik Thombare for your response. but I am expected to do this through business rule scripting. Is that something can you help me with?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2024 06:42 PM
Hi @HemaV ,
In this case, we can use a 'before' business rule to achieve the desired outcome. However, if the assigned_to field is changed, the rule will not trigger immediately. It will only execute when the form is saved.
Please refer to the screenshot and the script for the business rule below
Script -
(function executeRule(current, previous /*null when async*/ ) {
current.setValue('u_issue_manager', current.assigned_to.manager);
})(current, previous);
If my reply helped with your issue please mark helpful 👍and correct ✔️if your issue is resolved.
By doing so you help other community members find resolved questions which may relate to an issue they're having
Thanks,
Astik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2024 02:28 AM - edited 10-16-2024 02:31 AM
This scripting is not working When I try to insert and save the form after the "Assigned to" field is filled. "Issue manager" field is not auto-populating. it's showing blank.
Below are my changes evidence