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
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
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
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.
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.
Mohamed Amine Mahmoudi
83
Super User 2025 Season 1
Community Member
54
Victor Onyebuchi
6