- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2017 09:18 PM
Hi All,
I have a client script that will generate a change task when a communication checkbox is checked.But It is creating duplicate tasks each time user update something in the change request. How can i change this to make just create a task ticket when users check u_communication script. It should check if there is any exiting task for communication and create one if none, when user checked the u_communication.
function onSubmit() {
//Type appropriate comment here, and begin script below
var comm = g_form.getValue('u_communication');
var ct = new GlideRecord("change_task");
if (comm == 'true') {
ct.initialize();
ct.short_description = 'Process Communication Mail Out request';
ct.description = g_form.getValue('description');
ct.assignment_group = "244690cf37b1d600b8f3c97a43000ef8";
ct.change_request = g_form.getUniqueValue();
ct.insert();
}
}
Solved! Go to Solution.
- Labels:
-
Change Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2017 09:40 PM
Hello Sarasaamani,
Any reason you want to do this at client side? It's not a best practice to make I would recommend you to create an AFTER business rule and set the filter conditions to trigger it only when communication field is modified. Please refer the below script and modify it as per your req.
var ct = new GlideRecord("change_task");
ct.addQuery('change_request', current.sys_id);
ct.addQuery('short_description', 'Process Communication Mail Out request')
ct.query();
if(!ct.next())
{
ct.initialize();
ct.short_description = 'Process Communication Mail Out request';
ct.description = current.getValue('description');
ct.assignment_group = "244690cf37b1d600b8f3c97a43000ef8";
ct.change_request = current.sys_id;
ct.insert();
}
https://wiki.servicenow.com/?title=GlideRecord

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2017 09:40 PM
Hello Sarasaamani,
Any reason you want to do this at client side? It's not a best practice to make I would recommend you to create an AFTER business rule and set the filter conditions to trigger it only when communication field is modified. Please refer the below script and modify it as per your req.
var ct = new GlideRecord("change_task");
ct.addQuery('change_request', current.sys_id);
ct.addQuery('short_description', 'Process Communication Mail Out request')
ct.query();
if(!ct.next())
{
ct.initialize();
ct.short_description = 'Process Communication Mail Out request';
ct.description = current.getValue('description');
ct.assignment_group = "244690cf37b1d600b8f3c97a43000ef8";
ct.change_request = current.sys_id;
ct.insert();
}
https://wiki.servicenow.com/?title=GlideRecord
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2017 04:32 PM
Hi Pradeep,
I used BR earlier and it didn't work for me.Therefore, i tried with client script, might be something wrong with my script, your script working well, Thank you.