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.
11 replies Latest Post - ‏2013-03-25T16:47:01Z by llandale
cliff.sadler
cliff.sadler
12 Posts
ACCEPTED ANSWER

Pinned topic copying the value of one attribute to another

‏2011-01-14T14:33:53Z |
Like copy attributes, but instead of doing it for the whole module, I need it to copy attribute values for only the objects in my current view. Anyone modify or come up with a script for that?
Updated on 2013-03-25T16:47:01Z at 2013-03-25T16:47:01Z by llandale
  • adevicq
    adevicq
    154 Posts
    ACCEPTED ANSWER

    Re: copying the value of one attribute to another

    ‏2011-01-14T17:16:19Z  in response to cliff.sadler

    Hi,

    Try this:
     

    Object o
    Module m = current
    string fromAttr = "some attribute"
    string toAttr = "some other attribute"
     
     
    for o in m do {
    o.toAttr = probeAttr_(o, fromAttr)
    }
    

     


    Regards,

    Alain

     

    Updated on 2013-12-20T19:26:21Z at 2013-12-20T19:26:21Z by JAntley
  • llandale
    llandale
    2953 Posts
    ACCEPTED ANSWER

    Re: copying the value of one attribute to another

    ‏2011-01-14T18:15:35Z  in response to cliff.sadler

    The "for obj in mod" loop finds currently displayed objects and should work for this particular use. I seem to have a minority opinion about that loop in that I almost always use the "for obj in entire mod" loop, then explicitly reject objets I don't care about, typically "if (isDeleted(obj)) continue" and "if (table(obj) or row(obj) or cell(obj)) continue". I do not want my scripts routinely dependant on the current view, unless the script is specifically designed to be sensitive to that (such as your script).

    There is also an undocumented assignment perm that is superior in every way to retrieving one attr value and assigning it to another:

    string    set(Attr__ To,Attr__ From)
    Use:
    string ErrMess = set(oNew."NameAttr", oOld."NameOtherAttr")
    


    Will accurately copy rich text along with OLE diagrams without wasting space staging the value in memory. Works for objects in different modules. Is basically equivalent to this:
    oNew."NameAttr" = richText(richTextWithOle(oOld, "NameOtherAttr"))

    OK, not "every way" because you get DXL errors if the attr reference doesn't exist. But this solves that problem:

     

    noError()
    Object o = null
    set(o."New", o."Old")
    string Err1 =lastError()
    print "Err1: " Err1
    

     

     

     

    • Louie

     

     

     

    • Louie

     

    Updated on 2013-12-20T19:27:23Z at 2013-12-20T19:27:23Z by JAntley
  • cliff.sadler
    cliff.sadler
    12 Posts
    ACCEPTED ANSWER

    Re: copying the value of one attribute to another

    ‏2011-01-14T18:54:06Z  in response to cliff.sadler
    Thanks for the quick followup
    tightly controlled copy, so the first snippet worked great.
    • llandale
      llandale
      2953 Posts
      ACCEPTED ANSWER

      Re: copying the value of one attribute to another

      ‏2011-01-14T19:56:31Z  in response to cliff.sadler
      You know that "probeAttr_" retrieves raw text, "string probeRichAttr_(Object o, string attrName)" retrieves rich text but not OLE, and "string probeRichAttr_(Object o, string attrName, true)" retrieves rich text with OLE.
      • bullbala
        bullbala
        31 Posts
        ACCEPTED ANSWER

        Re: copying the value of one attribute to another

        ‏2011-01-18T13:06:15Z  in response to llandale
        When we want to retrieve rich text without OLE, can these forms be considered as equivalents ?

        string probeRichAttr_(Object o, string attrName)
        string probeRichAttr_(Object o, string attrName, false)
        • llandale
          llandale
          2953 Posts
          ACCEPTED ANSWER

          Re: copying the value of one attribute to another

          ‏2011-01-18T15:29:38Z  in response to bullbala
          They are in fact the same, the first perm calls the 2nd one just as you suggest.
          See ../lib/dxl/utils/attrutil.inc

          • Louie
          • SystemAdmin
            SystemAdmin
            3180 Posts
            ACCEPTED ANSWER

            Re: copying the value of one attribute to another

            ‏2013-03-22T18:34:41Z  in response to llandale

            I'm trying to use the following to cut OLE objects (1 OLE per object) from the Object Text attribute into an attribute called "LD 2". The script seems like it's cutting the OLE's ok, but it is not populating the "LD 2" attribute. LD 2 is type text just like Object Text.

            Any thoughts?
             

            Object o
            Module m = current
            string fromAttr = "Object Text"
            string toAttr = "LD 2"
             
             
            for o in m do {
            o.toAttr = set(o.fromAttr, o.toAttr)
            }
            

             


            thanks

             

            Updated on 2013-12-20T19:27:49Z at 2013-12-20T19:27:49Z by JAntley
            • SystemAdmin
              SystemAdmin
              3180 Posts
              ACCEPTED ANSWER

              Re: copying the value of one attribute to another

              ‏2013-03-22T18:45:32Z  in response to SystemAdmin
              o.toAttr = set(o.fromAttr, o.toAttr)
              

               


              use just (probably you have also from/to wrong way round)

               

               

               

              set(o.toAttr, o.fromAttr)
              

               

               

               

              • Pekka Mäkinen - http://www.softqa.eu/

               

              Updated on 2013-12-20T19:28:34Z at 2013-12-20T19:28:34Z by JAntley
              • SystemAdmin
                SystemAdmin
                3180 Posts
                ACCEPTED ANSWER

                Re: copying the value of one attribute to another

                ‏2013-03-22T19:48:32Z  in response to SystemAdmin

                you're absolutely right about the flip flop and taking off the prefix. The following copied the OLE from object text to my other attribute just like I wanted.
                 

                //set(oTo."NameAttr", oFrom."NameOtherAttr")
                 
                Object o
                Module m = current
                string fromAttr = "Object Text"
                string toAttr = "LD"
                 
                 
                for o in m do {
                set(o.toAttr, o.fromAttr)
                }
                

                 


                Thanks so much

                 

                Updated on 2013-12-20T19:29:11Z at 2013-12-20T19:29:11Z by JAntley
                • SystemAdmin
                  SystemAdmin
                  3180 Posts
                  ACCEPTED ANSWER

                  Re: copying the value of one attribute to another

                  ‏2013-03-22T19:58:06Z  in response to SystemAdmin

                  and the following will delete the original OLE as well after the copy
                   

                  //set(oTo."NameAttr", oFrom."NameOtherAttr")
                   
                  Object o
                  Module m = current
                  string fromAttr = "Object Text"
                  string toAttr = "LD"
                   
                   
                  for o in m do {
                  set(o.toAttr, o.fromAttr)
                  oleDelete (o)
                  }
                  
                  Updated on 2013-12-20T19:29:38Z at 2013-12-20T19:29:38Z by JAntley
                  • llandale
                    llandale
                    2953 Posts
                    ACCEPTED ANSWER

                    Re: copying the value of one attribute to another

                    ‏2013-03-25T16:47:01Z  in response to SystemAdmin

                    I am guessing that oleDelete(Object) only deletes the 1st OLE in Object Text. Test this with text with 3 OLEs:

                    int  Count = 0
                    bool More  = false
                    while(More) 
                    {  More = oleDelete(o)
                       if (More) print "OLE Deleted\t#" Count++
                    }
                    


                    -Louie

                    Updated on 2013-12-20T19:30:06Z at 2013-12-20T19:30:06Z by JAntley