cancel
Showing results for 
Search instead for 
Did you mean: 

Save Failed error when deleting a BO instance

Paul_Ka
Participant
0 Kudos

Hi Experts,

This is a weird one. 

Summary:

Validation:OnSave - is blocking the deletion of the BO.

Scenario:

I have written a SalesQuote extension with a couple of extra fields. One of the fields is a dropdown list that should have a selection before user can save the BO. This was accomplished using the standard code in the BeforeSave event:

BeforeSave:

if(this.ExampleField.IsInitial())

{

this.allowSave = false;   //allowSave is defined in the BO extension

}

else {this.allowSave= true}

Validation:OnSave:

return this.allowSave;

This is working perfectly fine when saving a new BO instance (salesQuote in this example) or modifying the existing SalesQuote. But I can't delete the BO's anymore from the OWL screen. 

After Selecting a BO in the OWL screen and clicking "Delete" the "Save Failed" error comes up and after refreshing the list the BO is still available.

I have tried a placing the true/false logic in the after modify or even in the OnSave event itself, still won't let me delete the BO.

Any ideas? Do I miss something obvious?

Cheers,

Paul

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Paul,

Afaik when deleting a BO neither AfterModify nor BeforeSave are called.

So you need to make sure your code is working also in the case both of these are not called.

However you wrote you also tried placing the code in the OnSave itself.

My first guess would be this could be related to something else outside of your code so I would verify whether this is really related to your code.

These are just some generic suggestions you might like to try:

  • Does it work correctly if OnSave always returns true?
  • Did you place a breakpoint in the OnSave and tried to debug your code?
    What is the value of the AllowSave Flag upon deletion?

After this you might understand better what is happening.

Best regards,

Ludger

--

Custom development with all4cloud.de

Paul_Ka
Participant
0 Kudos

Ok, done some debugging.

The allowSave is being set correctly in the AfterModify. I can observe this in the debugger when the value changes from false to true. I checked this by setting breakpoints right before the return statement in the Validation:OnSave event.

Another thing I tried was to actually display the value of allowSave in the UI

(Validation:OnSave)


raise testMsg.Create("W",this.allowSave.ToString())

Result:

I was expecting to see "true" instead of X.  Regardless of this I was able to save the SalesQuote.

Now, when I tried to delete the SalesQuote in the OWL screen I ended up with this message:

So it looks like the allowSave variable is not available at the deletion stage?

Former Member
0 Kudos

Hi Paul,

Your findings are correct.

Additional Note: Indicators are internally stored as "X" (true) or as " " (space - false) which is what you see here.

So yes, your valuation indeed prevents the deletion.

Next questions:

  1. How is the AllowSave field initialized? True or false?
  2. Is the code setting the AllowSave (in the AfterModify/BeforeSave events) executed on deletion (use break points to find out)?
  3. Which value does the AllowSave-Field have in the database of the SalesQuote Instance you are trying to delete (use ExecuteQuery from the Repository Explorer to have a look into the data base)?
  4. Background: It is possible that the value of AllowSave is false on disk even if it has been saved - if the SalesQuote has been created before your code has been added.

If some of these questions result in AllowSave having false, you might have to remove the AllowSave field and compute the validation result in a temporary variable inside the OnSave instead.

Best regards,

Ludger

HorstSchaude
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Ludger, Paul,

I can confirm that a deletion of a BO instance does NOT trigger the BeforeSave event nor the OnSave validation.

There is unfortunately no control after the deletion is triggered.
I know we had a lot of effort to get depending objects removed if such cases.

I would love to get a call to BeforeSave.

So, this behaviour must come from something else.

Are you sure, that removing the row is really triggering a deletion?

Can you have a look in the UI Designer?

Bye,

    Horst

Paul_Ka
Participant
0 Kudos

Hello Horst,

But it seems that the deletion does trigger the OnSave event. In my previous example I'm raising a message just before the return statement. That message shows up together with the "Save Failed" once the Delete button has been pressed.  

Did you mean that the OnSave even is triggered but the "return" statement is ignored ? (no validation)

I have not made any modifications to the OWL screen (standard SalesQuote screen).  Only QA and OIF screen have been enhanced with the new fields via extensibility explorer. Is there anything in particular in IU designer to check?

Cheers,

Paul

Former Member
0 Kudos

Hi Paul,

As we both are trying to say: on deletion the OnSave Validation is called but not AfterModify/BeforeSave.

No, the return statement is not ignored.

Thus your code needs to be so that is is working also if no AfterModify/BeforeSave has been called.

That is why I suspected that your default value is false and/or old SalesQuotes created before your code have AllowSave == false.

