- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2014 12:54 PM
When I use a record producer and use the applyTemplate function on the current GlideRecord object I end up with two records with the same task number. The Record Producer has a template field, but the template I am using varies depending upon the options chosen during the wizard.
Does anyone know of a work around? I'm having troubles coming up with one.
Update:
I believe the problem is that the Record Producer and GlideRecord.applyTemplate does an Insert. So when I apply the template the current record gets inserted, and then inserted again when the record producer finishes running the code. If there is a way to specify at runtime what template the record producer should use this problem could be easily solved.
Message was edited by: Jason Butz
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2014 05:25 AM
I appears as though my assumption that Record Producers run a current.insert() after running the script may be correct. I looked through the Record Producers in the sandbox instance of ServiceNow at https://sandbox.service-now.com and found that the New LDAP Server Record Producer manually inserted the record and then called current.setAbortAction(true). That gave me the idea to run a current.update() and then abort the action. This ended up working, I no longer get duplicate records.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2014 08:35 PM
Hi Jason,
Could you share the code you are using in the record producer?
Regards,
Mahira
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2014 04:39 AM
Here is the code:
(function(){
var uri = ('change_request.do?sysparm_query=sys_id=' + current.sys_id);
wizard.redirect = uri;
gs.addInfoMessage("Please review the Change Request below and click Request Approval");
//set the change class
var chgClass = getChangeClass();
current.type = chgClass;
current.short_description = wizard.short_description;
current.u_reason_for_change = wizard.change_reason;
current.u_potential_impact = wizard.potential_impact;
current.u_likelihood_of_impact = wizard.likelihood_of_impact;
current.start_date = wizard.change_start;
current.end_date = wizard.change_end;
current.u_peer_approval_group = wizard.peer_approval_group;
if(wizard.peer_approval_group == "") current.u_peer_approval_group = current.assignment_group;
current.requested_by = wizard.requested_by;
current.parent = wizard.parent;
if (wizard.external_ticket_system != '')
{
current.u_external_ticket_system = 1;
current.u_external_ticket_number = wizard.external_ticket_system;
}
else
{
current.u_external_ticket_system = 0;
}
if(wizard.customer_impact == 'yes')
{
var wza = wizard.customer_approval;
if (wza == 'not_required') {
current.u_customer_approval = 9;
}
else if (wza == 'blast') {
current.u_customer_approval = 5;
current.u_customer_approval_by = "Blast Notification"
}
else if (wza == 'approved') {
current.u_customer_approval = 5;
current.u_customer_approval_by = wizard.customer_approval_by;
}
else if (wza == 'not_yet') {
current.u_customer_approval = 1;
}
}
else
{
current.u_customer_approval = 9;
}
if(chgClass == 2) current.u_emg_manager = wizard.emg_manager; // Emergency Change
if(chgClass == 6) current.applyTemplate(wizard.routine_change_template.name);
if(chgClass != 6)
{
current.assignment_group = wizard.assignment_group;
current.assigned_to = wizard.assigned_to;
}
function getChangeClass() {
//Change types
//1 = normal
//2 = emergency
//3 = MAC
//4 = Informational
var selectedClass = wizard.change_class;
//normal
//mac_application
//emergency
var selectedOrg = wizard.change_organization;
//current_user
//internal_cass
//internal_pso
//external_org
if (selectedOrg == 'external_org') {
return 4;
}
else if (selectedClass == 'normal') {
return 1;
}
else if (selectedClass == 'emergency') {
return 2;
}
else if (selectedClass == 'mac_application') {
return 3;
}
else if(selectedClass == 'informational') {
return 4;
}
else if(selectedClass == 'routine') {
return 6;
}
else if(selectedClass == 'comprehensive') {
return 5;
}
}
}())
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2014 04:49 AM
Hi Jason,
Can you try if the code creates only one record if you hard code the template name in the script?
Regards,
Mahira
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2014 05:16 AM
I hard coded a template name and it still created duplicate records.
