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)

Run jscript as admin?

(0) ShareShare
ReportReport
Posted on by

I know with workflows, you can set them to run with the security settings of a specific user or as a system admin.  Is it possible to do the same thing with ribbon buttons executing jscript?

I have some records that are read-only to certain set of users, but I still need them to be able to click a button on the form to automatically do some activities and then set some attributes on the record saying when the button was clicked and by whom.  The problem is that since the record is read-only, the javascript is giving an error message saying the user doesn't have sufficient privilege etc.  I do have setSubmitMode("always") in my code which works for fields that are read-only fields but it does not work when the entire record is read-only.

The only solution that comes to mind is to temporarily make the user the owner of the record BEFORE running the code and then setting it back the way it was afterwards.  This isn't the most elegant solution IMO, but I believe it should work.

Another option I have not fully considered is having the button execute a workflow as described in https://ribbonworkbench.uservoice.com/knowledgebase/articles/132235-create-a-workflow-short-cut-ribbon-button-no-code.  However I'm not sure the jscript code I want to execute can be translated into a workflow.

*This post is locked for comments

I have the same question (0)
  • KG_CRM Profile Picture
    on at

    One idea I just had is to split the work into two actions.  One action will run the custom javascript that cannot be done in a workflow while the second action is a workflow that edits the record's attributes.  Fortunately the fields I'm editing are simple and don't need javascript to calculate their new values.

    While the above would get the job done, it would still be nice if I could do all of the work in one place instead of splitting it in two.

  • Suggested answer
    ScottDurow Profile Picture
    21 on at

    Hi,

    There is no way to run JavaScript in elevated privileges on the client since this would be a security risk. You will need to encapsulate your logic into a server side call. One way you could do this is via the workflow as I describe in the link you posted - or you could create a custom action and call that via the javascript - see deepakexploring.wordpress.com/.../calling-actions-from-javascript-in-crm-2013

    Essentially anything you can do in JavaScript can be done on the server as well and then you could refresh the form to reflect the changes on the client.

    Hope this helps,

    Scott

  • KG_CRM Profile Picture
    on at

    Hi Scott,

    I'm not sure the custom Action will help as according to Deepak it "Always runs under the context of the calling user."  So I would run into the same issue with permissions and ownership.

    I also just found out that security prevents javascript from setting the Regarding field to an entity that the user doesn't have permission to edit.

  • Suggested answer
    ScottDurow Profile Picture
    21 on at

    Hi,

    You can make a custom action run under elevated privileges by using:

    IOrganizationServiceFactory factory = (IOrganizationServiceFactory)localContext.ServiceProvider.GetService(typeof(IOrganizationServiceFactory));

    var privService = factory.CreateOrganizationService(null);

    You would need AppendTo and Append rights to set the regarding object on an activity.

    Hope this helps,

    Scott

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