• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

One field displays # and other field displays ##

Explorer ,
Sep 16, 2024 Sep 16, 2024

Copy link to clipboard

Copied

Team,

 

In my code I'm trying to dynamically replace the # with ##. 

 

Code is ,

for(key in localStruct.AdditionalFieldsToUpdateStruct)  {
                    localStruct.AdditionalFieldsToUpdateStruct[key] = replace(localStruct.AdditionalFieldsToUpdateStruct[key],'##','####','all');
 }
 
But while displaying, one field shows # and other shows ##, 
 
Vishnu22410012h6s8_2-1726470636531.png

 

Not able to find the reason why this happens,

 

Can you please help?
 
Code where the fields are displayed ,
 
<td class="formRow">
#local.fields[FiName].Display# 
</td>
 
 
 

Views

274

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Nov 24, 2024 Nov 24, 2024

Hi , thank you, we wrapped the display value with Evaluate() function , this resolved the issue. Thanks

Votes

Translate

Translate
Community Expert ,
Sep 16, 2024 Sep 16, 2024

Copy link to clipboard

Copied

There's an old joke that goes like this: someone goes to a doctor and complains "it hurts when I do this". The doctor replies "don't do this". That's what your question reminds me of. Don't try to escape hash marks in the middle of an expression the way you're doing. You might be able to get it to work, but there's almost certainly an easier way to do what you want.

 

Dave Watts, Eidolon LLC 

Dave Watts, Eidolon LLC

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 16, 2024 Sep 16, 2024

Copy link to clipboard

Copied

Separately, I'd argue we can't solve the problem without seeing the values in question. Show us which "key" value works and which does not.

 

Also, you can often help yourself in this situation by creating a simple test page that does ONLY what's needed to present the problem. That way any of us could run it to confirm we see the same result...but often in creating such a simple test page, one will more easily recognize the problem and solution on their own. 


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 16, 2024 Sep 16, 2024

Copy link to clipboard

Copied

The displayed ## and # suggest that the end-results were, respectively, the strings '####' and '##'.

Is that not what you expected? If not, what are the original field names and what did you expect the end-results to be?

Did you, for example, expect just one # to be displayed in every case? Or the double ## to be displayed in every case?

 

Also, could you include code that shows how we go from localStruct.AdditionalFieldsToUpdateStruct[key] to local.fields[FiName].Display ?

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 18, 2024 Sep 18, 2024

Copy link to clipboard

Copied

@Vishnu22410012h6s8 , Have you solved the problem already? If not, then provide the information asked for and you will get a solution. This problem need not interrupt your work. It is simple to solve.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 23, 2024 Sep 23, 2024

Copy link to clipboard

Copied

Hi I expect single # to be displayed in UI.  I added the below fix because, if user enters # in the text area field and saves, error page will occur. This could be because coldfusion doesn't allow single #. The below piece of code is in a  repository, say ABC.

 

