Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Decrypting & Setting Displayed Value - Not Entity Value - With JavaScript

Posted on by Microsoft Employee

I've made a plugin that encrypts certain fields on an Account entity prior to saving them to the database. Now, in the UI, I need to call an endpoint I wrote to decrypt them using JavaScript and then display that text in the field (without saving it to the database). I've got the script loaded correctly in Web Resources, it's calling the endpoint onLoad and getting the decrypted value, but I can't figure out how to set it as only the text that's displayed in the field, not as the field value on the actual entity. Is there a better way to do this? If I use

Xrm.Page.getAttribute("my_field").setValue(decryptedValue);
Xrm.Page.data.entity.save();

...it obviously saves the value. If I leave off the save(), it doesn't display the text correctly.

Can I use jQuery for this? If so, which fields do I need to set, and using which jQuery method - val, text, html?

Bonus: How can I 1) get the onLoad JS to get called faster and 2) also make this call onBlur?

Thanks in advance!

*This post is locked for comments

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Decrypting & Setting Displayed Value - Not Entity Value - With JavaScript

    Hi spjpdx,

    if you solved the problem thanks to an answer, please mark it as verified to encourage the community to provide more and more a better support. Thank you. Francesco

    If you found the answer helpful, please mark as Verified 

    Join my network on LinkedIn      Follow me on Twitter 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna+Milano, ITALY

    Independent Contractor

    http://www.francescopicchi.com

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Decrypting & Setting Displayed Value - Not Entity Value - With JavaScript

    Hi spjpdx ,

    why you need to set the value over attributes fields after you saved them in db?

    Doing so you have the problem to fill the attributes and then reset them!

    You could:

    1) show them only in web resource, once saved

    2) set the attributes onLoad event, and beforse save, blank them, like:

    function OnLoad(){
    Xrm.Page.getAttribute("my_field").setValue(decryptedValue);
    }
    
    function OnSave(){
    Xrm.Page.getAttribute("my_field").setValue(null);
    }

    Please let me know if you solve.

    If you found the answer helpful, please mark as Verified 

    Join my network on LinkedIn      Follow me on Twitter 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna+Milano, ITALY

    Independent Contractor

    http://www.francescopicchi.com

  • v22arvind Profile Picture
    v22arvind 65 on at
    RE: Decrypting & Setting Displayed Value - Not Entity Value - With JavaScript

    If all you needed data encryption when it sits in db, I would have done another plugin on retrieve/retrieve multiple to decrypt the data. That way i don't need to worry about dirty field handling etc, when the value is updated by user.

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Decrypting & Setting Displayed Value - Not Entity Value - With JavaScript

    Why not use Field Level Security? Does it not serve your need.

    Regarding setting the field so that it is not saved, you can use the setSubmitMode function on the attribute.

    You set setSubmitMode('never') for the field on the Form's onLoad, and then lock the field if you don't want changes to be performed, or add a script to the Attribute's onChange that then changes this to setSubmitMode('always').

    Then the field will not be submitted by CRM, but an event triggering the onChange event (i.e. the user manually making a change to the field) will instruct CRM to change this and submit the field. You can then re-encrypt the fields and save it.

    Hope this helps.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans