cancel
Showing results for 
Search instead for 
Did you mean: 

Delete attachment via script not working after upgrade

Former Member
0 Kudos

Hi All,

Recently we have upgraded our sourcing system to version 10. We have written script to delete attachment via script. It was working fine but after upgrade we are getting below error:

target exception : at Line: 474 : in file: inline evaluation of: ``import java.util.Calendar; import com.sap.odp.api.common.types.TypeFactory; im . . . '' : .delete ( docLinks .get ( i ) )

Target exception: java.lang.ClassCastException: Cannot cast class com.sap.odp.common.db.ObjectReference to class java.lang.String

Piece of code for attachment deletion:

docLinks = newMA1.getDocumentLinkList();

for(int i=0;i<docLinks.size();i++) {

docLinkLine = docLinks.get(i);

name = docLinkLine.getLinkDocId();

relationship = docLinkLine.getLinkDefinitionObjRef().getDisplayName();

if(name.equalsIgnoreCase("102_OLA_102") && relationship.equalsIgnoreCase("Master Agreement Template")) {

newMA1.getDocumentLinkList().delete(docLinks.get(i));

}

}

Please help us to resolve this issue

Accepted Solutions (0)

Answers (2)

Answers (2)

0 Kudos

Hello Muthu,
I was able to reproduce the problem internally. The ClassCastException shouldn’t be happening. It’s  a bug. Also, I don't believe this issue is related to upgrade to release 10.0. I see the same behavior in 9.0. In my testing, I see that the exception is being thrown but the doclink is in fact deleted from the UI and was able to save the MA successfully. Has this been your experience as well? In any case, I would suggest opening a ticket for this.

Regards,
Vikram

Former Member
0 Kudos

Hi Vikaran,

Same code working fine in Sourcing 9. We didn't got any casting exception and it was deleting the doclinks however after upgrade we are getting the exception,and doclinks are not deleted.

thanks,

Muthu

0 Kudos

Hi Muthu

Has this issue been resolved by SAP? Please assist with advise as I am having the same problem.

Your response is highly appreciated.

Regards

Dzuni

former_member207877
Active Participant
0 Kudos

Hello Prabhakar,

In Earlier versions i.e, before version 10, there is no class for document links(509), but in Version 10 we have a class for Document links and there are few methods available which can be used for your logic.

Try those methods and check.

Also Instead of "newMA1.getDocumentLinkList().delete(docLinks.get(i)); " just give "docLinks .delete(docLinks.get(i));"

and check. Ideally what you have given should work but some times bean shell script behaves wierd.

Regards,

Raj

Former Member
0 Kudos

Thanks Prabhakar!

Early we had docLinks .delete(docLinks.get(i)); to delete the attachment before upgrade and now same is not working. So I have changed the code as above.


Thanks,

Muthu

former_member207877
Active Participant
0 Kudos

After deleting an item in the collection you have to handle that in such a way that iterator should not go for deleted one. i.e, for loop checks for deleted member and throws target exception. Try to break the loop after deleting item and then re-iterate for other checks

Regards,

Raj

Former Member
0 Kudos

Actually only one entry will be in the loop always. Its runs one time and its fails on the delete statement

I tried changing the code and got the error again

Method Invocation docLinks.delete : at Line: 474 : in file: inline evaluation of: ``import java.util.Calendar; import com.sap.odp.api.common.types.TypeFactory; im . . . '' : docLinks .delete ( docLinks .get ( i ) )

Target exception: java.lang.ClassCastException: Cannot cast class com.sap.odp.common.db.ObjectReference to class java.lang.String

former_member207877
Active Participant
0 Kudos

Target exception: java.lang.ClassCastException: Cannot cast class com.sap.odp.common.db.ObjectReference to class java.lang.String


Check in code that some where you were casting object reference to String.

You will get more info in NWA logs


Regards,

Raj