Forum Discussion

kanchanpatil's avatar
kanchanpatil
New Contributor
7 years ago

how to use substring in PropertyTransfer

I want to transfer one attribute value from 1 request to another request.
i have used PropertyTransfer step to do the same.
but the actual value is present in the description format (highlighted in bold below).
and 2nd request will have below full string.
e.g.
Attribute 'Party ID' is transformed from ('') to ('49025')
 
I just need to transfer the value i.e. 49025
 
so what step should i use to do a substring?
 
request1 response:
 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
      <DataService version="2.0" xsi:schemaLocation="http://www.tibco.com/cim/services/mastercatalogrecord/wsdl/2.0 schemas/MasterCatalogRecord_Action.xsd" xmlns="http://www.tibco.com/cim/services/mastercatalogrecord/wsdl/2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <Transaction>
            <Response type="Add">
              <MasterCatalogRecord etype="Entity" commandqualifier="Validate/NoProcess">
                  <ExternalKeys>
                    <Key name="MASTERCATALOGNAME">PARTY_2</Key>
                  </ExternalKeys>
                  <EntityData>
                    <Attribute name="PartyType" type="string">Individual</Attribute>
                    <Attribute name="NamePrefix" type="string">Mr.</Attribute>
                    <Attribute name="FirstName" type="string">Hemali</Attribute>
                    <Attribute name="LastName" type="date">Shinde</Attribute>
                    <Attribute name="NameSuffix" type="string">Sr.</Attribute>
                    <Attribute name="Gender" type="string">Female</Attribute>
                  </EntityData>
                  <ResultList highestSeverity="Info" reference="PartyName">
                    <Result severity="Info" code="GEN-7300">
                        <Description lang="en">Attribute 'Party Name' is transformed from ('') to ('Mr. Hemali Shinde Sr.')</Description>
                    </Result>
                  </ResultList>
                  <ResultList highestSeverity="Info" reference="RELATIONSHIP_LIST">
                    <Result severity="Info" code="GEN-7300">
                        <Description lang="en">attribute RELATIONSHIP_LIST assigned value = [Contact_Details, Associated_Organisation]</Description>
                    </Result>
                  </ResultList>
                  <ResultList highestSeverity="Info" reference="PRODUCTID">
                    <Result severity="Info" code="GEN-7300">
                        <Description lang="en">Attribute 'Party ID' is transformed from ('') to ('49025')</Description>
                    </Result>
                  </ResultList>
              </MasterCatalogRecord>
              <ResultList highestSeverity="Info" reference="Add">
                  <Result severity="Info" code="SVC-11025">
                    <Description lang="en">Service 'Validate/NoProcess' executed successfully.</Description>
                  </Result>
              </ResultList>
            </Response>
            <TransactionResult result="Completed">
              <SuccessCount>1</SuccessCount>
              <EventID>40041</EventID>
            </TransactionResult>
        </Transaction>
      </DataService>
  </soapenv:Body>
</soapenv:Envelope>
 
 
Request 2 Request: ( it should have only that ID )
 
 
<soapenv:Header/>
<soapenv:Body>
 
 
 
<Identity>
    <DirectoryPath>
        <Directory type="Enterprise"></Directory>
        <Directory type="User"></Directory>
    </DirectoryPath>
    <Authentication type="Password"></Authentication>
</Identity>
<Transaction>
<Command type="Delete">
<MasterCatalogRecord commandqualifier="Record" etype="Entity">
<ExternalKeys>
    <Key name="MASTERCATALOGNAME">PARTY_2</Key>
    <Key name="PRODUCTID" type="String">Attribute 'Party ID' is transformed from ('') to ('49026')</Key>
</ExternalKeys>
 
</MasterCatalogRecord>
 
</Command>
 
</Transaction>
 
</DataService>
 
</soapenv:Body>
 
</soapenv:Envelope>
 
Kindly help.
 
Thanks,
kanchan

1 Reply

  • Lucian's avatar
    Lucian
    Community Hero

    You can use a groovy script to extract the id. If the message "Attribute Party Id.." is always the same this should work:

     

    // Get the raw response from a certain test step
    def rawResponse = testRunner.testCase.testSteps["NameOfYourRequestTestStep"].testRequest.response.contentAsString
    // Find the index where the product id begins
    def startIndexOfId = rawResponse.indexOf("Attribute 'Party ID' is transformed from ('') to ('") + "Attribute 'Party ID' is transformed from ('') to ('".length()
    // Cut the string from the beggining of the id to the end of the rawResponse
    def id = rawResponse.substring( startIndexOfId )
    // Find the place where the id is ending
    def endIndexOfId = id.indexOf("')")
    // Extract the id
    id = id.substring( 0, endIndexOfId )

     

    Cheers!