Auto populate
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2024 09:45 AM
I configured a custom attribute called "Pop location" on the sn customerservice task table, with the reference field set to "site." When an engineer selects a location, you want to populate the assignment field with all the individuals associated with that location.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2024 09:56 AM
Hi @Anusha Medharam ,
You need to create "Assignment field" as Glide List field and create the below script to push values into Glide list field.
(function executeRule(current, previous /*null when async*/) {
// Auto populating the Feature field with the feature records having Product same as current Product selected - This will only happen on the Newly created Client deployment records
var prod = current.u_product;
if (prod != '')
{
var arr = [];
var feat = new GlideRecord('u_product_feature');
feat.addQuery('u_product', current.u_product);
feat.addQuery('u_active', true);
feat.addQuery('u_default', true);
feat.query();
while(feat.next())
{
arr.push(feat.getValue('sys_id'));
}
current.u_feature = arr.toString();
current.update();
}
})(current, previous);
If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!
Thanks & Regards,
Sumanth Meda
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2024 10:17 AM
Hi @Anusha Medharam ,
For auto-populating the assignment field with all individuals associate with that location, you can go for onChange client script on that POP location variable.
OnChange Client Script:
var location = g_form.getValue('pop_location');
var ga = new GlideAjax('RetrieveUsersFromLocation');
ga.addParam('sysparm_name', 'getUsersByLocation');
ga.addParam('location', location);
ga.getXMLAnswer(function(response) {
if (response) {
// Assuming 'assignment' is the field name for assignment in the sn_customerservice_task table
g_form.setValue('assignment', response);
}
Create Script Include (Client Callable):
var RetrieveUsersFromLocation = Class.create();
RetrieveUsersFromLocation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUsersByLocation: function() {
var location = this.getParameter('location');
// Query users associated with the selected location
var userGr = new GlideRecord('sys_user');
userGr.addQuery('location', location);
userGr.query();
var userList = [];
while (userGr.next()) {
userList.push(userGr.getUniqueValue());
}
return userList.join(',');
}
});
In script include you will get all sysIDs. So preferably you can use assignment field as glidelist referrring to user table
HIT helpful & Accept Solution !!