Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Record Producers creating duplicate records when using applyTemplate

jbutz
Kilo Expert

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

1 ACCEPTED SOLUTION

jbutz
Kilo Expert

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.


View solution in original post

7 REPLIES 7

Chandan23
Tera Expert

Make sure your templae doesn't have the number also. Remove it.


The template does not have the number field in it.


jbutz
Kilo Expert

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.