validating workflow object

I've inherited some code form a previous developer.  I wanted to ask about this check when trying to validate a workflow Item - are all three of these checks required, or is this generally the best practice when validating returned results?  

if (workFlow.getItemCount() != 1 || workFlow.getProperty("source_id", "").Length != 32 || workFlow.getPropertyAttribute("source_type", "keyed_name", "").Length < 1)

{
return inn.newError("Error retrieving workflow: " + workFlow.getErrorDetail());
}

Parents
  • Hi David,

    These checks aren't required. Validating any result from an item.apply() or AML Query is a good idea, but not always necessary. Since an AML Query can return any number of items, this check is making sure you're only getting a single item.

    On top of that, it's better practice to perform these kinds of checks within the query. This will both make your code more manageable, and help ensure you're getting exactly what you need from your queries. If your query is generated through code, you could ensure the source_id / source_type are not null by adding the following lines to your "get" item.

    item.setPropertyCondition("source_id","is not null");

    item.setPropertyCondition("source_type","is not null");

    If you're using AML you can add the following:

    <source_id condition="is not null"/>

    <source_type condition="is not null"/>

    I'd also note that the validation checks could be improved. Instead of workflow.getProperty("source_id", "").Length != 32, just use workflow.getProperty("source_id", "") == ""

    AJ

Reply
  • Hi David,

    These checks aren't required. Validating any result from an item.apply() or AML Query is a good idea, but not always necessary. Since an AML Query can return any number of items, this check is making sure you're only getting a single item.

    On top of that, it's better practice to perform these kinds of checks within the query. This will both make your code more manageable, and help ensure you're getting exactly what you need from your queries. If your query is generated through code, you could ensure the source_id / source_type are not null by adding the following lines to your "get" item.

    item.setPropertyCondition("source_id","is not null");

    item.setPropertyCondition("source_type","is not null");

    If you're using AML you can add the following:

    <source_id condition="is not null"/>

    <source_type condition="is not null"/>

    I'd also note that the validation checks could be improved. Instead of workflow.getProperty("source_id", "").Length != 32, just use workflow.getProperty("source_id", "") == ""

    AJ

Children
No Data