I want auto populate watchlist member to another watchlist field

Talari Balateja
Tera Expert

Hi,

 

I have written script to auto populate assigned to based Business Unit. Now I want to auto populate business unit watchlist members to incident table watchlist based on Business Unit.

 

I written script include and client include.

 

script include

var BasedOnBuAutomatingAssignment = Class.create();
// Set the prototype of the class to extend the global.AbstractAjaxProcess object
BasedOnBuAutomatingAssignment.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
// Define a method to check if the class is public
isPublic: function() {
return true;
},

// Define a method to retrieve user attributes based on the provided business unit
getUserAttributes: function() {

var assign;
// Get the 'sysparm_deputedbu' parameter from the request
var dbu = this.getParameter('sysparm_deputedbu');

// Build a query to retrieve the primary internal DIP SPOC for the specified business unit
var query = 'u_primary_internal_dlp_spoc!=NULL^name=' + dbu;

// Create a GlideRecord object for the 'business_unit' table
var grBu = new GlideRecord('business_unit');
// Add the encoded query to the GlideRecord
grBu.addEncodedQuery(query);
// Execute the query
grBu.query();
// Check if a record was found and retrieve the 'u_primary_internal_dIp_spoc' field value
if (grBu.next()) {


assign = grBu.u_primary_internal_dlp_spoc;
}

// Return the assigned user value

return assign;
},
type: 'BasedOnBuAutomatingAssignment'
});

 

 

 

On Change client script

 

TalariBalateja_0-1707987785256.png

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
// Check if the form is still loading
if (isLoading) {
return;

}
// Check if the new value is an empty string
if (newValue === '') {
// Clear the value of the 'assigned_to' field and return
g_form.clearValue('assigned_to');
return;
}
// Create a new GLideAjax instance for making server-side calls
var ga = new GlideAjax('BasedOnBuAutomatingAssignment');
// Add parameters for the server-side script
ga.addParam('sysparm_name', 'getUserAttributes');
ga.addParam('sysparm_deputedbu', newValue);
// Make an asynchronous server call and handle the response with the setAT function
ga.getXMLAnswer(setAT);
}
// Callback function to set the value of 'assigned_to' based on the server response
function setAT(answer) {
g_form.setValue('assigned_to', answer);
//this is for testing
}

Note: I want to auto populate u_backup_team_memebers (Wathclist) to incident table watchlist(watchlist).

 

1 ACCEPTED SOLUTION

in the client script you have written assigned to then how the watchlist will be populated

Best Regards
Aman Kumar

View solution in original post

8 REPLIES 8

Mark Manders
Mega Patron

It it's a one-to-one copy, you can just copy the field itself (current.watch_list = gr.watch_list works for a simple copy action)


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Hi @Mark Manders 

 

I have added given line, but it's not working...

 

TalariBalateja_0-1707989836476.png

 

Hi @Talari Balateja 

change this line as:

assign = grBu.u_primary_internal_dlp_spoc.toString();

 

It should work fine

Best Regards
Aman Kumar

Hi @Aman Kumar S 

 

It's not working for watchlist field.

not reflecting:

TalariBalateja_0-1707990548548.png

 

data table

TalariBalateja_1-1707990748978.png