Sunday, January 22, 2012

Understanding EAI Transaction Service

Recently I got the chance to work on a EAI requirement which requires the use of business service:  "EAI Transaction Service"

This post might help you if you are hearing this business service for the first time.

First of all, let me tell you what was the requirement for which I used this business service and later will tell you how it works.

Requirement
We have integration between a third-party system which keeps the Quotes, created in Siebel. So whenever a Quote record is UPDATED, it should also get reflect in the third-party system. The synchronous transaction is being send via real-time Web Service call at the WriteRecord event of Quote BC. The requirement was, while sending the updated Quote XML to the other system, check for the web service response. If the response = "Success", it is fine, but if response = "Failed", then revert back the changes done by user on the UI. So lets suppose user has changed 3-4 fields on Quote list applet and saved the record, and while integration call, system receives the respone = "Failed", then system has to revert back the values of these 3-4 fields.

Now, let us see how EAI Transaction Service help in this scenario:

I will not discuss the integration details but just the technical details related to EAI Transaction Service. Please assume that we already have a function: "SendToInterface()" created which will take care of sending the Quote XML to the other system. Now, here is what you need to do:

1. BusComp Server Script -> General -> Declarations:


var svcEAITransService = TheApplication().GetService("EAI Transaction Service");
var psInp = TheApplication().NewPropertySet();
var psOut = TheApplication().NewPropertySet();

2. BusComp_PreWriteRecord:


function BusComp_PreWriteRecord ()
{
svcEAITransService.InvokeMethod("BeginTransaction", psInp, psOut);
return (ContinueOperation);
}

3. BusComp_WriteRecord()


var strResult = SendToInterface();
psInp.Reset();
psOut.Reset();
if (strResult == "Failed")
psInp.SetProperty("Is Abort", "True");
svcEAITransService.InvokeMethod("EndTransaction", psInp, psOut);
this.InvokeMethod("RefreshRecord");




So, from the point you invoke "BeginTransaction" method, system keeps a check-point for you, till the time you invoke "EndTransaction" method. And as soon as EndTransaction get executed, the data gets commit actually to the database. 

Points to ponder:
  1. If BeginTransaction method has been executed, then execution of EndTransaction method is MUST for getting the data commit into the database. If for any reason, it not get executed or thin-client session get closed, data will never go to database.
  2. In the same session, the updated value is available for the Business Component and if you do a GetFieldValue in the current instance or try to fetch value via Integration Object, you will get the updated value.
  3. In case you have a Workflow Policy based on some field you have updated, it will only get trigger after the event of execution of method: EndTransaction.


Query
Somebody might come back and ask why should even I use this business service, why don't I just call the "SendToInterface()" function in PreWriteRecord event itself and check for the web service response right there? If success, then let the WriteRecord event fire else prompt a message using RaiseErrorText?

Clarification
Well, the above statement might sounds correct, but keep in mind EAI Siebel Adapter will run a separate query to fetch the data in SiebelMessage, so unless and until, the WriteRecord event fires (in the current session) it won't be able to get the updated values in SiebelMessage.

Hope this helps.



11 comments:

  1. Great post! We are facing the exact same requirements on my current project. I had used this service as steps within a Workflow but only for inbound integration processing. Great use on the BC events to control outbound dual-write requirements.

    ReplyDelete
  2. Amazing solution for the complex requirement.

    ReplyDelete
  3. Gaurav,

    Have you tried this in the context of a Task? I tried adding a BeginTransaction step within the Task, write a record within a business service step, and then EndTransaction with IsAbort = True. For some reason the record commits to the DB anyway.

    Thanks!

    ReplyDelete
  4. Very Informative! This blog is great source of information which is very useful for me. Thank you very much for sharing this!
    thue dj

    ReplyDelete
  5. Enjoyed your blog. But missing your posts in 2013. Want to see you back soon.

    Thanks.

    ReplyDelete
  6. Yes! i completely agree! Fantastic! job...

    ReplyDelete
  7. Hi,

    I have one query . plese help me in implementing this requirement.
    . There is parent service request under which i am associating an activity of Type = web update.
    Once I made the status of the activity as done then a copy of this activity is getting associated in all child service request records.
    this is implemented through workflow policy.
    But in the child activity created in child service request last name field is not getting populated.
    Requirement is to stamdp the last name of the child service request in the chlid activity created under child service request.
    Please gudie me in implementing the request. Thanks.

    Regards,
    Priya

    ReplyDelete
    Replies
    1. Hi Priya,

      You need to check the Workflow Process which is being called via workflow policy. Try to look into that workflow how the activities are getting associated and then populate the Last Name there itself.

      Cheers
      Gaurav

      Delete
  8. really a great post.....helped a lot to understand this bs

    ReplyDelete
  9. Thanks for the post. Would this work in a scenario in an Inbound webservice if we are updating multiple BC's thru an Integration Object and I'm trying to do this in a BS with the steps below

    var svcEAITransService = TheApplication().GetService("EAI Transaction Service");
    var psInp = TheApplication().NewPropertySet();
    var psOut = TheApplication().NewPropertySet();

    try
    {
    EAI Siebel Adapter - Upsert (Using Integration Object)
    }
    catch(e)
    {
    psInp.SetProperty("Is Abort", "True");

    }
    finally
    {
    svcEAITransService.InvokeMethod("EndTransaction", psInp, psOut);

    }


    ReplyDelete
    Replies
    1. Yes, it will, but make sure to use BeginTransaction at the right place.

      Delete