Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

OnLoad Javascript Creating Write Priv Errors for Read-Only Users

(0) ShareShare
ReportReport
Posted on by

All,

Can someone explain to me if javascript for onLoad functions that write to an entity run under user context?

I have a few read-only users that get privWriteLead errors when opening up a lead.  Left me a bit confused, but remember I have js that writes to Lead onLoad.  I got rid of the error by giving the user read-write license level.

1)Can someone give me a low level explanation on why this happened?

2)How can I modify code to let this code write to entity for read-only user? -- I am confident this was root cause

Thanks and Regards.

*This post is locked for comments

  • Mohsin Ali Profile Picture
    3,618 on at
    RE: OnLoad Javascript Creating Write Priv Errors for Read-Only Users

    I hope follwoing article will help you to understand the plugin article:

    community.dynamics.com/.../how-to-change-a-plugin-run-in-user-s-context-programmatically

  • Verified answer
    Nithya Gopinath Profile Picture
    17,078 on at
    RE: OnLoad Javascript Creating Write Priv Errors for Read-Only Users

    Hi,

    In server-side plugins, we have InitiatingUserId and UserId in the IPluginExecutionContext.

    UserId : Gets the GUID of the user for whom the plug-in invokes “on behalf of” (which can be given while registering Plugin step in Plugin Registration tool)

    7888.2.png

    InitiatingUserId: Gets the GUID of the user who performed the action triggering the plugin.

    rajeevpentyala.com/.../userid-initiatinguserid-properties-in-plugin-of-crm

    community.dynamics.com/.../ms-crm-plugin-ipluginexecutioncontext-initiatinguserid-and-userid-plugintip2

    Hope this helps.

  • Temmy Wahyu Raharjo Profile Picture
    2,914 on at
    RE: OnLoad Javascript Creating Write Priv Errors for Read-Only Users

    Hey, Plugin can be set to run as Admin Context. But when you check the auditing history, it will shown up as Admin instead of the user it self and will make you hard to inspect. I suggests why not just give the user the correct security role?

  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at
    RE: OnLoad Javascript Creating Write Priv Errors for Read-Only Users

    Hello J.O,

    When you write plugin you can configure on which user context you want to run your plugin code. By default it will set as Run in User's context, so you can run it on the current user context just like JS code or you cam set specific user there on which you want to run your plugin code.

    You do have different option for impersonating users, I will suggest you to go through this KB: msdn.microsoft.com/.../gg309416.aspx it will help you.

  • J. O. Profile Picture
    on at
    RE: OnLoad Javascript Creating Write Priv Errors for Read-Only Users

    Goutam stated, "By default client side script run in user context ..." Makes sense that the client will always run in user context....what about if I rid the js and right the plugin to do what I whant?  Still user context?

  • Suggested answer
    Hameed Hussain Profile Picture
    250 on at
    RE: OnLoad Javascript Creating Write Priv Errors for Read-Only Users

    AAccess-Teams-Template.png"_blank" href="/api/data/v9.1/msdyn_richtextfiles(0559E2F8-31AD-4792-957A-C7E85182FDD9)/msdyn_imageblob/$value?size=full">community.dynamics.com/.../Access-Teams-Template.png

    community.dynamics.com/.../access-teams-and-access-team-templates

    Please let me know.

    Thanks.

  • J. O. Profile Picture
    on at
    RE: OnLoad Javascript Creating Write Priv Errors for Read-Only Users

    Excellent sir.  Thank you.  What if I update entity server-side?  Will it still run in user context?

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: OnLoad Javascript Creating Write Priv Errors for Read-Only Users

    Are you updating entity in the form onload ?

    By default client side script run in user context so the user which you are logged in does not have the entity write privilege and when you are trying to update the entity its throws error. .

    In this scenario I would suggest give the write access to the entity and implement two role  based forms (Editable ,read only) for the entity. Based on user assign  roles display the editable and read only form.  

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans