URL encoding and decoding

  • 1
  • Question
  • Updated 4 years ago
  • Answered
I am generating a URL on global action click and passing some values in parameters which are then used to set default field value on new record (which is skuid page). The field which holds the default value is a lookup field. So I am passing both SF id and SF name in URL parameters so that it shows proper name instead of SF ID. These param values are referred in model conditions to set default field values. Now the issue i think is with the URL encode. If the name is KEVIN O'BRIEN then the generated URL is KEVIN O'BRIEN. The lookup field is not set up properly. It shows KEVIN O which is incorrect. I checked by adding {{#urlDecode}} in the condition but it does not work. Pls help.
Photo of TJ

TJ

  • 952 Points 500 badge 2x thumb

Posted 4 years ago

  • 1
Photo of TJ

TJ

  • 952 Points 500 badge 2x thumb
I am using skuid.utils.encodeHTML to encode string.
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
Use encodeURIComponent instead of encodeHTML --- encodeHTML is not appropriate here.
Photo of TJ

TJ

  • 952 Points 500 badge 2x thumb
Thanks Zach. I used encodeURIComponent and now it shows KEVIN O'BRIEN in that lookup field.
Photo of TJ

TJ

  • 952 Points 500 badge 2x thumb
 However I can save the record without any error and then offcourse it changes to proper name after save. But it should display KEVIN O'BRIEN before saving.
Photo of TJ

TJ

  • 952 Points 500 badge 2x thumb
I think Lookup field or the model condition is not interpreting/decoding the name properly. when I checked resultant encoded URL; for O'BRIEN it becomes O%26%2339%3BBRIEN. And in the field it shows O'BRIEN. I tried nameString = nameString.replace('%26%2339%3B', "\\'"); but the field shows O\'BRIEN. Pls help.
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
We'd actually reccomend another strategy. 

Just pass the SF id for the related record in your URL.  This simplifies the URL string and avoids the URL encoding issues.

Then on your New Record page - create another model that uses the Id parameter to retrieve data from the existing record.  This data will include name, but can include whatever else you want. 

Then your "new record" models will use "Field from another model" conditions to pre-populate data instead of using URL parameter conditions. 

Then you should get the name you are interested in. 
Photo of TJ

TJ

  • 952 Points 500 badge 2x thumb
There are few complications in my model and the ways I have developed this page and that is the reason I have gone thorugh this URL route instead of "Field from another model" conditions. I had already discussed this with Skuid in a meeting and found out that URL route might be a way. Anyways, it would be really good if you let me know how to handle it through URL passing. Thanks!
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
We would need to see the exact setup of the portion of the source and target pages in question in order to help any further --- I tried what I believe you are doing and could not replicate the problem, the Model Conditions are doing what they should be doing. I believe that the source of the error is that you are trying to encode an already-encoded value. Normally, values in Skuid Model data are stored encoded, but depending on where you are getting the value you from, you may be "double encoding" it. How are you passing / converting values into the URL? Do you have a Button that is running some custom JavaScript, and is this JavaScript opening the new URL? If so, please post exact lines of JavaScript that are being called. If you are using a Redirect to URL action and your URL is defined by a Template, please post the full URL template you are using.

Here is the XML for a sample page that I used to test to show that this was working:

<skuidpage unsavedchangeswarning="" showsidebar="false" showheader="true" tabtooverride="Case">   
     <models>
      <model id="Case" limit="1" query="false" createrowifnonefound="true" sobject="Case" type="">
         <fields>
            <field id="Subject"/>
            <field id="AccountId"/>
            <field id="Account.Name"/>
         </fields>
         <conditions>
            <condition type="param" value="accid" field="AccountId" operator="=" enclosevalueinquotes="true" novaluebehavior=""/>
            <condition type="param" value="accname" field="Account.Name" operator="=" userinfotype="userid" enclosevalueinquotes="true" novaluebehavior=""/>
            <condition type="param" value="subject" field="Subject" operator="=" enclosevalueinquotes="true" novaluebehavior=""/>
         </conditions>
         <actions/>
      </model>
   </models>
   <components>
      <pagetitle model="Case">
         <maintitle>
            <template>New {{Model.label}}</template>
         </maintitle>
         <subtitle>
            <template>{{Model.labelPlural}}</template>
         </subtitle>
         <actions>
            <action type="savecancel" afterCancel="/{{Model.KeyPrefix}}/o" afterSave="/{{Id}}" rollbackonanyerror="true"/>
         </actions>
      </pagetitle>
      <basicfieldeditor showsavecancel="false" showheader="true" model="Case" mode="edit" buttonposition="" layout="">
         <columns>
            <column width="50%">
               <sections>
                  <section title="Basics">
                     <fields>
                        <field id="Subject" valuehalign="" type=""/>
                        <field id="AccountId"/>
                     </fields>
                  </section>
               </sections>
            </column>
            <column width="50%">
               <sections>
                  <section title="Additional Info">
                     <fields/>
                  </section>
               </sections>
            </column>
         </columns>
      </basicfieldeditor>
      <basicfieldeditor showheader="true" showsavecancel="false" model="Case" buttonposition="" uniqueid="sk-5863063473-146" mode="read" layout="">
         <columns>
            <column width="50%">
               <sections>
                  <section title="Section A">
                     <fields>
                        <field id="Subject" valuehalign="" type=""/>
                        <field id="AccountId" valuehalign="" type=""/>
                     </fields>
                  </section>
               </sections>
            </column>
            <column width="50%">
               <sections>
                  <section title="Section B">
                     <fields/>
                  </section>
               </sections>
            </column>
         </columns>
      </basicfieldeditor>
   </components>
   <resources>
      <labels/>
      <css/>
      <javascript/>
   </resources>
</skuidpage>

And here is a sample JavaScript Snippet i used to test with various dummy values:

var newValue = window.prompt('Enter the name to pass in','KEVIN O\'BRIEN');

skuid.utils.redirect({
   url: '/apex/skuid__ui?page=LookupFieldPopulation&accid=001G000000sgyKLIAY&accname='+newValue+'&subject='+newValue
});
Photo of TJ

TJ

  • 952 Points 500 badge 2x thumb
I am calling a js snippet from global action on a related list. The snippet generates URL and redirection happens. Below is a url string generation part from my snippet. Let me know if you need whole snippet and I can email it to you:


//URL string generation starts 
var urlSub = "/apex/skuid__ui?page=PKY_CDocument&pageMode=new&isDoc=true&mnId="+cModel.data[0].Business_Account__c+"&mainDocId="+cModel.data[0].Id;

urlSub += "&mainDocType="+mainDocType+"&rDate="+todaysDate;

//I encoded String below. I tried without encoding too
var nameString = encodeURIComponent(cModel.getFieldValue(cRow, EmplNameFld));
// nameString = nameString.replace('%26%2339%3B', "\\'");

//I am generating parameter names dynamically here and assigning values too
urlSub += "&"+Employees[i]+"Id="+cModel.getFieldValue(cRow, EmplIdFld)+"&"+Employees[i]+"Name="+nameString;

console.log(urlSub);
window.top.location = urlSub;


1) When cModel.getFieldValue(cRow, EmplNameFld) has KEVIN O'BRIEN and I generate URL without encoding then the skuid page shows Kevin O in field after redirection.

2) If I encode this string and generate URL then it shows KEVIN O&#39;BRIEN in the lookup field after redirection.

