The CreatorCon Call for Content is officially open! Get started here.

trigger a record in the related list when the form record is created

Madhan27
Mega Guru

HI community,

 

I got struck at a small issue, The ask is as shown in the below screen shot when the below form is created (wm_order)

 

Madhan27_0-1714067429077.png

 

Once the record is created as shown in below, It has to trigger a record on the work task table populating some data. But I am not able to achieve that. I wrote after business rule mapping the location field but the record is not getting created but when we are creating the work task record manually the location field is population with the data which is given in the parent form. 

 

Madhan27_1-1714067606152.png

 

After BR script:

 

/*var gr = new GlideRecord('wm_task');
gr.initialize();
gr.location=current.location;
gr.short_description='Duplicate of work order';
gr.insert();

 

Kindly help me in achieving this.

 

TIA

#FSM

4 REPLIES 4

Astik Thombare
Tera Sage
Tera Sage

Hi @Madhan27 ,

 

The script looks good . not sure why it is not updating . can you try using flow designer it is much more easier and just need to do drag and drop .

 

             If my reply helped with your issue please mark helpful 👍 and correct ✔️ if your issue is resolved.

 

                         By doing so you help other community members find resolved questions which may relate to an issue they're having

 

 

Thanks,

 

Astik

 

 

johnfeist
Mega Sage

Hi Madhan,

 

Assuming that the /* in your first line of code isn't in the script I think you need to look at ACLs, data policies and any BRs on wm_task.  The code that you show looks to be fine. 

 

One thing that ServiceNow is pushing is to do the assignments via setValue() and not by direct assignment

 

gr.setValue("location", current.location);

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster

Bert_c1
Kilo Patron

Besides what johnfeist found (remove the '/*' as the code is commented out). Add 'gr.parent = current.sys_id;' before the insert() so the wm_task is "linked" to the wm_order record.

shanmuk2
Tera Contributor

Hi Madhan Good day!!

Add parent reference in your script and try, it will work.

Ex: current.parent = gr.sys_id;

 

Best Regards 

Shanmuk

 

Please mark my response helpful, if this resolves your issue!!