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)

Can I run a JS function from a workflow?

(0) ShareShare
ReportReport
Posted on by 221

I built a client-side function that is triggered onChange of a form field. It makes a few REST calls to backend services (one being Web API) I'm now being told this field will be filled in at the time of creation of the record.

Can I trigger my function from a workflow?

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at

    answer is NO

    convert your JS function to action call, use your JS to call the action. then it benefits you as the workflow can call the action as well.

  • f23fzf34ffavcz2t56 Profile Picture
    221 on at

    I did a little research and this looks like it will require the help of a professional developer. Is that right? I'm a sysadmin with some basic coding skills (Javascript and PowerShell) but not C#.

  • Community Member Profile Picture
    on at

    You are right, you need a developer to convert the JS to C#

  • ashlega Profile Picture
    34,477 on at

    Maybe you can call that function in the on-load of the form?

  • BadrinathB Profile Picture
    970 on at

    Can't you call your JavaScript on formload event and put the condition based on FormType

    function MyJsFunction() {

       var isCreateForm = (Xrm.Page.ui.getFormType() == 1);

       var isUpdateForm = (Xrm.Page.ui.getFormType() == 2);

       if (isCreateForm === true) {

           // code to be executed if the current form is a Create Form

       } else if (isUpdateForm === true) {

           // code to be executed if the current form is an Update Form

       }

    }

  • Nithya Gopinath Profile Picture
    17,078 on at

    Hi,

    You can't trigger a JScript function with a workflow on Dynamics CRM.

    See: https://stackoverflow.com/questions/29676666/trigger-a-jscript-webresource-with-a-workflow-on-dynamics-crm

    In order to fill a field at the time of creation of the record, you could use the function below.

                Xrm.Page.ui.getFormType()

    This method is used to get the form context for the record.

    See: https://msdn.microsoft.com/en-us/library/gg327828.aspx#BKMK_getFormType

    function OnLoad(){
     var formType = Xrm.Page.ui.getFormType();
     //Checking if the context of the record is Create
     if(formtype == 1){
      Xrm.Page.getAttribute("fieldname").setValue("yourvalue");
     }
    }

    Hope this helps.

  • f23fzf34ffavcz2t56 Profile Picture
    221 on at

    The record is being created externally via an integration with our ERP system. Doesn't onLoad require that the form be loaded at the client?

  • f23fzf34ffavcz2t56 Profile Picture
    221 on at

    I don't believe I can (I could be wrong.) The record is created via an integration with our ERP system.

  • f23fzf34ffavcz2t56 Profile Picture
    221 on at

    You're the third person to make the same suggestion.

    No, I don't think that will work. The client doesn't create the record therefore onLoad doesn't fire.

  • joman Profile Picture
    617 on at

    If record processing externally, so you need to write a plug-in or workflow, witch will process needed fields.

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