Topic
  • 4 replies
  • Latest Post - ‏2013-11-08T16:43:05Z by llandale
mcnairk
mcnairk
111 Posts

Pinned topic Changing default value of an attribute

‏2013-11-08T15:20:29Z |

I want to change the default value of an attribute so that new objects have the new default value but withough affecting the existing objects that have the default value. Is it OK to run the following script on all objects in the database (resetting every object to it's current value) before changing the default? The attribute is defined as an enumeration of strings (SITE_A, SITE_B, BOTH, NONE, etc.). I've run a few basic tests and it seems to work...

Thanks,

               Ken.

 

Module m = current

filtering off

Object o

string current_value_of_site

for o in m do

{

current_value_of_site = o."Site"

o."Site" = current_value_of_site

}

Updated on 2013-11-08T16:13:55Z at 2013-11-08T16:13:55Z by mcnairk
  • llandale
    llandale
    3035 Posts
    ACCEPTED ANSWER

    Re: Changing default value of an attribute

    ‏2013-11-08T15:25:10Z  

    Looks good.  Existing objects with a default value will have that explicit value when done.

    However, this command inside the loop is better as it covers rich Text and doesn't waste string table space:

    • set(o."Site", o."Site")    // set(Attr__To, Attr__From)

    -Louie

  • llandale
    llandale
    3035 Posts
    ACCEPTED ANSWER

    Re: Changing default value of an attribute

    ‏2013-11-08T16:43:05Z  

    Default/Inherited discussion.  When an obj-attr value is null then it can APPEAR to have a Default or Inherited value; I think Inherited has precedence over Default.  "Appear" means:

    • You can see it in the GUI
    • string s = o.NameAttr indeed retrieves the Defaulted/Inherited value

    So if the Default value is "Hello" and you see "Hello", you don't know if that value is defaulted to "Hello" or it is set explicitely to "Hello"; but usually you do not care.  If you need to know, there is a command for that:

    • bool     hasSpecificValue(Object,AttrDef)

    which unfortunately forces you to get an AttrDef handle before you can query:

    • AttrDef ad = find(m, NameAttr)
    • bool Inherits = ad.inherit
    • bool HasDefault = (bool ad.defval)   // this "defval" means "has a default value" ...
    • string DefValue = (string ad.defval)  // ... not the same as this "defval", which means "This is the default value"
    • for o in m do
    • {   if (hasSpecificValue(o, ad))    //
    •      then print identifier(o) "\t" NameAttr "\t[" (o.NameAttr) "]\tIs Specific\n"
    •      else print identifier(o) "\t" NameAttr "\tI" (o.NameAttr) "]\ts Blank/Inherited/Defaulted\n"
    • }

    -Louie

  • llandale
    llandale
    3035 Posts

    Re: Changing default value of an attribute

    ‏2013-11-08T15:25:10Z  

    Looks good.  Existing objects with a default value will have that explicit value when done.

    However, this command inside the loop is better as it covers rich Text and doesn't waste string table space:

    • set(o."Site", o."Site")    // set(Attr__To, Attr__From)

    -Louie

  • mcnairk
    mcnairk
    111 Posts

    Re: Changing default value of an attribute

    ‏2013-11-08T16:16:00Z  
    • llandale
    • ‏2013-11-08T15:25:10Z

    Looks good.  Existing objects with a default value will have that explicit value when done.

    However, this command inside the loop is better as it covers rich Text and doesn't waste string table space:

    • set(o."Site", o."Site")    // set(Attr__To, Attr__From)

    -Louie

    Thanks! I was not aware of this version of the set command. I looked thru the DXL manual and it's not obvious...

  • llandale
    llandale
    3035 Posts

    Re: Changing default value of an attribute

    ‏2013-11-08T16:29:41Z  
    • mcnairk
    • ‏2013-11-08T16:16:00Z

    Thanks! I was not aware of this version of the set command. I looked thru the DXL manual and it's not obvious...

    Not in the manual...

  • llandale
    llandale
    3035 Posts

    Re: Changing default value of an attribute

    ‏2013-11-08T16:43:05Z  

    Default/Inherited discussion.  When an obj-attr value is null then it can APPEAR to have a Default or Inherited value; I think Inherited has precedence over Default.  "Appear" means:

    • You can see it in the GUI
    • string s = o.NameAttr indeed retrieves the Defaulted/Inherited value

    So if the Default value is "Hello" and you see "Hello", you don't know if that value is defaulted to "Hello" or it is set explicitely to "Hello"; but usually you do not care.  If you need to know, there is a command for that:

    • bool     hasSpecificValue(Object,AttrDef)

    which unfortunately forces you to get an AttrDef handle before you can query:

    • AttrDef ad = find(m, NameAttr)
    • bool Inherits = ad.inherit
    • bool HasDefault = (bool ad.defval)   // this "defval" means "has a default value" ...
    • string DefValue = (string ad.defval)  // ... not the same as this "defval", which means "This is the default value"
    • for o in m do
    • {   if (hasSpecificValue(o, ad))    //
    •      then print identifier(o) "\t" NameAttr "\t[" (o.NameAttr) "]\tIs Specific\n"
    •      else print identifier(o) "\t" NameAttr "\tI" (o.NameAttr) "]\ts Blank/Inherited/Defaulted\n"
    • }

    -Louie