cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sukie_y
Helper I
Helper I

[plugin] infinite loop of update record

Hi everybody,

 

I want to register 2 plugins to make a infinite loop of updating field.

Plugin1 monitors the [update] message of cr2ab_folder entity on cr2ab_prop1 attribute and executes on PreOperation stage.

sukie_y_0-1646463535576.png

And here is the source of plugin1:

if (context.Depth > 1) {
    trace.Trace("loop !!!");
    throw new InvalidPluginExecutionException("loop hassei");
}

cr2ab_Folder f = (context.InputParameters["Target"] as Entity).ToEntity<cr2ab_Folder>();
f.cr2ab_prop2 = f.cr2ab_prop1;

Plugin2 monitors the [update] message of cr2ab_folder entity on cr2ab_prop2 attribute and also executes on PreOperation stage.

sukie_y_1-1646463645503.png

And here is the source of plugin2:

if (context.Depth > 1) {
    trace.Trace("loop !!!");
    throw new InvalidPluginExecutionException("loop hassei 。");
}
cr2ab_Folder f = (context.InputParameters["Target"] as Entity).ToEntity<cr2ab_Folder>();
f.cr2ab_prop1 = f.cr2ab_prop2 + 1;

When I change the prop1 on form to 10, then prop2 will be 10 and the prop1 will be 101, And I am sure the plugin1 and plugin2 is only executed one time. 

I am confused why the infinite loop error did not happen??

 

The question is :

1, Although I changed only the prop2 value in plugin1, the prop1 is also set in the variable f. Why it does not triger the Update message of prop1 when the system updates the [folder] entity on MainOperation stage?

2, If the update of prop2 happened in plugin1 trigered the plugin2, why the update of prop1 did not triger the plugin1 again?

3, If I change the plugin1 to below:

if (context.Depth > 1) {
    trace.Trace("loop !!!");
    throw new InvalidPluginExecutionException("loop hassei");
}
cr2ab_Folder f = (context.InputParameters["Target"] as Entity).ToEntity<cr2ab_Folder>();
trace.Trace("not loop !!");
f.cr2ab_prop2 = f.cr2ab_prop1;
service.Update(f);

I got the infinite loop error ,

sukie_y_4-1646465637706.png

but the trace log will never stop ......

You can see the message is outputted per minute and paired,  one is "loop !!!" and one is "not loop !!"

sukie_y_3-1646465553664.png

I know the service.update(f) makes the error, but when the dialog is showed, the plugin should be stopped by system, why the execution continues??

 

Thank you very much!

Any reply or web resource will be appreciated !!

 

Best regards

justin

12 REPLIES 12
sukie_y
Helper I
Helper I

Could any MS supporter explain the question 3? ......

Should I create a support ticket?

ansrikanth
Resolver III
Resolver III

Hi, Sorry, took a bit of time to write the plugin my self.. finally able to do that.. 

here is my code.. exactly like yours.. 

ansrikanth_0-1646947826415.png

and I don't see it doing the loops like how it is for you.. here is my trace log.. 

ansrikanth_1-1646947905863.png

 

exactly what is expected.. 1st time not loop and then in loop.. 

 

It's all working as expected to me, which leaves me doubting if you have any other workflows/flows/plugins doing the update again and again causing this issue at your end?.. 

 

Thank you

-Srikanth

 

 

Hi @ansrikanth 

Thank you ! It is very kind of you.

Because you used late bound, I try my code with late bound style, but it is still showing the error logs. So I try to use the same table "contact" as you used it, and by coincidence..... my contact form has same JS code to show a dialog when save,  So, finally, I realized that it is the auto save !

The form is continuously saved even there is a error.....It is not a plugin problem. 

 

Thanks you for the help !!!

 

Best Regards

Justin

Helpful resources

Announcements
Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Super User 2 - 2022 Congratulations

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Government Carousel

New forum: GCC, GCCH, DoD - Federal App Makers (FAM)

In response to the unique and evolving requirements of the United States public sector, Microsoft has created Power Apps US Government.

Users online (2,525)