for(key in localStruct.AdditionalFieldsToUpdateStruct)  {
                    localStruct.AdditionalFieldsToUpdateStruct[key= replace(localStruct.AdditionalFieldsToUpdateStruct[key],'##','####','all');
 }
 
The below priece of code saves the value from the ABC repo into the database, gets the saved values from database and dsiplays the values in the UI using below code,
//get the additional field values
<cfscript>
    local.GetFieldsForRequest = this.GetFieldsForRequest(arguments.ReId);
</cfscript>

 
<cfif local.GetFieldsForRequest.RecordCount>

 
    <cfset local.fields = structNew()>

 
    <cfloop query="local.GetFieldsForRequest">
        <cfset local.fields[FiName] = StructNew()>

 
        <cfset local.configList = TyFiConfiguration>
        <cfset local.fields[FiName] = this.MapConfig(local.configList)>

 
        <cfset local.fields[FiName].value = ReFiVaValue>
        <cfset local.fields[FiName].required = TyFiRequired>

     
           
        <cfif Len(ReFiVaId)>
            <cfset isReadOnly = TyFiReadOnly>
        <cfelse>
            <cfset isReadOnly = false>
        </cfif>

        <cfset local.fields[FiName].readOnly = isReadOnly>

              <cfsavecontent variable="local.theDisplay"><cfoutput>
            <cfinclude template="Fields\#ReReplace(FiTyName,'[^a-zA-Z]','','all')#.cfm"> <!--- (FiTyName,' ','','all') --->
        </cfoutput></cfsavecontent>

        <cfset local.fields[FiName].Display = local.theDisplay>

    </cfloop>

    
    <cfoutput>
        <div style="text-align:left; overflow: auto; overflow-x: hidden; height:455px;"> <!--- --->
            <table class="table2008" width="50%">
                <tr>
                    <th class="reverse" colspan="3" style="text-align:center">Additional Information Fields</th>
                </tr>

               
                <cfset FiGroupName = "">
                <cfset local.previousGroupName = FiGroupName>
                <cfloop query="local.GetFieldsForRequest">
                    <cfset color = "">
                    <cfif structKeyExists(arguments.FieldErrors,FiName)>
                        <cfset color = "color:red;">
                    </cfif>

                    <cfif ListFindNoCase("Hidden Field",FiTyName)>
                 
                        #local.fields[FiName].Display#

                    <cfelse>

                  
                        <cfif FiGroupName neq local.previousGroupName>
                            <cfif LEN(FiGroupName)>
                                <tr>
                                    <th colspan="3">#FiGroupName#</th>
                                </tr>
                            </cfif>
                        </cfif>

                        <tr>
                            <td class="formRow"style="width:1%;#color#">
                                <cfif local.fields[FiName].required>
                                    *
                                <cfelse>
                                    &nbsp;
                                </cfif>
                            </td>
                            <td class="formRow " style="font-weight:bold;#color#" width="30%">
                                #FiDisplayName#
                            </td>
                            <td class="formRow">
                                #local.fields[FiName].Display# // Here is where all the field values are displayed
                            </td>
                        </tr>
                        <cfset local.previousGroupName = FiGroupName>

                    </cfif> <!--- <cfif ListFindNoCase("hidden",FiTyName)> --->

                </cfloop> <!--- <cfloop query="local.GetFieldsForRequest"> --->

            </table>

        </div>
    </cfoutput>
</cfif>
 
I also checked the database and can confirm that values of both the fields A and B in database have %23%23(in encoded format which is ##)
 
Let's assume the value sent to the system for field A (text field)  is "This is Vishnu. My id is #124."
Similarly the value sent to the system for field B (text area field) is "This is Ragav.My id is #234"
 
When we check in the UI,
The field A is displayed as ->   This is Vishnu. My id is ##124.
The field B is displayd as  ->    This is Ragav.My id is #234
 
Please let me know if mre information is required. Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 23, 2024 Sep 23, 2024

Copy link to clipboard

Copied

quote

I expect single # to be displayed in UI. 


By @Vishnu22410012h6s8

 

Thanks for that explanation. If you expect just a single # in each case, then the following code won't work

 replace(localStruct.AdditionalFieldsToUpdateStruct[key],'##','####','all')

That is because this code replaces "####" with "##". To illustrate with a different example, the result of

<cfoutput>#replace("Time flows.","flows","flies")#</cfoutput>

is: Time flies.


Suggestion:

  1.  Use chr(35) to represent #.
  2.  Use the regular-expression-replace function, REreplace, to replace any sequence of # characters with a single # character:
    <cfset localStruct.AdditionalFieldsToUpdateStruct={myKey1='myValue1',myKey2='##myValue2',myKey3='####myValue3',myKey4='######myValue4'}>
    
    <cfloop collection="#localStruct.AdditionalFieldsToUpdateStruct#" item="key">
    	<cfset localStruct.AdditionalFieldsToUpdateStruct[key]= REreplace(localStruct.AdditionalFieldsToUpdateStruct[key],'(#chr(35)#){2,}','#chr(35)#','all')>
    
    	<cfoutput>#"Key=" & key & "; " & "localStruct.AdditionalFieldsToUpdateStruct[key]=" & localStruct.AdditionalFieldsToUpdateStruct[key]#</cfoutput> <br>
    </cfloop>​
     The result is:
    Key=MYKEY1; localStruct.AdditionalFieldsToUpdateStruct[key]=myValue1
    Key=MYKEY2; localStruct.AdditionalFieldsToUpdateStruct[key]=#myValue2
    Key=MYKEY3; localStruct.AdditionalFieldsToUpdateStruct[key]=#myValue3
    Key=MYKEY4; localStruct.AdditionalFieldsToUpdateStruct[key]=#myValue4

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 24, 2024 Sep 24, 2024

Copy link to clipboard

Copied

Hi Vishnu, did that solve the # problem?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 24, 2024 Nov 24, 2024

Copy link to clipboard

Copied

Hi , thank you, we wrapped the display value with Evaluate() function , this resolved the issue. Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 25, 2024 Nov 25, 2024

Copy link to clipboard

Copied

LATEST

Thanks for the update. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation