Skip to main content
1-Visitor
May 3, 2013
Question

"cannot convert null to an object" in a triggerscript

  • May 3, 2013
  • 1 reply
  • 6187 views

Hi @all,

i'm now outing me as a non-programmer

We have following problem: in an item were three datefields. The first field should be filled by the user, and the other two fields should be computed by a rule. Because filling a datefield by a computation it is not editable anymore we wanted to use a trigger to do this.

This works fine unless the user doesnt fill the first datefield. Then we get a javascript error:

"Internal Error: undefined: Cannot convert null to an object."

Here comes the code from the triggerscript:

try

{

var issue = bsf.lookupBean("imIssueDeltaBean");

var params = bsf.lookupBean("parametersBean");

var fieldDueDate = params.getParameter("Startfeld");

var CompValue = params.getParameter("Anzahl Tage");

var targetField = params.getParameter("Zielfeld");

}

function main()

{

var StartDate = issue.getNewFieldValue(fieldDueDate);

var StartDate = new Date().setTime(StartDate.getTime()+(CompValue*24*60*60*1000));

issue.setFieldValue(targetField, StartDate); // set field to due date

}

}

The red line is the one which causes the error.

The Trigger-Config has three fields:

  • "Startfeld" (the first datefield),
  • "Zielfeld" (the target datefield)
  • "Anzahl Tage", which holds the Number of days to compute with.

So how we get rid of this Javascript-Error? First we tried to catch an empty field by the trigger-rule with looking for a "Startfeld" != -unspecified-

but this doesnt work. So we tried to get this in the script by an if-statement in the main-function like:

if (fieldDueDate != null)

but this has no effect, this if-Statement is always false.

Other if-Statements were

if (!fieldDueDate)

or

if (!isNaN(fieldDueDate))

are always true, so we never get into the function. Can someone help me, please ? Thanks in advance...

kind regards, Jens


    1 reply

    21-Topaz I
    May 3, 2013

    Hi Jens,

    In situations which usually cause this error, it is because of a blank parameter. When the trigger attempts to pull a value from the parameters defined (in this case 'Startfield'), it finds nothing there. Is the trigger properly configured with all necessary parameters?

    JensN.1-VisitorAuthor
    1-Visitor
    May 6, 2013

    Hi,

    i think it is properly configured. Its a pre-trigger and here is the rule:

    and

    |- Type = <Itemtype>

    |- Startfeld <> Startfeld [new Value]

    + or

    |- Startfeld <> - Unspecified -
    |- Startfeld [new Value] <> - Unspecified -

    So i want to trigger every time the value of "Startfeld" is changed and i want not to trigger if the field is empty. But this is my first problem: the "unspecified"-statement doesnt work, the trigger is always triggering. If this would work, we wouldnt have to handle this problem in the script.

    kind regards, Jens

    21-Topaz I
    May 6, 2013

    Ah I see. You can remove the "Startfeld <> - Unspecified -" part of the rule. This particular piece is checking the value of Startfield before the transaction and because it is looking for non-empty values, the trigger would fire even if it had a value.

    The "Startfield [New Value]" portion is all you need since the New Value element is checking the value at the end of the transaction. If the field started NULL but then was given a value, the trigger will not fire (exactly as expected).

    Hope that helps!