If possible try to move your code to OnSave without using an extension field.

If this is not possible, make sure all AllowSave fields have the value set to "true" by default.

Best regards,

Ludger

--

Custom development with all4cloud.de

Paul_Ka
Participant
0 Kudos

Thanks for you suggestions Ludger.

1. is initialised False in the AfterModify event, then if the conditions are meet, the allowSave is set to true.  This is executing fine.

2. This is a good point, I can't check this at the moment but there is a chance that the AfterModify gets executed (setting the allowSave back to False) but for some reason the IF statements are no longer working ( possibly due to the associated BO's being removed prior to the deletion of the root???)

3. True

4.Not sure how to verify that.

I think I will try the Tobias suggestion about reversing the logic, so after-modify initalizes the allowSave as true instead of false. Other option would be to do check in the OnSave if the associations are still set.

Anyway, thanks HEAPS to all for your input so far.  Back to studio!

Paul_Ka
Participant
0 Kudos

Ok, I think I understand now.  But last question, since the allowSave is stored with the BO instance and is set to True after the user saves the BO (confirmed by running a query via repository explorer) then why the OnSave fails when I simply do:


return this.allowSave

allowSave is True so the validation should work. 

I will play with the studio now and report back

Former Member
0 Kudos

Hi Paul,

There are two possibilities:

  1. The AllowSave is false for some other reason (e.g. prior initialization)
  2. This is a bug of the platform

My guess goes on the second since I definitely experienced (under rare occasions) something similar: an indicator evaluated to false even though it definitely has been set just one action call earlier to true.

If you can prove that this indicator has to be true (and is true in the database) then open an incident.

Best regards,

Ludger

Paul_Ka
Participant
0 Kudos

After more testing I have found the problem.

The OnSave event is triggered after the BO has been deleted thus the allowSave does not exist anymore. This is confirmed by a break  point just before the return statement.

You can see how the ID along with the other vars have no value.

Solution is to check in the OnSave event if the BO still exists. This can simply be done by checking the ID.


var check = true;

if (this.ID.content != "")     //check if the object still exists / is referenced

{

  if (this.QuotePhase != "")  //check if the mandatory QuotePhase extension field has been set.

  {

  check = true;

  }

  else

  {

  raise SuccessErrorMsg.Create("E");

  check = false;

  }

}

else 

{

check = true;

}

return check;

I think it's enough for today

Big thanks to all for helping me understand the events execution order!

HorstSchaude
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Paul,

Good to hear that your issue is solved.

But that the validation is triggered seems to me like a bug in the buffering:

Somehow the buffer still has the instance and of course triggers all the events and the validation on save.

Regarding the persistence of the "allowSave" flag:

Why don´t you annotate it with [Transient]?

Bye,

   Horst

Former Member
0 Kudos

Hi Horst,

my assumption is because transient annotations do not work with extension bo's 😉

Best regards,

Ludger

--

Custom development with all4cloud.de

Paul_Ka
Participant
0 Kudos

Yep, tried that already. Transient can't be used in extension BOs.

Cheers,

Paul

HorstSchaude
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Paul, Ludger,

Sorry, I mixed this up with an extension node.

Inside such a node is possible.

Sorry,

     Horst

Former Member
0 Kudos

Hi Paul,

I think this can be an lock problem.

If you delete the BO the BO content is also deleted (initial) and so your validation does not allow to save.

Try to combine your validation with an field validation of an Standard element so that your validation starts after an verification that the standard field (e.g. Customer) is not empty.

I know it is possible to save the quote without an customer but this quote is marked for the error.

Best regards,

Tobias

Paul_Ka
Participant
0 Kudos

Hi Tobias,

I'm not sure if I understand, how can I combine my validation with the validation of the standard element?



Currently I run this code in AfterModify before executing some calculation logic:

(QuotePhase is my extension field)

Do you think the problem is caused by the fact the the extension field is "checked" before the standard field? Though once the allowSave is set and the BO is saved the value of the allowSave should be available regardless of the fact that AfterModify is not executed on deletion.


if (this.PayerParty.IsSet())

{

    if (!this.QuotePhase.IsInitial())

      {

      if(this.TotalValues.IsSet()) 

       {

         <execute some calculation here>

        <set allowSave to true>

       }

    }

}

Former Member
0 Kudos

Hi Paul,

I got en better Idea to solve this (First Idea was not the best).

Allow Saving per default and only disallow the save if there is something strange happening.

So if you persist the AllowSave is true if it runs in the delete (Validate) and if you want to save the BO instance and the content is not set it will be set to false -> no save.

Best regards,

Tobias