Quantcast
Channel: SCN : Discussion List - SAP Sourcing
Viewing all articles
Browse latest Browse all 1416

Scripting POST_SAVE - does not commit changes

$
0
0

Hello,

I have implemented workflow approval that in case of acceptance move Project phase from Phase 1 to Phase 2.

Now I'm trying to implement functionality, that in case of any change on Project (when it's already in Phase 2) will automaticly get Project to the previous phase (Phase 1).

 

I tried with the following script which I assigned to Project object and POST_SAVE event:

 

prevPhaseList = myProjHome.findValidPreviousPhasesExternalIds(doc);

prevPhase = prevPhaseList.get(0);

 

doc.getIBeanHomeIfc().changePhase(doc, (java.lang.String) prevPhase);

 

After I made changes in Project that was already accepted (in Phase 2) and hit 'Save' the phase switched to Phase 1 which was good. But in fact Project remained in Phase 2. Also if I hit 'Done' and get back to the project it's still in Phase 2.

 

Then I tried with the more extended script - as the follwing:

 

prevPhaseList = myProjHome.findValidPreviousPhasesExternalIds(doc);

prevPhase = prevPhaseList.get(0);

 

doc.getIBeanHomeIfc().upgradeToEdit(doc);

doc.getIBeanHomeIfc().changePhase(doc, (java.lang.String) prevPhase);

doc.getIBeanHomeIfc().save(doc);

myProjHome.downgradeToView(doc);

 

With that one, after 'Save' I get the following message:

 

"The Project has been changed by User03, and your changes cannot be saved. You must discard these changes and reload the document."

 

 

But when I hit 'Done' it keeps right phase (Phase 1) but how to avoid this popup message?

 

I tried to avoid the popup with the following (but I don't find it *nice*):

 

doc.getIBeanHomeIfc().changePhase(doc, (java.lang.String) prevPhase);

 

try{

  doc.getIBeanHomeIfc().save(doc);

}catch( e ){

  doc.getIBeanHomeIfc().save(doc);

}

 

 

I've also tried to assign that script to event VALIDATED but it also doesn't seem to be a good idea as during Save the script is getting into recurrent loop.

 

Any ideas how to solve this problem?

 

Thanks in advance,

 

Best Regards,


Viewing all articles
Browse latest Browse all 1416

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>