I have conditions on my model(for both ID and Name) which takes these param values. I checked soql it looks good. That is why I am able to save the record without any error. It is just that the value before saving the record does not look proper in the field.
Photo of Ben Hubbard

Ben Hubbard, Employee

  • 12,490 Points 10k badge 2x thumb
There's a third parameter in skuid.model.Model.getFieldValue() shown here.

Try to put true in that third parameter like this.

cModel.getFieldValue(cRow,EmplIdFld,true);
Photo of Ben Hubbard

Ben Hubbard, Employee

  • 12,490 Points 10k badge 2x thumb
We escape the value from getFieldValue by default to prevent people from inadvertently letting XSS vulnerabilities into their page.  If you use the noEscape attribute, you have to be careful not to just throw that into your html somewhere though. (Your code looks fine, but just a friendly reminder.) :)
Photo of TJ

TJ

  • 952 Points 500 badge 2x thumb
I tried. It shows correct name in lookup field- KEVIN O'BRIEN.
However, the skuid pages shows problem on top. It is a problem with soql formed. It is a record creation page and the soql formed has Negotiator__r.Name = 'KEVIN O'BRIEN'   which creates a problem. This is coming from model condition.
(Edited)
Photo of Ben Hubbard

Ben Hubbard, Employee

  • 12,490 Points 10k badge 2x thumb
