create a subtask with scripting

santiago_bergal
Tera Expert

Hello,

 

I am working on a form that has a list collector variable with servers. I need to create a subtask per selected server with a script and the assignment group should be the one hardcoded below.  Below is the script I put together but I'm afraid it is not working. If you have another version for the same functionality, kindly share!

Any help will be appreciated. 

Thank you!

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

// var serverArray = [];

var serverList = g_form.getValue('Server_name');
var servers = serverList.split(',');

for(var i=0; i < servers.lenght; i++) {
var gr = new GlideRecord('cmdb_ci');
gr.query('sys_id', servers[i]);
gr.query();
while(gr.next()){
var grTask = new GlideRecord('sc_task');
grTask.initialize();
grTask.request_item = server[i].sys_id;
grTask.description = "test";
grTask.short_description = "Application Access Request - ";
grTask.assignment_group = 'MY ASSIGNMENT GROUP';
grTask.insert();
}
}

//Type appropriate comment here, and begin script below

}

6 REPLIES 6

I would never put that in a client script. It goes against every leading practice there is.

It's in a runscript in a workflow. I'm open to suggestions 🙂