Siebel eScript Replace function.

OkAvarageGoodVery GoodExcellent (2 votes, average: 5.00 out of 5)
Loading ... Loading ...
Viewed : 7,032 times

String Replace function is a pretty important and powerful function available in Siebel eScript. Powerful because we can use Regular expressions to find any type of pattern and replace it with our desired value. As usual I will try to explain with the help of example :)

Requirement:

I was working on a integration through webservices. They were sending response as an XML String. That was something like:

<? xml version= ”1.0” ?>
<statuobject>
<status> Success</status>
<reason> Quote inserted successfully </reason>
</statusobject>

Now I had to extract the values from the string and see if it has failed or passed. In case if it failed I had to send the mail including the reason code.

I could have solved it with two approaches.

1. Convert it to XML Hierarchy and extract the values using XML function in DTE Script
2. Use “replace” function to extract the values.

I will discuss the replace strategy which I finally used.

Solution: 


The code that finally did it for me was like this

  str = objectIn.GetProperty(“StatusString”);
 var pattern = /(<[^>]+>)/g;

// to remove the xml declaration part <? xml version= ”1.0” ?>
  status_str = str.substring(67,str.length – 29);

//replace the tags with “|” symbol
  finalstring = status_str.replace(pattern, “|”);

This code searched for tags in the string and replaced it with “|” symbol which I split using split function and got a array with the values.

result_ary = finalstring.split(“|”); 

So getting value was as easy as var stat =  result_ary[1] and so on

in pattern the /g represent global search if you don’t use that it will just replace the first occurrence not all the occurrences.

Discussing regular expression is out of scope but will surely discuss replace function in detail in the next posts.

Related Posts

  • Sahil

    Hi,
    nice solution. Replace is definitely a very powerful tool.
    You may also try to convert the string into a hierarchy, and use. ‘GetProperty(“status”);’.
    You may need to go down a few levels in the XML structure using ‘GetChild(n);’.
    This should also work with the advantage u have everything available in the form of Hierarchy which is native to Siebel. So the same property set can float around everywhere. There is no information loss either.
    In your approach, if you try to get back the original string, you cannot, because of replace function.

    Regards,
    Sahil

  • Sahil

    Hi,
    nice solution. Replace is definitely a very powerful tool.
    You may also try to convert the string into a hierarchy, and use. ‘GetProperty(“status”);’.
    You may need to go down a few levels in the XML structure using ‘GetChild(n);’.
    This should also work with the advantage u have everything available in the form of Hierarchy which is native to Siebel. So the same property set can float around everywhere. There is no information loss either.
    In your approach, if you try to get back the original string, you cannot, because of replace function.

    Regards,
    Sahil

  • neel

    very rightly put sahil.

    But we learn as we go along at that time I was not so much informed but IO hierarchy will be my prefered choice if I have to do it again :)

    • pankaj

      Hi Neel,
      I wanted to read XML input which have multiple input. I have custom BS which takes input as Name (s)and Code. The input format for Name (s) will be something like….
      <ListOfNames>
      <Name>abc</Name>
      <Name>xyz</Name>
      </ListOfName>
      and code will be simple imput.

      Can you please do let me know how to go about the same. What I tried is:
      1) Created BS with 2 input as Name and Code both data type will be striing and storage type will pe property.
      2) IN BS I m saying var x = input.getproperty(Name);
      and I am writing this property set to file using EAI XML Write to File.
      this BS is used by external application to get and set the data in siebel basically inboud.
      3) Done all the required setup for inbound but when they invoke the method with input , I am receiving only input i.e Code… the second input will be blank…

      Any idea?
      con me: pankajsingh01@gmail.com

      • http://intensedebate.com/people/neelmani neelmani

        Name that you are passing is a property set not string. So, you need to set it's data type as Hierarchy and storage also as hierarchy.

        and in business service you need to do

        var x = input.GetChild(0);

        Then you will be able to get hierarchy that you have passed.

        There is another question for you. How are you calling this business service
        via script or via workflow ????

  • neel

    very rightly put sahil.

    But we learn as we go along at that time I was not so much informed but IO hierarchy will be my prefered choice if I have to do it again :)

    • pankaj

      Hi Neel,
      I wanted to read XML input which have multiple input. I have custom BS which takes input as Name (s)and Code. The input format for Name (s) will be something like….
      <ListOfNames>
      <Name>abc</Name>
      <Name>xyz</Name>
      </ListOfName>
      and code will be simple imput.

      Can you please do let me know how to go about the same. What I tried is:
      1) Created BS with 2 input as Name and Code both data type will be striing and storage type will pe property.
      2) IN BS I m saying var x = input.getproperty(Name);
      and I am writing this property set to file using EAI XML Write to File.
      this BS is used by external application to get and set the data in siebel basically inboud.
      3) Done all the required setup for inbound but when they invoke the method with input , I am receiving only input i.e Code… the second input will be blank…

      Any idea?
      con me: pankajsingh01@gmail.com

      • http://intensedebate.com/people/neelmani neelmani

        Name that you are passing is a property set not string. So, you need to set it's data type as Hierarchy and storage also as hierarchy.

        and in business service you need to do

        var x = input.GetChild(0);

        Then you will be able to get hierarchy that you have passed.

        There is another question for you. How are you calling this business service
        via script or via workflow ????

  • pankaj

    Hi Neel,
    Thanx for your reply….
    I tried something like this…
    1) Instead of having two input as Name and Code …I used only one input which contian both names and code.. use data type as string and storage type as property.
    2) In the BS I am saying
    var x = Inputs.GetProperty(“GroupInputXML”);
    then converting input XML to proprerty set and extracting values from property set.

    3) I am not calling this BS from anywere .. I exposed this BS as web service (so this is basically inbound integration)…

  • pankaj

    Hi Neel,
    Thanx for your reply….
    I tried something like this…
    1) Instead of having two input as Name and Code …I used only one input which contian both names and code.. use data type as string and storage type as property.
    2) In the BS I am saying
    var x = Inputs.GetProperty(“GroupInputXML”);
    then converting input XML to proprerty set and extracting values from property set.

    3) I am not calling this BS from anywere .. I exposed this BS as web service (so this is basically inbound integration)…

  • Scriptless Siebel
  • Product Configurator