What version of Skuid are you running?
Photo of TJ

TJ

  • 952 Points 500 badge 2x thumb
6.8.7
Photo of Ben Hubbard

Ben Hubbard, Employee

  • 12,490 Points 10k badge 2x thumb
Hmmm, that sounds strange. I'll try to recreate in my org, if you wouldn't mind granting Skuid access to your org by following the instructions below, I may be able to figure it out sooner.

http://help.skuidify.com/m/getting-started/l/182412-getting-help-how-to-grant-skuid-login-rights-to-...
Photo of Ben Hubbard

Ben Hubbard, Employee

  • 12,490 Points 10k badge 2x thumb
I'll also need your org Id and page name if you want me to take a look at your setup.  You can send that in an email to support@skuidify.com
Photo of Ben Hubbard

Ben Hubbard, Employee

  • 12,490 Points 10k badge 2x thumb
Actually nevermind. I'm able to reproduce this issue.  I'll look into it more and let you know what I find.
Photo of TJ

TJ

  • 952 Points 500 badge 2x thumb
Thanks Ben! However I will have to check on sharing this info tomorrow with our admin. Company policy might restrict it. I will be in touch with you on your email tomorrow morning PST. Hope this time suits you.
Photo of TJ

TJ

  • 952 Points 500 badge 2x thumb
OK, thank you!
Photo of Ben Hubbard

Ben Hubbard, Employee

  • 12,490 Points 10k badge 2x thumb
Ok, we were able to replicate this issue and it is a bug in Skuid.  We'll put out a patch later this week to fix this.
Photo of TJ

TJ

  • 952 Points 500 badge 2x thumb
Ok, thank you. I will follow up on this patch offline through email.
Photo of Ben Hubbard

Ben Hubbard, Employee

  • 12,490 Points 10k badge 2x thumb
This has been fixed in Skuid 6.8.8 available on the Skuid Releases page.

http://www.skuidify.com/skuidreleases
Photo of TJ

TJ

  • 952 Points 500 badge 2x thumb
Hi Ben,
I upgraded Skuid to 6.8.8 and checked this issue. It still shows incorrect name in lookup field.
I used cModel.getFieldValue(cRow,EmplIdFld,true) and passed this string in URL. The employee name KEVIN O'BRIEN displays in lookup field as KEVIN O\'BRIEN. The pages shows no erros and saves properly.
Photo of Ben Hubbard

Ben Hubbard, Employee

  • 12,490 Points 10k badge 2x thumb
Strange.  I'll take another look at this today.
Photo of Ben Hubbard

Ben Hubbard, Employee

  • 12,490 Points 10k badge 2x thumb
Yup, we fixed half of the bug.  The SOQL is being generated correctly now, but condition values are still too escaped, and resulting in defaults being messed up.  We'll try to get this into our next patch release.
Photo of TJ

TJ

  • 952 Points 500 badge 2x thumb
Thanks again. I will keep an eye on your next patch.
Photo of Ben Hubbard

Ben Hubbard, Employee

  • 12,490 Points 10k badge 2x thumb
Alright, I believe this has been completely fixed in 6.8.14 which is available for install on the skuidify.com/skuidreleases page.
Photo of TJ

TJ

  • 952 Points 500 badge 2x thumb
It works. Thank you Ben!