cancel
Showing results for 
Search instead for 
Did you mean: 

How to delete document links via script?

Former Member
0 Kudos

Hi,

I am trying to write an import lifecycle script to delete all document links for a document say: project. 

I've tried the following code, but it keeps throwing me Indexoutofbound exception, can some one help on why this error happens?

docLinks = doc.getDocumentLinkList();

docLinksSize = docLinks.size();

if(docLinksSize > 0){
for (int i=docLinksSize; i>0; i--){

docLinks.delete(docLinks.get(i-1));

}

}

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Daniel,

same thing here. Trying to delete a doc link collection member throws error:

Cannot cast class ObjectReference to class String

All I do is this

Iterator iter = doc.getDocumentLinkList().iterator();

while (iter.hasNext()) {

doc.getDocumentLinkList().delete(iter.next());

}

Did you find any solution or is there any reply from SAP?

Thanks and regards,

özlem

0 Kudos

Hi

I'm also having the same issue of "Cannot cast class ObjectReference to class String". Can anyone assist if they have a solution

Regards

Dzuni

Former Member
0 Kudos

Hi Dzuni,

not best solution I guess but works:

Surround ONLY delete statement with try catch(empty):

Iterator iter = doc.getDocumentLinkList().iterator();

while (iter.hasNext()) {

....

try{ doc.getDocumentLinkList().delete(iter.next()); }catch(Exception e){}

.....

}

0 Kudos

Hi

Thanks a million. It worked just fine

Regards

Dzuni

Answers (3)

Answers (3)

former_member190023
Contributor
0 Kudos

Have you tried using iterator?

Iterator iter = doc.getDocumentLinkList().iterator();

        while (iter.hasNext()) {

            doc.getDocumentLinkList().delete(iter.next());

        }

PS: The delete() statement is part of AssociativeCollectionIfc so it should work the same for all references...

Former Member
0 Kudos

Hi all,

As a followup to my question above, I rasied an incident to SAP and they believe this could be a defect while executing docLinks.delete() statement for Project class.  Could anyone suggest any other approach that can be taken to delete decoment links in a project?  I mean via scripting.

Thanks in advance.

Former Member
0 Kudos

To add on,  the same code is applied to MA PROCESS_ROW script, it successfully deletes existing document links in MA, but it just does not work in project PROCESS_ROW script. getting indexoutofbound exception.