Skip to main content
Solved

Trim blank spaces in URI

  • January 23, 2025
  • 1 reply
  • 27 views

Forum|alt.badge.img

Getting an error when trying to reterive data.

I have created a nested statement

api:set attr="detailsIn.URITemplate" 		value="[urlbase]/api/Budget/{projectNumber}/currentbudget?api-version=1.0" />

I think its because of a blank space after the project number 123456
All other projects in TX log comes without a blank space

2025-01-23T11:48:43.178+01:00	2	[JSON] Reading JSON file at https://baseurl/Budget/123456 /currentbudget?api-version=1.0
2025-01-23T11:48:43.184+01:00	2	[53|Q-Id]	[HTTP|Req: 1457] GET https://baseURL/Budget/123456 /currentbudget?api-version=1.0

I have tried to remove blank spaces with following code but its not working.
Anyone has a suggestion?

 <api:script method="GET">    
    <api:call op="jsonproviderGet" in="touchIn" out="touchOut">
 <!-- Remove all blank spaces from projectNumber and store in a variable -->
        <api:set attr="cleanedProjectNumber" 
                 value="[touchOut.projectNumber | replace('\\s+', '')]" />

        <!-- Use the cleaned projectNumber in the URI -->
        <api:set attr="detailsIn.URI" 
                 value="[detailsIn.URITemplate | replace('{projectNumber}', [cleanedProjectNumber])]" />
        <api:call op="jsonproviderGet" in="detailsIn" out="detailsOut">
<api:set attr="out.projectRecord"						value="[detailsOut.ProjectRecord| allownull()]"/>
      <api:push item=out/>
    </api:call>
	</api:call>
  </api:script>

 

Best answer by Thomas Lind

Hi ​@aftabp 

Perhaps using the trim function could help.

https://cdn.cdata.com/help/DWK/ado/pg_stringvalueformatters.htm#attr--trim

 <api:script method="GET">    
    <api:call op="jsonproviderGet" in="touchIn" out="touchOut">
 <!-- Remove all blank spaces from projectNumber and store in a variable -->
        <api:set attr="touchin.cleanedProjectNumber" 
                 value="[touchOut.projectNumber | trim()]" />

        <!-- Use the cleaned projectNumber in the URI -->
        <api:set attr="detailsIn.URI" 
                 value="[detailsIn.URITemplate | replace('{projectNumber}', [touchin.cleanedProjectNumber])]" />
        <api:call op="jsonproviderGet" in="detailsIn" out="detailsOut">
<api:set attr="out.projectRecord"						value="[detailsOut.ProjectRecord| allownull()]"/>
      <api:push item=out/>
    </api:call>
	</api:call>
  </api:script>

 

View original
Did this topic help you find an answer to your question?

Thomas Lind
Community Manager
Forum|alt.badge.img+5
  • Community Manager
  • January 23, 2025

Hi ​@aftabp 

Perhaps using the trim function could help.

https://cdn.cdata.com/help/DWK/ado/pg_stringvalueformatters.htm#attr--trim

 <api:script method="GET">    
    <api:call op="jsonproviderGet" in="touchIn" out="touchOut">
 <!-- Remove all blank spaces from projectNumber and store in a variable -->
        <api:set attr="touchin.cleanedProjectNumber" 
                 value="[touchOut.projectNumber | trim()]" />

        <!-- Use the cleaned projectNumber in the URI -->
        <api:set attr="detailsIn.URI" 
                 value="[detailsIn.URITemplate | replace('{projectNumber}', [touchin.cleanedProjectNumber])]" />
        <api:call op="jsonproviderGet" in="detailsIn" out="detailsOut">
<api:set attr="out.projectRecord"						value="[detailsOut.ProjectRecord| allownull()]"/>
      <api:push item=out/>
    </api:call>
	</api:call>
  </api:script>

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings