URL encoding and decoding

TJTJ Member
edited March 2017 in Questions
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.

Comments

  • TJTJ Member
    edited March 2017
    I am using skuid.utils.encodeHTML to encode string.
  • Rob HatchRob Hatch Skuad, Sonar ✭✭
    edited September 2016
    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. 
  • TJTJ Member
    edited April 2016
    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!
  • Zach McElrathZach McElrath Skuad
    edited December 2016
    Use encodeURIComponent instead of encodeHTML --- encodeHTML is not appropriate here.
  • TJTJ Member
    edited April 2016
    Thanks Zach. I used encodeURIComponent and now it shows KEVIN O'BRIEN in that lookup field.
  • TJTJ Member
    edited April 2016
     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.
  • TJTJ Member
    edited April 2016
    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.
  • Zach McElrathZach McElrath Skuad
    edited March 2017
    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
    });


  • TJTJ Member
    edited April 2016
    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.
  • Ben HubbardBen Hubbard Member
    edited March 2017
    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);
  • Ben HubbardBen Hubbard Member
    edited March 2015
    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.) :)
  • TJTJ Member
    edited April 2016
    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.
  • Ben HubbardBen Hubbard Member
    edited March 2017
    What version of Skuid are you running?
  • TJTJ Member
    edited April 2016
    6.8.7
  • Ben HubbardBen Hubbard Member
    edited March 2017
    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-...
  • Ben HubbardBen Hubbard Member
    edited March 2015
    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 [email protected]
  • Ben HubbardBen Hubbard Member
    edited March 2015
    Actually nevermind. I'm able to reproduce this issue.  I'll look into it more and let you know what I find.
  • TJTJ Member
    edited April 2016
    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.
  • TJTJ Member
    edited April 2016
    OK, thank you!
  • Ben HubbardBen Hubbard Member
    edited March 2017
    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.
  • TJTJ Member
    edited April 2016
    Ok, thank you. I will follow up on this patch offline through email.
  • Ben HubbardBen Hubbard Member
    edited March 2017
    This has been fixed in Skuid 6.8.8 available on the Skuid Releases page.

    http://www.skuidify.com/skuidreleases
  • TJTJ Member
    edited March 2017
    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.
  • Ben HubbardBen Hubbard Member
    edited March 2015
    Strange.  I'll take another look at this today.
  • Ben HubbardBen Hubbard Member
    edited March 2015
    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.
  • TJTJ Member
    edited April 2016
    Thanks again. I will keep an eye on your next patch.
  • Ben HubbardBen Hubbard Member
    edited March 2017
    Alright, I believe this has been completely fixed in 6.8.14 which is available for install on the skuidify.com/skuidreleases page.
  • TJTJ Member
    edited April 2016
    It works. Thank you Ben!
Sign In or Register to comment.