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)

Need to prevent Infinite Loop

(0) ShareShare
ReportReport
Posted on by

As per the requirement ON LOAD of contact form I have written javascript, Inside Javascript function I am calling action through one more javascript. In Action I have a custom workflow code to update contact fields based upon some scenario. Fields in the form is getting updated from custom workflow but I can see the changes only after manual web page refresh. My requirement is to make change visible to user without manual refresh. So I added Xrm.Page.data.refresh(false) in the end of script, but on every refresh of page my ON LOAD javascript is triggering which calls custom worflow and ended up with infinite times page refresh, Please help me with solution.

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at
    RE: Need to prevent Infinite Loop

    Thank You Aiden, Now everything is fine.

    As you said I created new field "Refresh" and made it hidden, by default I made it NO, I checked the condition if(refresh==NO)

    {

    Using workflow I made "refresh"=YES and refreshed the form using Xrm.Page.data.refresh();

    }

    When the page loaded after refresh it didn't enter the condition. So Now it is working proper as expected.

    Regards,

    Venkat

  • Suggested answer
    Aiden Kaskela Profile Picture
    19,696 on at
    RE: Need to prevent Infinite Loop

    Hi again,

    The slickest way to do what you need is to pull your workflow code and and run it as a plugin, then invoke the plugin via javascript. It's more work but you won't see the page refresh.

    1. Create a new entity called System Event, with fields Request and Response.
    2. Move your workflow logic to a plugin that runs on PreCreate of the System Event. It should look for input parameters on the Request, do stuff, and set the result on the Response field.
    3. On form load in javascript, create a new System Event and set the Request to whatever parameters you need from the entity and Save the system event. 
    4. Refresh the system event from CRM so you can read the response field.
    5. Parse the response in javascript and set the fields on the form.

    This will let you set the fields in javascript, while writing your complex business logic in C#. Hat tip to Michael Ochs who presented this at extremeCRM in Warsaw earlier this year.

    Hope this helps! I'd appreciate if you'd mark this as Answering your question.

    Thanks,

     Aiden

  • Verified answer
    Aiden Kaskela Profile Picture
    19,696 on at
    RE: Need to prevent Infinite Loop

    Hi,

    The easy way would be to add a field to the record, "Refreshing". When a form loads for the first time, run the workflow, set this to yes, save and refresh. On form load, if it's yes, don't run the workflow and set it to no.

    Thanks,

     Aiden

  • Community Member Profile Picture
    on at
    RE: Need to prevent Infinite Loop

    Hi Aiden,

    Thanks for your reply.

    Yes, I can do it by javascript. But in requirement  data is coming from other web page, so I have used custom workflow for it.  Data is getting updated in my contact form but need to do manual web page refresh which I want to make automatically.

  • Suggested answer
    Aiden Kaskela Profile Picture
    19,696 on at
    RE: Need to prevent Infinite Loop

    Hi,

    To see the changes immediately and without an infinite loop, you need to remove the workflow and do everything right in the Javascript. That will let you set the field value without needing to refresh

    Hope this helps! I'd appreciate if you'd mark this as Answering your question.

    Thanks,

    Aiden

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
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#2
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans