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.
3 replies Latest Post - ‏2013-12-09T09:29:28Z by bungle_77
bungle_77
bungle_77
58 Posts
ACCEPTED ANSWER

Pinned topic Copy enumeration attribute values in objects in defferent modules

‏2013-12-02T11:33:15Z |

Hi,

I have to copy an object and all his attributes from the module A  to the module B. Let's call Xa the object in the module A and Xb the clone object in the module B. The two modules has the same attributes, but it can be that in the module B the value "jjj" of the enumeration attribute types "kkk" is not present

Is there a simple control that  when i try to assign Xb."kkk" = "jjj" the script doesn't crash, but it doesn't assign the value? Should i check for each attribute of each objects i want to copy that the attribute is an enumeration, for each value of the attribute that the value is present also in b?

I need to copy a huge amount of object, so i want to optimize the computation time.

  • GregM_dxler
    GregM_dxler
    163 Posts
    ACCEPTED ANSWER

    Re: Copy enumeration attribute values in objects in defferent modules

    ‏2013-12-02T19:53:19Z  in response to bungle_77

    Hi,

    What you need to do is check and verify the attribute value is valid first before you assign it.  Here is a snipet of code I used to check to see if an attribute value is valid or not.  sAN is the attribute name and sAV is the attribute value.  The curmod would have to be your module B.  If the value is not valid, it will write to the error log.  You can add in an else where you would then copy the attribute value in module B when it is valid.

                   if (exists attribute sAN){ //check if the attribute is there
                      AttrDef ad = find(curmod, sAN) //get attribute name as a definition
                      if (!attributeValue(ad, sAV)) {
                         //value is invalid, so add to error log
                         sError_Log = sError_Log "Error, invalid attribute value"\n"
                         sError_Log = sError_Log "Attribute:" sAN ";  Value:" sAV ";\n"
                      }
                   }

    Hope this helps,

    Greg

  • llandale
    llandale
    2952 Posts
    ACCEPTED ANSWER

    Re: Copy enumeration attribute values in objects in defferent modules

    ‏2013-12-05T18:59:19Z  in response to bungle_77

    First you can trap errors of many DXL commands:

    • noError()
    • o."MyAttr" = "Some Value"
    • string ErrMess = lastError()
    • if (!null ErrMess) then deal with the error

    Too lazy to look myself, but google "CopyAtts.dxl", hopefully version 1.3 or greater.  It will push attr types and defs from one module to another.  It will not, I notice, REPLACE an existing attr, so make sure it is defined correctly before pushing.

    -Louie

    • bungle_77
      bungle_77
      58 Posts
      ACCEPTED ANSWER

      Re: Copy enumeration attribute values in objects in defferent modules

      ‏2013-12-09T09:29:28Z  in response to llandale

      thanks both, you provided me two very yuseful instructions