Siebel Code Challenge – #10

UPDATED: Well done Rick for spotting this one! It is considered bad practice to return from a finally block – the behavior of the code is unpredictable, based on the route the code takes and whether an exception is thrown or not. Here’s some further reading on the subject. If an exception must be thrown, the return should happen outside of the try…catch. If the function must return a value, the catch should return a value, for example -1, while suppressing (not throwing) the exception.

Really quick one today! I found this in loads of code at my latest project – can you identify the problem?

function CodeChallenge10()
{
  // Declare variables
  var boContact, bcContact;
  var numContact = 0;

  try
  {
    // Instantiate new BC instance
    boContact = TheApplication().GetBusObject("Contact");
    bcContact = boContact.GetBusComp("Contact");
    with (bcContact)
    {
      // Create query context
      ClearToQuery();
      SetViewMode(AllView);
      ExecuteQuery(ForwardOnly);

      numContact = CountRecords();

      return numContact;
    }
  }
  catch(e)
  {
    // Call the custom LogError function to write error to error log
    LogError("Woops, an error has occurred!");
  }
  finally
  {
    // Destroy objects
    bcContact = null;
    boContact = null;
    return numContact;
  }
}

Answers below, please!

VN:F [1.9.17_1161]
Rating: 0.0/10 (0 votes cast)

Siebel Code Challenge – #9

UPDATED: Thanks to Rick for spotting this one! The Today() function returns today’s date without a time component. As there is specialised class validation functionality all over the Action BC, the Workflow will fail if the planned start date is any time today – regardless if it’s before the current time or not. Using the Timestamp() function, within the operation step, will achieve the result expected by the developer.

By special request from Rahul, I give you Siebel Code Challenge #9 – Return of the Code Challenge!

This is something I came across recently – you need to think about the context of vanilla validation in the Action BC to realise why this Workflow isn’t quite right.

This is such a simple mistake but one that can really affect the logic that the developer has in mind. Comments and answers below, please!

VN:F [1.9.17_1161]
Rating: 0.0/10 (0 votes cast)

Siebel Code Challenge – #8

UPDATED: Once again, Rahul has spotted the issue. In this case, the developer has used an exception connector to connect the exception handling Business Service to the End step. This should be a default (black) connector, not the exception (red) connector.

Interestingly, the workflow will still run through but the exception handling step itself will raise an exception that will be thrown out of the workflow!

A REALLY easy one today! When maintaining or reviewing code and configuration, do not underestimate the stressed and hurried developer. This is something I came across a lot in a previous engagement and it’s something that one developer had got wrong in their head and propagated around the system. A real pain to tidy up!

Answers in the comments box below please!

VN:F [1.9.17_1161]
Rating: 0.0/10 (0 votes cast)

Siebel Code Challenge – #7

UPDATED: Thanks to Maurice for posting the correct answer, in addition to spotting my ‘deliberate’ mistake of failing to add a ‘default’ branch to the ‘Records?’ decision step!

The issue is that the process property ‘Valid’ is updated each time a record is assessed – the net result is that the Workflow property will only ever contain the result of the last record processed. It is highly likely that this behaviour is undesirable. A working solution would be to default the property to ‘Y’ then drop out of the loop the moment a record returns ‘Invalid’, setting the process property to ‘N’. This would also prevent processing of any additional records should an invalid one be found.

Another workflow for you today. This is a logic error that I came across recently – it looks innocuous but the impact could be quite significant:

The Workflow outputs the ‘Valid’ property, for use by the calling process to determine whether all contacts queried were valid or not. If you spot the issue with this workflow, post below!

VN:F [1.9.17_1161]
Rating: 8.0/10 (1 vote cast)

Siebel Code Challenge – #6

UPDATED: Well, Ranjith wins again! ForwardBackward removes duplicates from the record set returned while ForwardOnly does not. As such, if there’s a dodgy join in the BC, which returns more than one record, then the record counts will actually differ. This type of issue raises it’s head when traversing record sets in code using ForwardOnly, having seen what should be the same record set in the UI – however, Siebel uses ForwardBackward to populate applets, so the records seen may be different. Nice one Ranjith! :)

An interesting one today. I came across this while debugging an issue and it revealed something about some Business Component methods that I didn’t know. I’ve been in the Siebel business for nearly 13 years and I’m still learning! Note that this is a bit of an ‘odd’ one and you may need to open your mind a bit as to how I’ve presented it.

function CodeChallenge6(Inputs, Outputs)
{
  // Declare variables
  var boContact, bcContact;
  try
  {
    // Instantiate new BC instance
    boContact = TheApplication().GetBusObject("Contact");
    bcContact = boContact.GetBusComp("Contact");
    with (bcContact)
    {
      // Create query context
      ClearToQuery();
      SetViewMode(AllView);
      ExecuteQuery(ForwardOnly);

      Outputs.SetProperty("NumRec1", CountRecords());
    }

    // This does the same thing
    with (bcContact)
    {
      // Create query context
      ClearToQuery();
      SetViewMode(AllView);
      ExecuteQuery(ForwardBackward);

      Outputs.SetProperty("NumRec2", CountRecords());
    }
  }
  catch(e)
  {
    // Call the custom LogError function to write error to error log
    LogError("Woops, an error has occurred!");
  }
  finally
  {
    // Destroy objects
    bcContact = null;
    boContact = null;
  }
}

Answers below! :)

VN:F [1.9.17_1161]
Rating: 0.0/10 (0 votes cast)