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)

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

I have the same question (0)
  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    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.  

  • J. O. Profile Picture
    on at

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

  • Suggested answer
    Hameed Hussain Profile Picture
    250 on at

    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

    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
    Mahendar Pal Profile Picture
    45,095 on at

    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.

  • Temmy Wahyu Raharjo Profile Picture
    2,916 on at

    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?

  • Verified answer
    Nithya Gopinath Profile Picture
    17,078 on at

    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.

  • Mohsin Ali Profile Picture
    3,634 on at

    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

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