web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

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

(1) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    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.

  • v22arvind Profile Picture
    65 on at

    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
    Community Member Profile Picture
    on at

    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

  • Suggested answer
    Community Member Profile Picture
    on at

    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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans