Topic
  • 5 replies
  • Latest Post - ‏2014-04-28T20:07:52Z by llandale
KBSri
KBSri
104 Posts

Pinned topic Trigger to clear the attribute value to check whether other attribute values are changed after modifying the attribute

‏2014-04-24T08:27:13Z |

Hello All,

I have requirement in which i got stuck in.

I need to clear the value of the attribute "Date" if the value of other attribute ("Type" && "Value") are changed since the attribute  "Date" value has been filled in.

Here is the code I am playing with:

//This function activates the trigger to clear the  date attribute

string strObjectType = ""

void activate_trigger()
{    
    string clearReviewDateDXLCode =
    "    int clear_review_date_flag = 1
    
        Module mod = current Module
        string modname = fullName(mod)
                        
        Regexp imp = regexp2 \"^ *Implemented *$\"
        Regexp sub_dir = regexp2 \"|02_System|03_Subsystems_SYS_SW\"
                
        strObjectType = obj."ObjType"
        
        set(trigPreConPass)
        Trigger    trig = current    
        Object obj = object trig
            
        if (null trig)    
            halt()
            
        AttrDef    ad  = attrdef(trig)
        
        if (null ad || !(ad.name == \"Type\"))
        {
            halt()
        }    
        
        string str = value(Trigger trig)
            
        if(imp str)
        {
            clear_review_date_flag = 0
        }

        if(!sub_dir modname)
        {
            clear_review_date_flag = 0
        }
                
        if((clear_review_date_flag == 1) && (!null(ad = find(current Module,\"Review Date\"))))
        {
            if(obj.\"Review Date\"\"\" != \"\")
            {
                infoBox \"Review Date will be lost if you save your changes!\"
                obj.\"Review Date\" = \"\"
            }    
        }
    
    "  // End of string clearReviewDateDXLCode

    //Script for creation of trigger
        
    string trig_name = "ClearReviewDateTrigger"
    Trigger trig
    
    //The following portion has been commented out since the trigger has already been installed
    /*
    int create_trigger_flag = 1
    for trig in (current Project) do
    {  
        if (name(trig) == trig_name)
        {  
            create_trigger_flag = 0
            break
        }
    }
        
    if(create_trigger_flag == 1)
    {
        trigger(trig_name, project->module->all->attribute->all, pre, save, 5, clearReviewDateDXLCode)
        infoBox "Trigger - ClearReviewDateTrigger - created!"
    }
    */
}
activate_trigger()

Please help. I am not sure how to modify the code to suit the requirement.

  • llandale
    llandale
    3035 Posts

    Re: Trigger to clear the attribute value to check whether other attribute values are changed after modifying the attribute

    ‏2014-04-24T14:23:05Z  

    It would help if you told us the specific errors you are getting.

    Do I read this correctly?  If the user is changing attribute "Type" to the value "Implemented" then you want to erase the value of "Review Date" if it is not already ereased and the user confirms it?

    []  I would either print clearReviewDateDXLCode; or put it in a Notepad file and "readFile()" to get it into the code; while debugging.  But that's because I cannot visuallize escaping with slashes the slashes and quotes.

    [] At the bottom where you "infoBox", I think you want this:

    • if (confirm( \"Review Date will be lost if you save your changes!\\nSave Changes anyway?\")) //
    • then  obj.\"Review Date\" = \"\"
    • else  set(trigPreConFail)

    []   Add slashes to this line:

    • strObjectType = obj.\"ObjType\"\

    [] This looks bad:  if((clear_review_date_flag == 1) && (!null(ad = find(current Module,\"Review Date\")))).  How about

    •  if((clear_review_date_flag == 1) && (!null(AttrDef find(mod,\"Review Date\"))))

    [] I think you need parens.  I'd add sub-drectory slashes:

    -Louie

    On other news

    • move set(trigPreConPass) to the very top
    • I think clear_review_date_flag should be a boolean true/false instead of an integer 1/0.
    • You don't seem to be using variable       strObjectType
    • If you indeed find the trigger in the project, offer ..err.. confirm to remove it.
    • Your trigger level could be [project->module->all->attribute->"Type"]; and then forget the check inside the trigger code.
    • You don't need a Regular Expression for "Implemented".
      • if (str != \"Implemented\")

     

  • KBSri
    KBSri
    104 Posts

    Re: Trigger to clear the attribute value to check whether other attribute values are changed after modifying the attribute

    ‏2014-04-24T17:28:57Z  
    • llandale
    • ‏2014-04-24T14:23:05Z

    It would help if you told us the specific errors you are getting.

    Do I read this correctly?  If the user is changing attribute "Type" to the value "Implemented" then you want to erase the value of "Review Date" if it is not already ereased and the user confirms it?

    []  I would either print clearReviewDateDXLCode; or put it in a Notepad file and "readFile()" to get it into the code; while debugging.  But that's because I cannot visuallize escaping with slashes the slashes and quotes.

    [] At the bottom where you "infoBox", I think you want this:

    • if (confirm( \"Review Date will be lost if you save your changes!\\nSave Changes anyway?\")) //
    • then  obj.\"Review Date\" = \"\"
    • else  set(trigPreConFail)

    []   Add slashes to this line:

    • strObjectType = obj.\"ObjType\"\

    [] This looks bad:  if((clear_review_date_flag == 1) && (!null(ad = find(current Module,\"Review Date\")))).  How about

    •  if((clear_review_date_flag == 1) && (!null(AttrDef find(mod,\"Review Date\"))))

    [] I think you need parens.  I'd add sub-drectory slashes:

    -Louie

    On other news

    • move set(trigPreConPass) to the very top
    • I think clear_review_date_flag should be a boolean true/false instead of an integer 1/0.
    • You don't seem to be using variable       strObjectType
    • If you indeed find the trigger in the project, offer ..err.. confirm to remove it.
    • Your trigger level could be [project->module->all->attribute->"Type"]; and then forget the check inside the trigger code.
    • You don't need a Regular Expression for "Implemented".
      • if (str != \"Implemented\")

     

    Hello Louie,

    Thanks .Your suggestions are always helpful and invaluable.It would make me to code better day by day.

    I should have more clear with the requirement.

    The Review Date attribute must be cleared if the attribute value " Type" and other value of the attribute "Value" is modified or changed since the "Review Date" attribute is filled in.

     

     

  • llandale
    llandale
    3035 Posts

    Re: Trigger to clear the attribute value to check whether other attribute values are changed after modifying the attribute

    ‏2014-04-24T19:22:32Z  
    • KBSri
    • ‏2014-04-24T17:28:57Z

    Hello Louie,

    Thanks .Your suggestions are always helpful and invaluable.It would make me to code better day by day.

    I should have more clear with the requirement.

    The Review Date attribute must be cleared if the attribute value " Type" and other value of the attribute "Value" is modified or changed since the "Review Date" attribute is filled in.

     

     

    If you are triggering on a change to either of these attributes, then we can presume that change happens after any previous change to the Review Date attribute.  So we don't need to examine History.  If you get a qualifying change then erase Review Date if it has a value.

    So you want to erase the object's value of "Review Date" when the module is somewhere underneath one of your two folders the value of attributes "Type" or "Value" changes to something other than "Implemented".

    The problem with the generic trigger is that it will fire for EVERY obj-attr change you make in the project which can be annoying.  Since you have two Attributes, either have 2 triggers (changed the way I said) or do it your way and dynamically see of the Attribute qualifies.  That would look like:

    • if (null ad || !((ad.name == \"Type\") || (ad.name == \"Type\")))

    If you ignore my suggestion for a "confirm", then change the "infoBox" text; attr value "is" erased.

    Also, perhaps this, to prevent "infoBox" when DXL is changing the values:

    • if (inplaceEditing(mod)) then infoBox(...)

    Give it a whirl.

    -Louie

  • KBSri
    KBSri
    104 Posts

    Re: Trigger to clear the attribute value to check whether other attribute values are changed after modifying the attribute

    ‏2014-04-28T14:20:47Z  
    • llandale
    • ‏2014-04-24T19:22:32Z

    If you are triggering on a change to either of these attributes, then we can presume that change happens after any previous change to the Review Date attribute.  So we don't need to examine History.  If you get a qualifying change then erase Review Date if it has a value.

    So you want to erase the object's value of "Review Date" when the module is somewhere underneath one of your two folders the value of attributes "Type" or "Value" changes to something other than "Implemented".

    The problem with the generic trigger is that it will fire for EVERY obj-attr change you make in the project which can be annoying.  Since you have two Attributes, either have 2 triggers (changed the way I said) or do it your way and dynamically see of the Attribute qualifies.  That would look like:

    • if (null ad || !((ad.name == \"Type\") || (ad.name == \"Type\")))

    If you ignore my suggestion for a "confirm", then change the "infoBox" text; attr value "is" erased.

    Also, perhaps this, to prevent "infoBox" when DXL is changing the values:

    • if (inplaceEditing(mod)) then infoBox(...)

    Give it a whirl.

    -Louie

    Thanks as always Louie.

    But i tried your solution for this. I am not able to erase the Review Date value if the value of attributes "Value" or "Type" is changed since the value of "Review Date" is modified.

    if (null ad || !((ad.name == \"Value\") || (ad.name == \"Value\")))

    if (null ad || !((ad.name == \"Type\") || (ad.name == \"Type\")))

    Sorry you have ignore the word "Implemented". This can be of any data which is modified.

    A trigger shall clear the "Review Date" attribute if "Value" attribute or "Type" attribute has been modified since the review date has been filled in.

    Please help.

     

  • llandale
    llandale
    3035 Posts

    Re: Trigger to clear the attribute value to check whether other attribute values are changed after modifying the attribute

    ‏2014-04-28T20:07:52Z  
    • KBSri
    • ‏2014-04-28T14:20:47Z

    Thanks as always Louie.

    But i tried your solution for this. I am not able to erase the Review Date value if the value of attributes "Value" or "Type" is changed since the value of "Review Date" is modified.

    if (null ad || !((ad.name == \"Value\") || (ad.name == \"Value\")))

    if (null ad || !((ad.name == \"Type\") || (ad.name == \"Type\")))

    Sorry you have ignore the word "Implemented". This can be of any data which is modified.

    A trigger shall clear the "Review Date" attribute if "Value" attribute or "Type" attribute has been modified since the review date has been filled in.

    Please help.

     

    I made a typo:

    • if (null ad || !((ad.name == \"Type\") || (ad.name == \"Value\")))

    "A trigger shall clear the "Review Date" attribute if "Value" attribute or "Type" attribute has been modified since the review date has been filled in.".  That sentance can be implemented with some on-demand script.  For an object, review History for the last change to the 3 attributes and erase as needed by comparing dates.

    But you are correctly using a trigger for when Value or Type IS being changed.  Since it is changing right now, we can easily deduce that any current value of Review Date must have been made before right now.  Thus, I suggest that when Value or Type change triggers your code, that you erase Review Date, if it has a value right now.  So I think it better to re-word your requirement:

    "A trigger shall clear the "Review Date" attribute when "Value" attribute or "Type" attribute changes.". 

    I get the feeling that one of us fundamentally does not undestand the other.  Perhaps it is this: as I read your code, it is a trigger that fires when any object attribute value changes; you want it to ignore all changes outside your folder and ignore changes to attributes that are not Value and Type.  If so, then effectively the "event" for the trigger is when those attributes change; specifically before the change (thus it is a "pre" trigger).

    -louie