web
You’re offline. This is a read only version of the page.
close
Skip to main content
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
    f23fzf34ffavcz2t56 Profile Picture
    221 on at
    RE: Can I run a JS function from a workflow?

    See my followup here: community.dynamics.com/.../238206

  • ashlega Profile Picture
    34,477 on at
    RE: Can I run a JS function from a workflow?

    With the "onLoad", the idea was not to completely replace a plugin/workflow, but to re-use that javascript IF your users don't need the field to be populated right away. But it depends of course. Anyway, if they can wait till somebody opens the form (if they don't need to see that field int he views, if there are no workflows linked to it that have to run earlier, etc) then, maybe, you can re-use that javascript in the onLoad (yes, it will not start automatically. Only when somebody opens that record in CRM)

    Otherwise, you will need a plugin/custom workflow activity, so you will need to do some development.

  • joman Profile Picture
    617 on at
    RE: Can I run a JS function from a workflow?

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

  • f23fzf34ffavcz2t56 Profile Picture
    221 on at
    RE: Can I run a JS function from a workflow?

    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.

  • f23fzf34ffavcz2t56 Profile Picture
    221 on at
    RE: Can I run a JS function from a workflow?

    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
    RE: Can I run a JS function from a workflow?

    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?

  • Nithya Gopinath Profile Picture
    17,078 on at
    RE: Can I run a JS function from a workflow?

    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.

  • BadrinathB Profile Picture
    970 on at
    RE: Can I run a JS function from a workflow?

    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

       }

    }

  • ashlega Profile Picture
    34,477 on at
    RE: Can I run a JS function from a workflow?

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

  • Community Member Profile Picture
    on at
    RE: Can I run a JS function from a workflow?

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

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#2
Christoph Pock Profile Picture

Christoph Pock 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans