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)

How to call javascript method from plugin c#

(0) ShareShare
ReportReport
Posted on by

I have a method in javascript I want to call from a plugin. I tried with the following method but I have not succeeded, the project does not want to take the assemblys.

 ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "alert('hola mundo');", true);

*This post is locked for comments

I have the same question (0)
  • Tim Dutcher Profile Picture
    2,100 on at

    What are the specific requirements?

    You can't directly invoke client-side JavaScript code from a plug-in. There are indirect ways of doing this, such as a change to an entity record made it a plug-in can cause JavaScript code that's running with setInterval to interact with the form.

  • Community Member Profile Picture
    on at

    Hi Tim, thanks for your reply, now I have a plug removal. This runs when I delete a record of a subgrid, but I have a custom field values that sum is in this subgrid. I want the plug after removal run the value of my custom field is updated. For this reason I wanted to call a method to make a javascript refresh the page with the following code because from a plugin can not.

    Xrm.Page.data.refresh().

  • Tim Dutcher Profile Picture
    2,100 on at

    First, check the following forum post and see if the code provided by Gary or Neil works for your scenario:

    community.dynamics.com/.../190413

  • Community Member Profile Picture
    on at

    Hi Tim,

    Javascript function will not trigger if field changes are made from plugin

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi ,

    Unfortunately this is not supported in the Dynamics CRM, you don't have any control to use  ScriptManager .

    I  believe you are aware that plugin execute server side  and  you can not call client side function from server side plugin. It is really not possible .

    As an alternate you can trigger a function in OnSave (if your plugin fires in create/Update event)  and then after few seconds timeout check the record is created/Update or not and based on that fire JS function. Here is sample code  - 

    //Register the function in OnSave
    function OnSave() {
        Xrm.Page.data.save().then(successSubmitCallback(), errorSubmitCallback);
    }
    function successSubmitCallback() {
        setTimeout(function () {
    // Write some logic to make sure your plugin has fired and record created and updated // Call your JS function here }, 3000); // Set timeout to know that record created successfully and id has generated } function errorSubmitCallback(message) { alert("error"); }

    You  can show progress bar for the set timeout 3 seconds .
    Hope this helps . 

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