Using XrmServiceToolkit.Soap.Create() to Create a Child Record Upon OnSave of Parent Record

Apr 5, 2012 at 4:41 PM


I'm using XrmServiceToolkit.Soap.Create() synchronously to create child records upon the OnSave form event of the parent record. However, it does not work when creating the parent record because the GUID for the parent record does not yet exist, thus the EntityReference cannot be set.

How would I use this for my purpose (without using a post-event plugin)?




Apr 11, 2012 at 3:55 PM
Edited Apr 11, 2012 at 3:56 PM

Hey Dave.

Ideally, Plug-in will be my approach to solve this since onSave event in JavaScript does not hit the database and create the record yet.

If you really have to do this in JavaScript.

I suppose you could create some logic when on load when the form is opened for update.

Some ideas here:

1. Create a new boolean attribute called "new_childrecordcreated". Put it on the form but invisiable.

2. When the parent record is created, save the new attribute as false (default value or javascript)

3. When the form is opend for update, if this attribute is false, then run your create child records logics.

4. Once the child records are created using XrmServiceToolkit.Soap.Create(), simply set the value to true for the attribute. Therefore, your create logic won't run again in the future.

The problem is if you run the javascript in synchrous mode and there are quite a few child records to be created, this way will affect the performance to just open the page.

Again, this might be your choice if you want to do it. There might be other ways to solve the issue.

Best Regards,


Apr 12, 2012 at 5:01 PM

Hey Jaimie,

Thanks for the suggestion but I decided to go with a plugin. Plus, the XrmServiceToolkit.Soap.Create() function already works fine for creating the child records AFTER the parent record is created without any extra hidden fields, etc.

Thanks again,