Forums

Forums / Developing Portals / Autofill a lookup field

Autofill a lookup field

23 posts, 0 answered
  1. Charlotte Wang
    Charlotte Wang avatar
    20 posts
    Registered:
    02 Nov 2021
    02 Feb 2022
    Link to this post
    How can I autofill a lookup field? only when the field value is empty or blank.

    I used Rule Manager to set a default value for Country field but it doesn't work? Doesn't work for lookup fiels?

    Here are what I setup in Rule Manager: 
    1st attempt:
    When: tsbc_address1countryid doesnotcontainsdata
    Then set tsbc_address1countryid to the guid of the country (for instance: Canada)

    2nd attempt:
    When: tsbc_address1countryid doesnotcontainsdata
    Then set tsbc_address1countryid to "Canada" (text)

    Please help. Thanks!
    Last modified on 03 Feb 2022 01:02 by Charlotte Wang
  2. Brady Ward
    Brady Ward avatar
    92 posts
    Registered:
    19 Aug 2021
    03 Feb 2022 in reply to Charlotte Wang
    Link to this post
    Hello Charlotte,

    If you are not concerned with which specific value the Lookup populates with, you can set the PrepopulateFirstValue setting to true under Advanced > Model.

    However, if you do want to populate a specific value, you can continue using the Rule Manager widget. When you are setting a value in a lookup widget, you need to use the following convention:

    entity_logical_name;00000000-0000-0000-0000-000000000000

    ie. account;853a8760-65a2-2acc-0593-ceeb27ab391b

    Let me know if you have any questions,

    Brady
    TPC Web Developer
  3. Eric Mann
    Eric Mann avatar
    59 posts
    Registered:
    16 Oct 2020
    08 Feb 2022 in reply to Brady Ward
    Link to this post
    Brady, 
    I attempted the above using the PrePopulateFirstValue setting to True and I'm not seeing it prepopulate, is there any other settings to adjust? I do have a Filter and using FetchXML to limit results down to a single record / selection. 
  4. Brady Ward
    Brady Ward avatar
    92 posts
    Registered:
    19 Aug 2021
    09 Feb 2022 in reply to Eric Mann
    Link to this post
    Hello Eric,

    What version of TPC/Sitefinity are you using? PrepopulateFirstValue seems to work for me using a filter and not using a filter (my filter also limits results to a single record).

    Another thing we can try is editing the lookup and going to Advanced > Model and ensuring NoDefaultOption is set to False.

    Let me know if that works,

    Brady
    TPC Web Developer
  5. Eric Mann
    Eric Mann avatar
    59 posts
    Registered:
    16 Oct 2020
    09 Feb 2022 in reply to Brady Ward
    Link to this post
    Brady,
    Yes, I double-checked NoDefaultOption is set to False. Here are versions we are running. Also, if important the form is part of a Form Flow. 

    TPC v6.0.7400.145
    Sitefinity 13.1.7400.0

    Thank you,

    Eric
  6. Brady Ward
    Brady Ward avatar
    92 posts
    Registered:
    19 Aug 2021
    09 Feb 2022 in reply to Eric Mann
    Link to this post
    Hello Eric,

    I tested on TPC 6.0.7629.145 and it seems to still work, even in a Form Flow setup.

    Just to confirm a few things;

    - Do you see any errors in the console?
    - Do you see a value in the list when manually clicking the lookup?
    - Is there any custom JavaScript or a Rules Manager on the page that could be interacting with that field?
    - Have you tried adding a new Lookup to the form, copying the fetch and setting PrePopulateFirstValue to True to see if the issue lies within that specific instance?

    Looking forward to your reply,

    Brady
    TPC Web Developer
    Last modified on 09 Feb 2022 20:02 by Brady Ward
  7. Eric Mann
    Eric Mann avatar
    59 posts
    Registered:
    16 Oct 2020
    09 Feb 2022 in reply to Brady Ward
    Link to this post
    Brady,
    1. No errors in console
    2. Yes, value is present and as expected in lookup manually
    3. No Rules or JS on that field on that form
    4. New form / lookup - we will attempt this next and inform when complete. 

    thank you,

    Eric 
  8. Brady Ward
    Brady Ward avatar
    92 posts
    Registered:
    19 Aug 2021
    10 Feb 2022 in reply to Eric Mann
    Link to this post
    Thank you for that information Eric!

    Let me know how it goes with the new form and/or lookup.

    In the meantime, I will attempt to setup a Sitefinity instance that matches your version exactly to rule that out as well - I only matched your TPC version during my first test.

    Kind regards,

    Brady
    TPC Web Developer
  9. Eric Mann
    Eric Mann avatar
    59 posts
    Registered:
    16 Oct 2020
    10 Feb 2022 in reply to Brady Ward
    Link to this post
    Brady,
    New form / field outside of Form Flow and worked as expected. I'm going to rebuild form and fields from scratch as another attempt. 
  10. Brady Ward
    Brady Ward avatar
    92 posts
    Registered:
    19 Aug 2021
    10 Feb 2022 in reply to Eric Mann
    Link to this post
    Awesome! Keep me updated with the progress.

    All the best,

    Brady
    TPC Web Developer
  11. Eric Mann
    Eric Mann avatar
    59 posts
    Registered:
    16 Oct 2020
    10 Feb 2022 in reply to Brady Ward
    Link to this post
    Brady, 
    I switched one of the filters from another lookup field / widget (customerid) to QueryString (customerid) in Form Flow. I added it a couple of steps ahead of target field w/ PrePopulateFirstValue = True. This method is working consistently. I'm thinking the filter lookup (A) was not populated when PrePopulateFirstValue fired on target field (B). Hope this helps someone else and I appreciate your assistance. 

    Thank you,

    Eric 
  12. Charlotte Wang
    Charlotte Wang avatar
    20 posts
    Registered:
    02 Nov 2021
    11 Feb 2022 in reply to Brady Ward
    Link to this post
    Hi Brady,
    I tried the format you provided and it doesn't work.
    I wonder if the GUID should be encrypted or unencrypted?


  13. Brady Ward
    Brady Ward avatar
    92 posts
    Registered:
    19 Aug 2021
    11 Feb 2022 in reply to Charlotte Wang
    Link to this post
    Hello Charlotte,

    The GUID has to match whatever is contained in the lookup. So if you are passing an unencrypted GUID to the lookup, the lookup must also be set to EncryptGuids = false. Though, it is highly recommended to keep GUID's encrypted whenever possible.

    All the best,

    Brady
    TPC Web Developer
  14. Charlotte Wang
    Charlotte Wang avatar
    20 posts
    Registered:
    02 Nov 2021
    11 Feb 2022 in reply to Brady Ward
    Link to this post
    I see. I used unencrypted and didn't update the field setting to "false". I will try again. 
    Re encrypted GUID, it seems to be related to security risk., right? Could you explain me a bit more
    the risk be if using unencrypted GUID? I'd like to get a better understanding how this works.

    Thanks a lot!
  15. Brady Ward
    Brady Ward avatar
    92 posts
    Registered:
    19 Aug 2021
    11 Feb 2022 in reply to Charlotte Wang
    Link to this post
    Hello Charlotte,

    Yes, it is related to security. Encrypting the GUID's adds an extra layer to protect any potentially sensitive information. The GUID's returned from CRM may not always need to be encrypted, but having everything Always Encrypted helps prevent any unwanted information being released to the public domain.

    I would also like to add one more suggestion for your trials. If it is easier, in your rules manager, you can set the Action step to Run Script and use the text value (like the country name) to populate the lookup. In the script add the following line:

    tpc.forms[0].field_developer_name.set_textValue("COUNTRY NAME");

    Updating field_developer_name to the developer name of the lookup (found when you edit the wdiget and expand More Options) and the COUNTRY NAME to the text value of the country name (case insensitive).

    Let me know if you have any more questions,

    Brady
    TPC Web Developer
  16. Dan Rausch
    Dan Rausch avatar
    11 posts
    Registered:
    20 Aug 2021
    11 Feb 2022 in reply to Brady Ward
    Link to this post
    Brady Ward said:Hello Charlotte,

    The GUID has to match whatever is contained in the lookup. So if you are passing an unencrypted GUID to the lookup, the lookup must also be set to EncryptGuids = false. Though, it is highly recommended to keep GUID's encrypted whenever possible.

    All the best,

    Brady
    TPC Web Developer


    Hi Brady,

    Per your note above I'm wondering if there is a way to generate an encrypted value in a Rules manager rule.  For example, the value in the rule might be something like "853a8760-65a2-2acc-0593-ceeb27ab391b:encrypt" or some other format like that.  Is this possible?  Then we don't need to set EncryptGuids = False.

  17. Brady Ward
    Brady Ward avatar
    92 posts
    Registered:
    19 Aug 2021
    11 Feb 2022 in reply to Dan Rausch
    Link to this post
    Hello Dan,

    There are a few ways we could approach this depending on your current process.

    Where is the unencrypted GUID coming from in the first place?

    We could create a Saved Query (https://www.crmportalconnector.com/developer-network/documentation/how-tos/mvc-based-widgets/how-to-use-the-saved-queries-feature) to pass the unencrypted GUID to and retrieve an encrypted GUID back, but I'm curious why the GUID is unencrypted to begin with.

    If you'd like to go ahead with the Saved Query I can assist you with the process but would love to hear your current approach to getting the unencrypted GUID in the first place.

    Looking forward to your reply,

    Brady
    TPC Web Developer
    Last modified on 11 Feb 2022 21:02 by Brady Ward
  18. Dan Rausch
    Dan Rausch avatar
    11 posts
    Registered:
    20 Aug 2021
    11 Feb 2022 in reply to Brady Ward
    Link to this post
    It's actually really simple ... we go into the CRM, open the record we want as a default and grab the id value from the url.  Then we can paste that value into the Rules Manager in the Set Value action of the rule.
  19. Brady Ward
    Brady Ward avatar
    92 posts
    Registered:
    19 Aug 2021
    14 Feb 2022 in reply to Dan Rausch
    Link to this post
    Hello Dan,

    In that case, would my above suggestion about using set_textValue and Script as the action step not work for you? This would save any GUID conversions.

    Let me know,

    Brady
    TPC Web Developer
  20. Dan Rausch
    Dan Rausch avatar
    11 posts
    Registered:
    20 Aug 2021
    14 Feb 2022 in reply to Brady Ward
    Link to this post
    Yes, that's probably the best solution.  We will give that a try.
    Dan
  21. Brady Ward
    Brady Ward avatar
    92 posts
    Registered:
    19 Aug 2021
    14 Feb 2022 in reply to Dan Rausch
    Link to this post
    Let me know how it goes. Worst case we can continue with the Saved Query, but if we're able to implement the script and setting text value, that would be a huge time-saver and one less barrier for yourself and your team.

    Best of luck,

    Brady
    TPC Web Developer
  22. Charlotte Wang
    Charlotte Wang avatar
    20 posts
    Registered:
    02 Nov 2021
    16 Feb 2022 in reply to Brady Ward
    Link to this post
    Hi Brady,

    I tried using set_TextValue()  in Rule Mgr and it works. Thanks.

    I also tried the configuration 'Set Value' when country field contains no data using Rule Mgr with the format (entity name; GUID) and it doesn't work for both encrypted or unencrypted GUID.
    I wonder if it's a bug? The tpc version is v6.0.7629.145 for your reference. 


  23. Bhargavi Mahal
    Bhargavi Mahal avatar
    14 posts
    Registered:
    16 Dec 2020
    17 Feb 2022 in reply to Charlotte Wang
    Link to this post
    Hello Charlotte,

    Good to know that it worked!

    Thank you for providing the version. We will test it and report to product team.

    Regards,
    Bhargavi.
23 posts, 0 answered