Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
8 replies Latest Post - ‏2013-10-31T14:47:08Z by GregM_dxler
braolive
braolive
36 Posts
ACCEPTED ANSWER

Pinned topic Delete obj

‏2013-10-24T18:01:38Z |
Hello,
This may be a silly question, but I'm having trouble understanding the delete function.
You see, I created the function in which I compare two objects with an attribute with common values and the oldest would be deleted.
But the function doesn't work.
I just want to know if the error is in the delete part. Or if I got that right.

Thanks

 

void delete(Object obj1, obj2)
{
 
m = current Module    
string idStr
 
string auxtag2
auxtag2 = obj2."Old tag" ""
 
for obj1 in m do {
 
idStr = obj1."Old tag" ""
 
if (idStr == auxtag2) {
 
if(obj1."Last Modified On" "" < dateAndTime(today)""){
delete obj1
}
if(obj2."Last Modified On" "" < dateAndTime(today)""){
delete obj2
}
}
    }
}
Updated on 2013-10-24T18:02:11Z at 2013-10-24T18:02:11Z by braolive
  • llandale
    llandale
    2943 Posts
    ACCEPTED ANSWER

    Re: Delete obj

    ‏2013-10-24T18:49:05Z  in response to braolive

    Your code has some serious problems nothing to do with "delete(Object)".

    [1] It doesn't make sense to accept "obj1" as a parameter, and then use that variable in a loop.

    [2] You don't want objects in the "current" module, you want objects in the same module as obj2:
    m = module(obj2)

    [3] I think you want to compare the "Last Modified On" date of the two objects; comparing it to "today" will almost always result in deleting both objects.

    [4] The "for o in m do" loop puts you at the mercy of the current view settings, especially the current Filter.  You probably want:
         for o in entire m do
         {  if (isDeleted(o))   continue

    [5] Use "hardDelete(Object)"

    [6] flushDeletions() when done.

    [7] if (!isEdit(m)) then errorBox("Open module edit")

    -Louie

    • braolive
      braolive
      36 Posts
      ACCEPTED ANSWER

      Re: Delete obj

      ‏2013-10-25T12:05:13Z  in response to llandale

      I'm really having difficult in this.

      What I'm trying to do is look for objects that have the same "old tag" attribute and delete the older one. 

      I'm happy to know that the error isn't in the delete part. At least that I got right. But the loop to find the similar ones is where I'm stuck.

       

      But thank you.

      • pommCannelle
        pommCannelle
        41 Posts
        ACCEPTED ANSWER

        Re: Delete obj

        ‏2013-10-25T12:20:51Z  in response to braolive

        ( Hi !!
        euh ... Louie is right, you should modify your code to deal with his remarks ... Then you should think about the management of existing links ... the delete function should return an error if your objects have incoming links ... Feel free to post your code if you are in trouble. o;) )

        • braolive
          braolive
          36 Posts
          ACCEPTED ANSWER

          Re: Delete obj

          ‏2013-10-25T13:28:49Z  in response to pommCannelle

          If you can help...I appreciate it.

          Attachments

          Updated on 2013-10-25T15:32:28Z at 2013-10-25T15:32:28Z by braolive
          • llandale
            llandale
            2943 Posts
            ACCEPTED ANSWER

            Re: Delete obj

            ‏2013-10-28T14:41:57Z  in response to braolive

            I did not run the code.  I'm looking only at function "del()".

            I think you want something like this:

            • Skip skpTags = createString() // KEY 'string' Tag; DATA 'Object' with most recent Tag
            • Skip skpDelete = create()   // KEY and DATA both 'Object'
            • for oCurr in entire mTarget do
            • {  if (isDeleted(oCurr))  then continue
            •     OldTag =  oCurr."Old Tag"
            •     if (null OldTag)    then continue
            •     if (oCurr is otherwise disqualified) then continue
            •     if (find(skpTags, OldTag, oPrev))
            •     {       // we have already encountered a previous object with this Tag 
            •        if (LastDate(oCurr) < LastDate(oPrev)) //
            •        then put (skpDelete, oCurr, oCurr)
            •        else {delete oPrev from skpTags; put oCurr in skpDates; put oPrev in skpDelete}
            •    }
            •    else
            •    {        // first encounter of this Tag
            •       put(skpTags, OldTag, oCurr)
            •    }
            • }      // end finding objects to delete
            •        // GregM is right:
            • for oCurr in skpDeletes do
            • {   noError()
            •     hardDelete(oCurr)
            •     ErrMes = lastError()
            •     report ErrMess
            • }
            • flushDeletions()
            • delete the Skips

            I have doubts that "Last Modified Date" is a suitable condition.  What if someone just modified the wrong object?

            I think you want function lastModifiedTime(Object) instead of o."Last Modified On" (but I've never actually used it)

            -Louie

            -Louie

    • GregM_dxler
      GregM_dxler
      163 Posts
      ACCEPTED ANSWER

      Re: Delete obj

      ‏2013-10-25T13:01:14Z  in response to llandale

      Hello,

      I'm surprised Louie didn't mention to not delete the loop variable obj1 inside the loop.  I think it would work ok if you deleted the object in the loop and then do the flushDeletions after the loop is completed.  The normal practice would be to add it to a skip list and then after the loop is completed, delete the objects in the skip list.

      Greg

      • pommCannelle
        pommCannelle
        41 Posts
        ACCEPTED ANSWER

        Re: Delete obj

        ‏2013-10-31T14:17:17Z  in response to GregM_dxler

        ( well ... the link treatment is missing ... You may have some problem if you try to delete linked objects, and if you don't then you'll have some problems with links without available target.
        I'm affraid you have to delete incoming links before the object deletion ... And outcoming links too if you have links to baselined objects ... o;) )

        • GregM_dxler
          GregM_dxler
          163 Posts
          ACCEPTED ANSWER

          Re: Delete obj

          ‏2013-10-31T14:47:08Z  in response to pommCannelle

          Yes, pommCannelle your right.  Both outlinks and inlinks need to be deleted before the object is deleted.  Outlinks might not be needed to be deleted, but I've seen some problems if we don't do that, so I just make it a habit.

          Of course, in order to delete inlinks, you need to open up the source module in editable mode.

          Another thing to worry about is that when an object is deleted, all of it's children get deleted as well.  So not only do you need to check and delete in/out links in the object but also delete in/out links in the children.  Something that bite me in the past.

          I'll attach a snippet of code where I do object deleting with checking and deleting in/out links.  It is not workable code, as I just copied the pertainent parts.  Note too, that this does not include the use of skip lists.

          Hope this helps,

          Greg

          Attachments